migrations_controller.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. MoveService.new.call(@migration)
  16. redirect_to settings_migration_path, notice: I18n.t('migrations.moved_msg', acct: current_account.moved_to_account.acct)
  17. else
  18. render :show
  19. end
  20. end
  21. helper_method :on_cooldown?
  22. private
  23. def resource_params
  24. params.require(:account_migration).permit(:acct, :current_password, :current_username)
  25. end
  26. def set_migrations
  27. @migrations = current_account.migrations.includes(:target_account).order(id: :desc).reject(&:new_record?)
  28. end
  29. def set_cooldown
  30. @cooldown = current_account.migrations.within_cooldown.first
  31. end
  32. def on_cooldown?
  33. @cooldown.present?
  34. end
  35. def require_not_suspended!
  36. forbidden if current_account.suspended?
  37. end
  38. end