statuses_cleanup_controller.rb 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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_cache_headers
  7. def show; end
  8. def update
  9. if @policy.update(resource_params)
  10. redirect_to statuses_cleanup_path, notice: I18n.t('generic.changes_saved_msg')
  11. else
  12. render :show
  13. end
  14. rescue ActionController::ParameterMissing
  15. # Do nothing
  16. end
  17. def require_functional!
  18. redirect_to edit_user_registration_path unless current_user.functional_or_moved?
  19. end
  20. private
  21. def set_policy
  22. @policy = current_account.statuses_cleanup_policy || current_account.build_statuses_cleanup_policy(enabled: false)
  23. end
  24. def resource_params
  25. 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)
  26. end
  27. def set_cache_headers
  28. response.cache_control.replace(private: true, no_store: true)
  29. end
  30. end