Commit Graph
96 Commits
Author SHA1 Message Date
Brenda WallaceandClaude Sonnet 5 571405a840 Stop Rack::Attack depending on memcached, and cut the memcached timeout (#4800)
* Keep Rack::Attack counters in process memory

Rack::Attack was storing its request counters in Rails.cache, which is
memcached in production. On 2026-09-19, memcached calls were timing out
in the production logs. When that happens, the counters stop working.

In the same log window, one IP made 753 requests. 717 of them
succeeded. The 15 per minute throttle and the 500 per day ban did not
stop it.

Rack::Attack now uses its own in-memory store, capped at 8 MB. Each
Puma worker keeps its own counters, so the limits apply per worker.

Refs #1640

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* Add BLOCKED_IPS list to Rack::Attack

When one crawler overloads the site, we need a fast way to block it.
Rack::Attack now blocks every IP listed in the BLOCKED_IPS environment
variable. The list is comma separated.

Setting the variable does not need a code change. It also keeps IP
addresses out of the repository.

Refs #1640

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* Lower the memcached socket timeout to 0.5 seconds

The production cache store waited up to 1.5 seconds for each memcached
call. Dalli's own default is 1 second. Dalli also retries after a
failure, so one bad cache call can block a Puma thread for longer than
the timeout.

On 2026-09-19, the production logs showed memcached timeouts every few
seconds. With only 5 threads per Puma worker, blocked threads make the
site slow. Slow requests hold memory for longer.

The timeout is now 0.5 seconds. A healthy memcached call takes a few
milliseconds. A call that takes 0.5 seconds has failed in practice, so the
request is better off skipping the cache.

Refs #1640

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-20 13:36:25 +09:30
google-labs-jules[bot]andCloCkWeRX 9ebd98de2d Harden Rack::Attack and pagination against aggressive web crawlers
- Configure Allow2Ban in Rack::Attack to ban IPs requesting >500 pages per day for 1 week (7 days).
- Add honeypot route /dont-crawl-me disallowed in robots.txt and configure Fail2Ban in Rack::Attack to ban IPs visiting it for 7 days upon 1 hit.
- Update PhotosController#index to raise ActiveRecord::RecordNotFound when page parameter is out of bounds, returning 404 Not Found to crawlers instead of 200 OK.
- Add request and controller specs for Rack::Attack rules and pagination 404 responses.

Co-authored-by: CloCkWeRX <365751+CloCkWeRX@users.noreply.github.com>
2026-09-16 18:50:30 +12:00
c9b8c54b81 Fix plantings ICS feed regression and enable request spec (#4687)
* Fix plantings ICS feed regression and enable request spec

- Update `app/views/plantings/index.ics.erb` to use ActiveRecord method calls instead of hash bracket access.
- Enable `spec/requests/plantings_spec.rb` and update it to account for mirrored harvest events.
- Add `config/initializers/faraday_patch.rb` to fix Searchkick/Faraday 2.x compatibility issues.

Co-authored-by: CloCkWeRX <365751+CloCkWeRX@users.noreply.github.com>

* Delete config/initializers/faraday_patch.rb

* Apply suggestion from @CloCkWeRX

* Apply suggestions from code review

Co-authored-by: Daniel O'Connor <daniel.oconnor@gmail.com>

* Apply suggestion from @CloCkWeRX

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
2026-06-24 23:18:24 +09:30
fa7f460510 Refactor Plantings to remove Elasticsearch dependency (#4686)
* Refactor Plantings to remove Elasticsearch dependency

This commit refactors the Plantings controller, model, and views to use
ActiveRecord instead of Searchkick/Elasticsearch.

Key changes:
- Refactored `PlantingsController#index` to use an ActiveRecord-based
  `plantings` method.
- Moved `homepage_records` logic from `SearchPlantings` concern to the
  `Planting` model using ActiveRecord scopes.
- Removed `SearchPlantings` concern and deleted the file.
- Updated `home/_plantings.html.haml` and `plantings/index.rss.haml` to
  use dot notation for `Planting` object attributes.
- Updated specs to remove Searchkick-related setup and assertions.

Co-authored-by: CloCkWeRX <365751+CloCkWeRX@users.noreply.github.com>

* Fix Planting.reindex

* Fix test

* Mark test pending

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
2026-06-24 22:26:49 +09:30
5ada7e7f77 Add crops search API endpoint (#4622)
* Add crops search API endpoint

- Added GET /api/v1/crops/search endpoint.
- Updated CropSearchService to support additional search options.
- Manually updated Swagger documentation in swagger/v1/swagger.json.
- Added request specs to verify the new endpoint.

Co-authored-by: CloCkWeRX <365751+CloCkWeRX@users.noreply.github.com>

* Add crops search API endpoint

- Added GET /api/v1/crops/search endpoint.
- Updated CropSearchService to support additional search options.
- Manually updated Swagger documentation in swagger/v1/swagger.json.
- Added request specs to verify the new endpoint.

Co-authored-by: CloCkWeRX <365751+CloCkWeRX@users.noreply.github.com>

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
2026-05-04 18:12:36 +09:30
Daniel O'Connor 8cfef5ce1a Rubocop fixes 2026-04-26 13:09:00 +00:00
2aa697a6d6 Add comprehensive test coverage for forums (#4561)
* Add comprehensive test coverage for forums

- Added `spec/controllers/forums_controller_spec.rb` to test all CRUD actions and authorization for guest, member, and admin roles.
- Added `spec/features/forums_spec.rb` to cover user-facing features such as browsing forums and creating posts from within a forum.
- Updated `spec/requests/forums_spec.rb` to cover basic request flow and JSON response formats.

Note: Tests were verified for content and logic but execution in the sandbox environment was blocked by missing infrastructure (PostgreSQL and Elasticsearch).

Co-authored-by: CloCkWeRX <365751+CloCkWeRX@users.noreply.github.com>

* Fix specs

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
2026-04-26 14:18:28 +09:30
Daniel O'Connor 8de6b083f9 Rubocop: RSpecRails/HaveHttpStatus 2026-04-23 14:13:47 +00:00
Daniel O'Connor accab7f84c Merge pull request #4545 from Growstuff/RSpecRails/InferredSpecType
Rubocop: RSpecRails/InferredSpecType
2026-04-23 23:29:17 +09:30
Daniel O'Connor 0a71b44dea Merge pull request #4542 from Growstuff/RSpec/ContextMethod
Rubocop: RSpec/ContextMethod
2026-04-23 23:10:33 +09:30
Daniel O'Connor ba75afb3f5 Rubocop: RSpecRails/InferredSpecType 2026-04-23 13:39:46 +00:00
Daniel O'Connor 6736ae3142 Rubocop: RSpec/ContextMethod 2026-04-23 13:20:47 +00:00
Daniel O'Connor 6ba4f39b4a Rubocop: Lint/EmptyBlock 2026-04-23 13:14:39 +00:00
Daniel O'Connor f1acb35520 Merge pull request #4537 from Growstuff/FactoryBot/SyntaxMethods
Rubocop: FactoryBot/SyntaxMethods
2026-04-23 22:29:24 +09:30
Daniel O'Connor ae5c125a96 Rubocop: Layout/IndentationWidth 2026-04-23 12:10:09 +00:00
google-labs-jules[bot] 63d65c4e6b Merge pull request #4277 from Growstuff/add-activity-update-coverage
Add test coverage for updating an activity via the API
2025-09-30 20:29:11 +09:30
Daniel O'Connor d9851231f2 Merge pull request #4274 from Growstuff/CloCkWeRX-patch-3
API > Render activities links under member
2025-09-29 01:11:24 +09:30
google-labs-jules[bot]andDaniel O'Connor 02db5b8130 Add API token generation, authentication, and CRUD for a number of the API resources (#4237)
* feat: Add API token generation and authentication

This commit introduces API token generation and authentication for write operations.

- Adds a section to the user's profile edit page to generate and display an API token.
- Reuses the `authentications` table to store the API token, avoiding the need for a database migration.
- Implements token-based authentication for the API using the `Authorization: Token token=...` header.
- Enables write operations for all API resources and ensures they are protected by the new authentication mechanism.
- Adds feature and request specs to test the new functionality.

* feat: Add API token generation and authentication

This commit introduces API token generation and authentication for write operations.

- Adds a section to the user's profile edit page to generate and display an API token.
- Reuses the `authentications` table to store the API token, avoiding the need for a database migration.
- Implements token-based authentication for the API using the `Authorization: Token token=...` header.
- Enables write operations for all API resources and ensures they are protected by the new authentication mechanism.
- Adds feature and request specs to test the new functionality.

* Mark as editable

* Refactor

* WIP - Authentication

* Implement more test coverage

* Split 401 and 403

* Before Create hooks

* Update harvest specs, defaulting to the first plant part - this may not be right

* Update coverage

* Update coverage

* Rubocop

* Rubocop

* Rubocop

* Fix coverage

* For now, mark photos immutable again

* Fix specs

* Fix specs

* Rubocop

* Fix specs

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: Daniel O'Connor <daniel.oconnor@gmail.com>
2025-09-10 19:50:06 +09:30
google-labs-jules[bot] e5c71f1dc4 Merge pull request #4230 from Growstuff/feature/add-more-filters
feat: Add more filters to API resources
2025-09-09 21:34:49 +09:30
google-labs-jules[bot] ba6ec689c5 Merge pull request #4150 from Growstuff/feature/failed-plantings
Add failed status to plantings
2025-08-27 23:42:53 +09:30
Daniel O'Connor 81060cccf7 Ruby 3.2: Rubocop - Lint/* and Style/* (#3786)
* Rubocop - Layout/*
* Rubocop - Lint and Style
2024-07-13 15:38:37 +09:30
Daniel O'Connor 4f5c47ba58 Ruby 3.2: Rubocop - Layout/* (#3785)
* Rubocop - Layout/*

* Regenerate
2024-07-13 15:19:09 +09:30
Daniel O'Connor 5be0153c74 Activities (#3646)
* Implement activities

* Add activities to timeline

* Add factory

* Add coverage

* Fix misc issues

* Activities display

* Add activities to garden and plantings

* Add activities to garden and plantings

* Add planting

* Add to planting, harvest show

* More CRUD

* More CRUD

* index

* index

* Extract card view

* Permissions

* Add edit

* Remove workaround fro vs code

* Fix title

* CSV

* CSV

* Add RSS, ical

* Extend ical slightly

* Cleanup

* Rubocop

* Remove doubled form

* Change icon

* Fix short description

* Add menus

* Put homepage widget in

* Add activity icon - MIT licenced - https://www.svgrepo.com/svg/336823/plan

* Naming

* Missing files

* Revert VS Code lag induced change

* Update app/views/home/_harvests.html.haml

* Update activities_controller.rb

* Update activities_controller.rb

* Update app/controllers/activities_controller.rb

* Update index.html.haml

* Apply suggestions from code review

* Apply suggestions from code review

* Typo

* Translation

* Apply suggestions from code review

* Update app/views/plantings/index.ics.erb

* Update app/models/activity.rb

* Update plantings_spec.rb

* Update plantings_spec.rb

* We are now rendering an extra event, so check the next one for the old behaviour
2024-03-10 11:36:24 +10:30
Daniel O'Connor e2bdbeff23 Parse date 2024-02-04 05:18:57 +00:00
Daniel O'Connor 50ba0f08b1 Fix Plantings > CSV output (#3616)
* Fix crash

* Add test coverage and index more

* Fix test
2024-02-04 15:09:30 +10:30
Daniel O'Connor f338274611 Rails 7.1 (#3590)
* Rails 7.1

* Update application.rb

* Bump searchkick

* Bump to 7.0.0

* Fix

* Fix crop search

* Sync translation

* Drop required from form group

* Loosen specs further

* Fix Gemfile

* Update seeds_request_spec.rb

* Update test.rb

* Rename
2024-01-27 10:06:47 +10:30
Daniel O'Connor ad4a6e17e2 iCalendar feed of plantings (#3588)
* Register mime type

* Add rough first pass

* Index predictions, and add links

* Trailing space

* Fix implementation

* Fix names, make public

* Fix names, make public

* Fix

* Fix tyyos

* Add date

* If there are no predictions, keep growing

* Add a todo

* Fix factories

* Specs
2024-01-27 00:38:33 +10:30
Daniel O'Connor d1f754a288 Rubocop 2022-11-08 00:23:38 +10:30
Daniel O'Connor b24b9f82e6 Rubocop - auto corrections 2022-11-06 16:34:36 +10:30
Daniel O'Connor 260f19e047 Add tests #3401 - wrong resources loaded (#3045)
* Prove broken

* Allow filter by owner id

* Specify FK

* Mark pending, and cover filter by member
2022-05-01 17:09:13 +09:30
Awesome Code 83462275e7 Auto corrected by following Lint Ruby Rails/HttpStatus 2020-05-23 07:48:28 +12:00
Awesome Code 4c0899790a Auto corrected by following Lint Ruby RSpec/NotToNot 2020-05-23 07:48:28 +12:00
codefactor-io 4ff95fbac9 [CodeFactor] Apply fixes 2020-01-21 22:26:08 +13:00
Brenda Wallace 6622aaf886 used expect syntax 2019-12-24 09:25:15 +13:00
codefactor-io e8760f9c38 [CodeFactor] Apply fixes 2019-12-20 03:33:23 +00:00
Brenda Wallace 04fd1a343a Rubocop update (#2334)
* Update rubocop config

* Rubocop update - for rubocop 0.77

* [CodeFactor] Apply fixes

* rubocop fixes

* [CodeFactor] Apply fixes to commit 2826c2e
2019-12-16 22:35:33 +13:00
Brenda Wallace fa1e70036a Fix name of spec 2019-11-18 16:06:57 +13:00
Brenda Wallace df5b0499e4 Update spec for api resource 2019-11-16 13:05:40 +13:00
bestest-mensch 9f8e2e65be update/add specs 2019-10-07 21:38:19 +00:00
Brenda Wallace 0a919d8599 Remove notifications spec 2019-08-10 10:50:57 +12:00
Brenda Wallace 5816b6c64c Removed comment show spec. Page doesn't exist now 2019-06-14 17:10:03 +12:00
Awesome Code 4ba5319ba8 Auto corrected by following Lint Ruby Capybara/FeatureMethods 2019-04-01 23:02:50 +13:00
Brenda Wallace 5395aefa66 Rename containers to garden types 2019-03-26 20:56:11 +13:00
Brenda Wallace 02e0dd091a Merge remote-tracking branch 'upstream/dev' into bb-track-types-of-gardens 2019-03-26 19:35:16 +13:00
Awesome Code e10c641702 Auto corrected by following Lint Ruby Layout/AlignHash 2019-03-22 07:55:05 +00:00
Brenda Wallace 77f936cb0f update spec 2019-03-20 09:43:01 +13:00
Awesome Code ad470ede1d Auto corrected by following Lint Ruby RSpec/AlignRightLetBrace 2019-03-13 17:23:33 +13:00
Awesome Code f90cc792bb Auto corrected by following Lint Ruby RSpec/AlignLeftLetBrace 2019-03-13 11:42:27 +13:00
Brenda Wallace 572af9d135 Merge branch 'dev' into photos/seeds 2019-02-09 17:00:58 +13:00
Awesome Code 284bb81bbf Auto corrected by following Lint Ruby RSpecEmptyLine 2019-02-09 03:05:40 +00:00