tags_controller.rb 1013 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # frozen_string_literal: true
  2. class Admin::Trends::TagsController < Admin::BaseController
  3. def index
  4. authorize :tag, :review?
  5. @tags = filtered_tags.page(params[:page])
  6. @form = Trends::TagBatch.new
  7. end
  8. def batch
  9. authorize :tag, :review?
  10. @form = Trends::TagBatch.new(trends_tag_batch_params.merge(current_account: current_account, action: action_from_button))
  11. @form.save
  12. rescue ActionController::ParameterMissing
  13. flash[:alert] = I18n.t('admin.accounts.no_account_selected')
  14. ensure
  15. redirect_to admin_trends_tags_path(filter_params)
  16. end
  17. private
  18. def filtered_tags
  19. Trends::TagFilter.new(filter_params).results
  20. end
  21. def filter_params
  22. params.slice(:page, *Trends::TagFilter::KEYS).permit(:page, *Trends::TagFilter::KEYS)
  23. end
  24. def trends_tag_batch_params
  25. params.require(:trends_tag_batch).permit(:action, tag_ids: [])
  26. end
  27. def action_from_button
  28. if params[:approve]
  29. 'approve'
  30. elsif params[:reject]
  31. 'reject'
  32. end
  33. end
  34. end