You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.4 KiB

  1. # frozen_string_literal: true
  2. class Settings::MigrationsController < Settings::BaseController
  3. layout 'admin'
  4. before_action :authenticate_user!
  5. before_action :require_not_suspended!
  6. before_action :set_migrations
  7. before_action :set_cooldown
  8. skip_before_action :require_functional!
  9. def show
  10. @migration = current_account.migrations.build
  11. end
  12. def create
  13. @migration = current_account.migrations.build(resource_params)
  14. if @migration.save_with_challenge(current_user)
  15. current_account.update!(moved_to_account: @migration.target_account)
  16. ActivityPub::UpdateDistributionWorker.perform_async(current_account.id)
  17. ActivityPub::MoveDistributionWorker.perform_async(@migration.id)
  18. redirect_to settings_migration_path, notice: I18n.t('migrations.moved_msg', acct: current_account.moved_to_account.acct)
  19. else
  20. render :show
  21. end
  22. end
  23. helper_method :on_cooldown?
  24. private
  25. def resource_params
  26. params.require(:account_migration).permit(:acct, :current_password, :current_username)
  27. end
  28. def set_migrations
  29. @migrations = current_account.migrations.includes(:target_account).order(id: :desc).reject(&:new_record?)
  30. end
  31. def set_cooldown
  32. @cooldown = current_account.migrations.within_cooldown.first
  33. end
  34. def on_cooldown?
  35. @cooldown.present?
  36. end
  37. def require_not_suspended!
  38. forbidden if current_account.suspended?
  39. end
  40. end