forked from mastodon/mastodon
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add account migration UI (mastodon#11846)
Fix mastodon#10736 - Change data export to be available for non-functional accounts - Change non-functional accounts to include redirecting accounts
- Loading branch information
1 parent
aa1ac2d
commit ac3fd84
Showing
31 changed files
with
542 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# frozen_string_literal: true | ||
|
||
class Settings::AliasesController < Settings::BaseController | ||
layout 'admin' | ||
|
||
before_action :authenticate_user! | ||
before_action :set_aliases, except: :destroy | ||
before_action :set_alias, only: :destroy | ||
|
||
def index | ||
@alias = current_account.aliases.build | ||
end | ||
|
||
def create | ||
@alias = current_account.aliases.build(resource_params) | ||
|
||
if @alias.save | ||
redirect_to settings_aliases_path, notice: I18n.t('aliases.created_msg') | ||
else | ||
render :show | ||
end | ||
end | ||
|
||
def destroy | ||
@alias.destroy! | ||
redirect_to settings_aliases_path, notice: I18n.t('aliases.deleted_msg') | ||
end | ||
|
||
private | ||
|
||
def resource_params | ||
params.require(:account_alias).permit(:acct) | ||
end | ||
|
||
def set_alias | ||
@alias = current_account.aliases.find(params[:id]) | ||
end | ||
|
||
def set_aliases | ||
@aliases = current_account.aliases.order(id: :desc).reject(&:new_record?) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# frozen_string_literal: true | ||
|
||
# == Schema Information | ||
# | ||
# Table name: account_aliases | ||
# | ||
# id :bigint(8) not null, primary key | ||
# account_id :bigint(8) | ||
# acct :string default(""), not null | ||
# uri :string default(""), not null | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
|
||
class AccountAlias < ApplicationRecord | ||
belongs_to :account | ||
|
||
validates :acct, presence: true, domain: { acct: true } | ||
validates :uri, presence: true | ||
|
||
before_validation :set_uri | ||
after_create :add_to_account | ||
after_destroy :remove_from_account | ||
|
||
private | ||
|
||
def set_uri | ||
target_account = ResolveAccountService.new.call(acct) | ||
self.uri = ActivityPub::TagManager.instance.uri_for(target_account) unless target_account.nil? | ||
rescue Goldfinger::Error, HTTP::Error, OpenSSL::SSL::SSLError, Mastodon::Error | ||
# Validation will take care of it | ||
end | ||
|
||
def add_to_account | ||
account.update(also_known_as: account.also_known_as + [uri]) | ||
end | ||
|
||
def remove_from_account | ||
account.update(also_known_as: account.also_known_as.reject { |x| x == uri }) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# frozen_string_literal: true | ||
|
||
# == Schema Information | ||
# | ||
# Table name: account_migrations | ||
# | ||
# id :bigint(8) not null, primary key | ||
# account_id :bigint(8) | ||
# acct :string default(""), not null | ||
# followers_count :bigint(8) default(0), not null | ||
# target_account_id :bigint(8) | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
|
||
class AccountMigration < ApplicationRecord | ||
COOLDOWN_PERIOD = 30.days.freeze | ||
|
||
belongs_to :account | ||
belongs_to :target_account, class_name: 'Account' | ||
|
||
before_validation :set_target_account | ||
before_validation :set_followers_count | ||
|
||
validates :acct, presence: true, domain: { acct: true } | ||
validate :validate_migration_cooldown | ||
validate :validate_target_account | ||
|
||
scope :within_cooldown, ->(now = Time.now.utc) { where(arel_table[:created_at].gteq(now - COOLDOWN_PERIOD)) } | ||
|
||
attr_accessor :current_password, :current_username | ||
|
||
def save_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? | ||
|
||
save | ||
end | ||
|
||
def cooldown_at | ||
created_at + COOLDOWN_PERIOD | ||
end | ||
|
||
private | ||
|
||
def set_target_account | ||
self.target_account = ResolveAccountService.new.call(acct) | ||
rescue Goldfinger::Error, HTTP::Error, OpenSSL::SSL::SSLError, Mastodon::Error | ||
# Validation will take care of it | ||
end | ||
|
||
def set_followers_count | ||
self.followers_count = account.followers_count | ||
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.missing_also_known_as')) unless target_account.also_known_as.include?(ActivityPub::TagManager.instance.uri_for(account)) | ||
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 | ||
|
||
def validate_migration_cooldown | ||
errors.add(:base, I18n.t('migrations.errors.on_cooldown')) if account.migrations.within_cooldown.exists? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
class ActivityPub::MoveSerializer < ActivityPub::Serializer | ||
attributes :id, :type, :target, :actor | ||
attribute :virtual_object, key: :object | ||
|
||
def id | ||
[ActivityPub::TagManager.instance.uri_for(object.account), '#moves/', object.id].join | ||
end | ||
|
||
def type | ||
'Move' | ||
end | ||
|
||
def target | ||
ActivityPub::TagManager.instance.uri_for(object.target_account) | ||
end | ||
|
||
def virtual_object | ||
ActivityPub::TagManager.instance.uri_for(object.account) | ||
end | ||
|
||
def actor | ||
ActivityPub::TagManager.instance.uri_for(object.account) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,22 @@ | ||
%h3= t('auth.status.account_status') | ||
|
||
- if @user.account.suspended? | ||
%span.negative-hint= t('user_mailer.warning.explanation.suspend') | ||
- elsif @user.disabled? | ||
%span.negative-hint= t('user_mailer.warning.explanation.disable') | ||
- elsif @user.account.silenced? | ||
%span.warning-hint= t('user_mailer.warning.explanation.silence') | ||
- elsif !@user.confirmed? | ||
%span.warning-hint= t('auth.status.confirming') | ||
- elsif !@user.approved? | ||
%span.warning-hint= t('auth.status.pending') | ||
- else | ||
%span.positive-hint= t('auth.status.functional') | ||
.simple_form | ||
%p.hint | ||
- if @user.account.suspended? | ||
%span.negative-hint= t('user_mailer.warning.explanation.suspend') | ||
- elsif @user.disabled? | ||
%span.negative-hint= t('user_mailer.warning.explanation.disable') | ||
- elsif @user.account.silenced? | ||
%span.warning-hint= t('user_mailer.warning.explanation.silence') | ||
- elsif !@user.confirmed? | ||
%span.warning-hint= t('auth.status.confirming') | ||
= link_to t('auth.didnt_get_confirmation'), new_user_confirmation_path | ||
- elsif !@user.approved? | ||
%span.warning-hint= t('auth.status.pending') | ||
- elsif @user.account.moved_to_account_id.present? | ||
%span.positive-hint= t('auth.status.redirecting_to', acct: @user.account.moved_to_account.acct) | ||
= link_to t('migrations.cancel'), settings_migration_path | ||
- else | ||
%span.positive-hint= t('auth.status.functional') | ||
|
||
%hr.spacer/ |
Oops, something went wrong.