redirects_controller.rb 1.1 KB

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