statuses_cleanup_controller.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # frozen_string_literal: true
  2. class StatusesCleanupController < ApplicationController
  3. layout 'admin'
  4. before_action :authenticate_user!
  5. before_action :set_policy
  6. before_action :set_body_classes
  7. before_action :set_cache_headers
  8. def show; end
  9. def update
  10. if @policy.update(resource_params)
  11. redirect_to statuses_cleanup_path, notice: I18n.t('generic.changes_saved_msg')
  12. else
  13. render :show
  14. end
  15. rescue ActionController::ParameterMissing
  16. # Do nothing
  17. end
  18. def require_functional!
  19. redirect_to edit_user_registration_path unless current_user.functional_or_moved?
  20. end
  21. private
  22. def set_policy
  23. @policy = current_account.statuses_cleanup_policy || current_account.build_statuses_cleanup_policy(enabled: false)
  24. end
  25. def resource_params
  26. params.require(:account_statuses_cleanup_policy).permit(:enabled, :min_status_age, :keep_direct, :keep_pinned, :keep_polls, :keep_media, :keep_self_fav, :keep_self_bookmark, :min_favs, :min_reblogs)
  27. end
  28. def set_body_classes
  29. @body_classes = 'admin'
  30. end
  31. def set_cache_headers
  32. response.cache_control.replace(private: true, no_store: true)
  33. end
  34. end