relationships_controller.rb 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # frozen_string_literal: true
  2. class RelationshipsController < ApplicationController
  3. layout 'admin'
  4. before_action :authenticate_user!
  5. before_action :set_accounts, only: :show
  6. before_action :set_body_classes
  7. helper_method :following_relationship?, :followed_by_relationship?, :mutual_relationship?
  8. def show
  9. @form = Form::AccountBatch.new
  10. end
  11. def update
  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 relationships_path(filter_params)
  18. end
  19. private
  20. def set_accounts
  21. @accounts = RelationshipFilter.new(current_account, filter_params).results.page(params[:page]).per(40)
  22. end
  23. def form_account_batch_params
  24. params.require(:form_account_batch).permit(:action, account_ids: [])
  25. end
  26. def following_relationship?
  27. params[:relationship].blank? || params[:relationship] == 'following'
  28. end
  29. def mutual_relationship?
  30. params[:relationship] == 'mutual'
  31. end
  32. def followed_by_relationship?
  33. params[:relationship] == 'followed_by'
  34. end
  35. def filter_params
  36. params.slice(:page, *RelationshipFilter::KEYS).permit(:page, *RelationshipFilter::KEYS)
  37. end
  38. def action_from_button
  39. if params[:unfollow]
  40. 'unfollow'
  41. elsif params[:remove_from_followers]
  42. 'remove_from_followers'
  43. elsif params[:block_domains]
  44. 'block_domains'
  45. end
  46. end
  47. def set_body_classes
  48. @body_classes = 'admin'
  49. end
  50. end