You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.3 KiB

  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. @form = Form::AccountBatch.new(form_account_batch_params.merge(current_account: current_account, action: action_from_button))
  12. @form.save
  13. rescue ActionController::ParameterMissing
  14. # Do nothing
  15. ensure
  16. redirect_to admin_follow_recommendations_path(filter_params)
  17. end
  18. private
  19. def set_language
  20. @language = follow_recommendation_filter.language
  21. end
  22. def filtered_follow_recommendations
  23. follow_recommendation_filter.results
  24. end
  25. def follow_recommendation_filter
  26. @follow_recommendation_filter ||= FollowRecommendationFilter.new(filter_params)
  27. end
  28. def form_account_batch_params
  29. params.require(:form_account_batch).permit(:action, account_ids: [])
  30. end
  31. def filter_params
  32. params.slice(*FollowRecommendationFilter::KEYS).permit(*FollowRecommendationFilter::KEYS)
  33. end
  34. def action_from_button
  35. if params[:suppress]
  36. 'suppress_follow_recommendation'
  37. elsif params[:unsuppress]
  38. 'unsuppress_follow_recommendation'
  39. end
  40. end
  41. end
  42. end