redirects_controller.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # frozen_string_literal: true
  2. class Settings::Migration::RedirectsController < Settings::BaseController
  3. layout 'admin'
  4. before_action :authenticate_user!
  5. before_action :require_not_suspended!
  6. skip_before_action :require_functional!
  7. def new
  8. @redirect = Form::Redirect.new
  9. end
  10. def create
  11. @redirect = Form::Redirect.new(resource_params.merge(account: current_account))
  12. if @redirect.valid_with_challenge?(current_user)
  13. current_account.update!(moved_to_account: @redirect.target_account)
  14. ActivityPub::UpdateDistributionWorker.perform_async(current_account.id)
  15. redirect_to settings_migration_path, notice: I18n.t('migrations.redirected_msg', acct: current_account.moved_to_account.acct)
  16. else
  17. render :new
  18. end
  19. end
  20. def destroy
  21. if current_account.moved_to_account_id.present?
  22. current_account.update!(moved_to_account: nil)
  23. ActivityPub::UpdateDistributionWorker.perform_async(current_account.id)
  24. end
  25. redirect_to settings_migration_path, notice: I18n.t('migrations.cancelled_msg')
  26. end
  27. private
  28. def resource_params
  29. params.require(:form_redirect).permit(:acct, :current_password, :current_username)
  30. end
  31. def require_not_suspended!
  32. forbidden if current_account.suspended?
  33. end
  34. end