Files
growstuff/app/controllers/harvests_controller.rb
Daniel O'Connor c32fae3cbe release88 (#4688)
* Bump actions/cache from 5 to 6

Bumps [actions/cache](https://github.com/actions/cache) from 5 to 6.
- [Release notes](https://github.com/actions/cache/releases)
- [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md)
- [Commits](https://github.com/actions/cache/compare/v5...v6)

---
updated-dependencies:
- dependency-name: actions/cache
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump axe-core-rspec from 4.11.3 to 4.12.0

Bumps [axe-core-rspec](https://github.com/dequelabs/axe-core-gems) from 4.11.3 to 4.12.0.
- [Release notes](https://github.com/dequelabs/axe-core-gems/releases)
- [Changelog](https://github.com/dequelabs/axe-core-gems/blob/develop/CHANGELOG.md)
- [Commits](https://github.com/dequelabs/axe-core-gems/compare/v4.11.3...v4.12.0)

---
updated-dependencies:
- dependency-name: axe-core-rspec
  dependency-version: 4.12.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Merge pull request #4683 from Growstuff/refactor-harvests-remove-elasticsearch-14630838429921835504

Refactor harvests to remove Elasticsearch

* Refactor Seeds to remove Elasticsearch dependency (#4684)

* Refactor Seeds to remove Elasticsearch dependency

This commit refactors the `SeedsController` and `Seed` model to remove
dependency on Elasticsearch and Searchkick.

Key changes:
- Removed `SearchSeeds` concern from the `Seed` model.
- Reimplemented `Seed.homepage_records` using ActiveRecord.
- Refactored `SeedsController#index` to use ActiveRecord for filtering,
  eager loading, and pagination.
- Deleted `app/models/concerns/search_seeds.rb`.
- Updated relevant specs to remove Searchkick-specific tags and setup.

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

* Remove Seed.reindex

* Remove trait

* Fix tests

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>

* 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>

* 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>

* Block Semrush crawler in Rack Attack initializer

Added a blocklist entry for the Semrush crawler to prevent abusive requests.

* Bump sitemap_generator from 6.3.0 to 7.0.2

Bumps [sitemap_generator](https://github.com/kjvarga/sitemap_generator) from 6.3.0 to 7.0.2.
- [Changelog](https://github.com/kjvarga/sitemap_generator/blob/master/CHANGES.md)
- [Commits](https://github.com/kjvarga/sitemap_generator/compare/v6.3.0...v7.0.2)

---
updated-dependencies:
- dependency-name: sitemap_generator
  dependency-version: 7.0.2
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump carrierwave from 3.0.7 to 3.1.3

Bumps [carrierwave](https://github.com/carrierwaveuploader/carrierwave) from 3.0.7 to 3.1.3.
- [Release notes](https://github.com/carrierwaveuploader/carrierwave/releases)
- [Changelog](https://github.com/carrierwaveuploader/carrierwave/blob/master/CHANGELOG.md)
- [Commits](https://github.com/carrierwaveuploader/carrierwave/compare/v3.0.7...v3.1.3)

---
updated-dependencies:
- dependency-name: carrierwave
  dependency-version: 3.1.3
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump rubocop from 1.88.0 to 1.88.1 (#4691)

Bumps [rubocop](https://github.com/rubocop/rubocop) from 1.88.0 to 1.88.1.
- [Release notes](https://github.com/rubocop/rubocop/releases)
- [Changelog](https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rubocop/rubocop/compare/v1.88.0...v1.88.1)

---
updated-dependencies:
- dependency-name: rubocop
  dependency-version: 1.88.1
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump sitemap_generator from 7.0.2 to 7.0.3 (#4692)

Bumps [sitemap_generator](https://github.com/kjvarga/sitemap_generator) from 7.0.2 to 7.0.3.
- [Changelog](https://github.com/kjvarga/sitemap_generator/blob/master/CHANGES.md)
- [Commits](https://github.com/kjvarga/sitemap_generator/compare/v7.0.2...v7.0.3)

---
updated-dependencies:
- dependency-name: sitemap_generator
  dependency-version: 7.0.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump sitemap_generator from 7.0.3 to 7.1.0

Bumps [sitemap_generator](https://github.com/kjvarga/sitemap_generator) from 7.0.3 to 7.1.0.
- [Changelog](https://github.com/kjvarga/sitemap_generator/blob/master/CHANGES.md)
- [Commits](https://github.com/kjvarga/sitemap_generator/compare/v7.0.3...v7.1.0)

---
updated-dependencies:
- dependency-name: sitemap_generator
  dependency-version: 7.1.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump haml_lint from 0.74.0 to 0.75.0 (#4694)

Bumps [haml_lint](https://github.com/sds/haml-lint) from 0.74.0 to 0.75.0.
- [Release notes](https://github.com/sds/haml-lint/releases)
- [Changelog](https://github.com/sds/haml-lint/blob/main/CHANGELOG.md)
- [Commits](https://github.com/sds/haml-lint/compare/v0.74.0...v0.75.0)

---
updated-dependencies:
- dependency-name: haml_lint
  dependency-version: 0.75.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump rubocop from 1.88.1 to 1.88.2

Bumps [rubocop](https://github.com/rubocop/rubocop) from 1.88.1 to 1.88.2.
- [Release notes](https://github.com/rubocop/rubocop/releases)
- [Changelog](https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rubocop/rubocop/compare/v1.88.1...v1.88.2)

---
updated-dependencies:
- dependency-name: rubocop
  dependency-version: 1.88.2
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Cesy <cesy.avon@gmail.com>
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
2026-07-10 19:25:08 +09:30

122 lines
3.5 KiB
Ruby

# frozen_string_literal: true
class HarvestsController < DataController
after_action :update_crop_medians, only: %i(create update destroy)
def index
@harvests = Harvest.all
if params[:member_slug].present?
@owner = Member.find_by!(slug: params[:member_slug])
@harvests = @harvests.where(owner_id: @owner.id)
end
if params[:crop_slug]
@crop = Crop.find_by(slug: params[:crop_slug])
@harvests = @harvests.where(crop_id: @crop.id) if @crop
end
if params[:planting_slug]
@planting = Planting.find_by(slug: params[:planting_slug])
@harvests = @harvests.where(planting_id: @planting.id) if @planting
end
@harvests = @harvests.includes(:crop, :owner, :plant_part)
@harvests = @harvests.recent.paginate(page: params[:page], per_page: 100)
@filename = csv_filename
respond_with(@harvests)
end
def show
@matching_plantings = matching_plantings if @harvest.owner == current_member
@photos = @harvest.photos.order(created_at: :desc).paginate(page: params[:page])
respond_with(@harvest)
end
def new
@harvest = Harvest.new(new_harvest_params.merge(harvested_at: Time.zone.today))
@planting = @harvest.planting
@crop = @harvest.crop
respond_with(@harvest)
end
def edit
@planting = @harvest.planting if @harvest.planting_id
respond_with(@harvest)
end
def create
@harvest.crop_id = @harvest.planting.crop_id if @harvest.planting_id
@harvest.harvested_at = Time.zone.now if @harvest.harvested_at.blank?
update_planting_rating if @harvest.save
if params[:return] == 'planting'
respond_with(@harvest, location: @harvest.planting)
else
respond_with(@harvest)
end
end
def update
update_planting_rating if @harvest.update(harvest_params)
respond_with(@harvest)
end
def destroy
@harvest.destroy
respond_with(@harvest)
end
private
def harvest_params
params.require(:harvest)
.permit(:planting_id, :crop_id, :harvested_at, :description,
:quantity, :unit, :weight_quantity, :weight_unit,
:plant_part_id, :slug, :si_weight, :overall_rating)
.merge(owner_id: current_member.id)
end
def new_harvest_params
return {} unless params[:harvest]
params.require(:harvest)
.permit(:planting_id, :crop_id, :harvested_at, :description,
:quantity, :unit, :weight_quantity, :weight_unit,
:plant_part_id, :slug, :si_weight, :overall_rating)
.merge(owner_id: current_member.id)
end
def matching_plantings
Planting.where(crop: @harvest.crop, owner: @harvest.owner)
.where('(planted_at IS NULL OR planted_at <= ?)', @harvest.harvested_at)
.where('(finished_at IS NULL OR finished_at >= ?)', @harvest.harvested_at)
end
def csv_filename
specifics = if @owner
"#{@owner.to_param}-"
elsif @crop
"#{@crop.to_param}-"
end
"Growstuff-#{specifics}Harvests-#{Time.zone.now.to_fs(:number)}.csv"
end
def update_crop_medians
# We only update medians to predict plantings
# if this harvest is not linked to a planting, then do nothing
return if @harvest.planting.nil?
@harvest.planting.update_harvest_days!
@harvest.crop.update_harvest_medians
end
def update_planting_rating
return if @harvest.planting.nil? || params[:harvest][:overall_rating].blank?
@harvest.planting.update(overall_rating: params[:harvest][:overall_rating])
end
end