2017-11-27 22:47:06 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-12-12 22:32:13 +01:00
|
|
|
class Settings::MigrationsController < Settings::BaseController
|
2017-11-27 22:47:06 +01:00
|
|
|
layout 'admin'
|
|
|
|
|
|
|
|
before_action :authenticate_user!
|
2019-09-19 20:58:19 +02:00
|
|
|
before_action :require_not_suspended!
|
|
|
|
before_action :set_migrations
|
|
|
|
before_action :set_cooldown
|
|
|
|
|
|
|
|
skip_before_action :require_functional!
|
2017-11-27 22:47:06 +01:00
|
|
|
|
|
|
|
def show
|
2019-09-19 20:58:19 +02:00
|
|
|
@migration = current_account.migrations.build
|
2017-11-27 22:47:06 +01:00
|
|
|
end
|
|
|
|
|
2019-09-19 20:58:19 +02:00
|
|
|
def create
|
|
|
|
@migration = current_account.migrations.build(resource_params)
|
2017-11-27 22:47:06 +01:00
|
|
|
|
2019-09-19 20:58:19 +02:00
|
|
|
if @migration.save_with_challenge(current_user)
|
|
|
|
current_account.update!(moved_to_account: @migration.target_account)
|
2017-11-28 14:31:23 +01:00
|
|
|
ActivityPub::UpdateDistributionWorker.perform_async(current_account.id)
|
2019-09-19 20:58:19 +02:00
|
|
|
ActivityPub::MoveDistributionWorker.perform_async(@migration.id)
|
|
|
|
redirect_to settings_migration_path, notice: I18n.t('migrations.moved_msg', acct: current_account.moved_to_account.acct)
|
2017-11-27 22:47:06 +01:00
|
|
|
else
|
|
|
|
render :show
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-19 20:58:19 +02:00
|
|
|
def cancel
|
|
|
|
if current_account.moved_to_account_id.present?
|
|
|
|
current_account.update!(moved_to_account: nil)
|
|
|
|
ActivityPub::UpdateDistributionWorker.perform_async(current_account.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
redirect_to settings_migration_path, notice: I18n.t('migrations.cancelled_msg')
|
|
|
|
end
|
|
|
|
|
|
|
|
helper_method :on_cooldown?
|
|
|
|
|
2017-11-27 22:47:06 +01:00
|
|
|
private
|
|
|
|
|
|
|
|
def resource_params
|
2019-09-19 20:58:19 +02:00
|
|
|
params.require(:account_migration).permit(:acct, :current_password, :current_username)
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_migrations
|
|
|
|
@migrations = current_account.migrations.includes(:target_account).order(id: :desc).reject(&:new_record?)
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_cooldown
|
|
|
|
@cooldown = current_account.migrations.within_cooldown.first
|
|
|
|
end
|
|
|
|
|
|
|
|
def on_cooldown?
|
|
|
|
@cooldown.present?
|
2017-11-27 22:47:06 +01:00
|
|
|
end
|
2017-11-28 14:31:23 +01:00
|
|
|
|
2019-09-19 20:58:19 +02:00
|
|
|
def require_not_suspended!
|
|
|
|
forbidden if current_account.suspended?
|
2017-11-28 14:31:23 +01:00
|
|
|
end
|
2017-11-27 22:47:06 +01:00
|
|
|
end
|