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.

44 lines
1.1 KiB

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