follow_recommendations_controller.rb 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # frozen_string_literal: true
  2. module Admin
  3. class FollowRecommendationsController < BaseController
  4. before_action :set_language
  5. def show
  6. authorize :follow_recommendation, :show?
  7. @form = Form::AccountBatch.new
  8. @accounts = filtered_follow_recommendations
  9. end
  10. def update
  11. authorize :follow_recommendation, :show?
  12. @form = Form::AccountBatch.new(form_account_batch_params.merge(current_account: current_account, action: action_from_button))
  13. @form.save
  14. rescue ActionController::ParameterMissing
  15. # Do nothing
  16. ensure
  17. redirect_to admin_follow_recommendations_path(filter_params)
  18. end
  19. private
  20. def set_language
  21. @language = follow_recommendation_filter.language
  22. end
  23. def filtered_follow_recommendations
  24. follow_recommendation_filter.results
  25. end
  26. def follow_recommendation_filter
  27. @follow_recommendation_filter ||= FollowRecommendationFilter.new(filter_params)
  28. end
  29. def form_account_batch_params
  30. params.require(:form_account_batch).permit(:action, account_ids: [])
  31. end
  32. def filter_params
  33. params.slice(*FollowRecommendationFilter::KEYS).permit(*FollowRecommendationFilter::KEYS)
  34. end
  35. def action_from_button
  36. if params[:suppress]
  37. 'suppress_follow_recommendation'
  38. elsif params[:unsuppress]
  39. 'unsuppress_follow_recommendation'
  40. end
  41. end
  42. end
  43. end