Add (back) option to set redirect notice on account without moving followers (#11994)
Fix #11913master
parent
b0cda7a504
commit
163ed91af3
@ -0,0 +1,45 @@ |
|||||||
|
# frozen_string_literal: true |
||||||
|
|
||||||
|
class Settings::Migration::RedirectsController < Settings::BaseController |
||||||
|
layout 'admin' |
||||||
|
|
||||||
|
before_action :authenticate_user! |
||||||
|
before_action :require_not_suspended! |
||||||
|
|
||||||
|
skip_before_action :require_functional! |
||||||
|
|
||||||
|
def new |
||||||
|
@redirect = Form::Redirect.new |
||||||
|
end |
||||||
|
|
||||||
|
def create |
||||||
|
@redirect = Form::Redirect.new(resource_params.merge(account: current_account)) |
||||||
|
|
||||||
|
if @redirect.valid_with_challenge?(current_user) |
||||||
|
current_account.update!(moved_to_account: @redirect.target_account) |
||||||
|
ActivityPub::UpdateDistributionWorker.perform_async(current_account.id) |
||||||
|
redirect_to settings_migration_path, notice: I18n.t('migrations.moved_msg', acct: current_account.moved_to_account.acct) |
||||||
|
else |
||||||
|
render :new |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
def destroy |
||||||
|
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 |
||||||
|
|
||||||
|
private |
||||||
|
|
||||||
|
def resource_params |
||||||
|
params.require(:form_redirect).permit(:acct, :current_password, :current_username) |
||||||
|
end |
||||||
|
|
||||||
|
def require_not_suspended! |
||||||
|
forbidden if current_account.suspended? |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,47 @@ |
|||||||
|
# frozen_string_literal: true |
||||||
|
|
||||||
|
class Form::Redirect |
||||||
|
include ActiveModel::Model |
||||||
|
|
||||||
|
attr_accessor :account, :target_account, :current_password, |
||||||
|
:current_username |
||||||
|
|
||||||
|
attr_reader :acct |
||||||
|
|
||||||
|
validates :acct, presence: true, domain: { acct: true } |
||||||
|
validate :validate_target_account |
||||||
|
|
||||||
|
def valid_with_challenge?(current_user) |
||||||
|
if current_user.encrypted_password.present? |
||||||
|
errors.add(:current_password, :invalid) unless current_user.valid_password?(current_password) |
||||||
|
else |
||||||
|
errors.add(:current_username, :invalid) unless account.username == current_username |
||||||
|
end |
||||||
|
|
||||||
|
return false unless errors.empty? |
||||||
|
|
||||||
|
set_target_account |
||||||
|
valid? |
||||||
|
end |
||||||
|
|
||||||
|
def acct=(val) |
||||||
|
@acct = val.to_s.strip.gsub(/\A@/, '') |
||||||
|
end |
||||||
|
|
||||||
|
private |
||||||
|
|
||||||
|
def set_target_account |
||||||
|
@target_account = ResolveAccountService.new.call(acct) |
||||||
|
rescue Goldfinger::Error, HTTP::Error, OpenSSL::SSL::SSLError, Mastodon::Error |
||||||
|
# Validation will take care of it |
||||||
|
end |
||||||
|
|
||||||
|
def validate_target_account |
||||||
|
if target_account.nil? |
||||||
|
errors.add(:acct, I18n.t('migrations.errors.not_found')) |
||||||
|
else |
||||||
|
errors.add(:acct, I18n.t('migrations.errors.already_moved')) if account.moved_to_account_id.present? && account.moved_to_account_id == target_account.id |
||||||
|
errors.add(:acct, I18n.t('migrations.errors.move_to_self')) if account.id == target_account.id |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,27 @@ |
|||||||
|
- content_for :page_title do |
||||||
|
= t('settings.migrate') |
||||||
|
|
||||||
|
= simple_form_for @redirect, url: settings_migration_redirect_path do |f| |
||||||
|
%p.hint= t('migrations.warning.before') |
||||||
|
|
||||||
|
%ul.hint |
||||||
|
%li.warning-hint= t('migrations.warning.redirect') |
||||||
|
%li.warning-hint= t('migrations.warning.other_data') |
||||||
|
%li.warning-hint= t('migrations.warning.disabled_account') |
||||||
|
|
||||||
|
%hr.spacer/ |
||||||
|
|
||||||
|
= render 'shared/error_messages', object: @redirect |
||||||
|
|
||||||
|
.fields-row |
||||||
|
.fields-row__column.fields-group.fields-row__column-6 |
||||||
|
= f.input :acct, wrapper: :with_block_label, input_html: { autocapitalize: 'none', autocorrect: 'off' }, label: t('simple_form.labels.account_migration.acct'), hint: t('simple_form.hints.account_migration.acct') |
||||||
|
|
||||||
|
.fields-row__column.fields-group.fields-row__column-6 |
||||||
|
- if current_user.encrypted_password.present? |
||||||
|
= f.input :current_password, wrapper: :with_block_label, input_html: { :autocomplete => 'off' }, required: true |
||||||
|
- else |
||||||
|
= f.input :current_username, wrapper: :with_block_label, input_html: { :autocomplete => 'off' }, required: true |
||||||
|
|
||||||
|
.actions |
||||||
|
= f.button :button, t('migrations.set_redirect'), type: :submit, class: 'button button--destructive' |
Loading…
Reference in new issue