mirror of
https://github.com/mastodon/mastodon.git
synced 2025-12-11 11:52:42 +00:00
Allow username updates for Update Actor
This commit is contained in:
parent
eb18e5df29
commit
24ac1c1204
|
|
@ -20,7 +20,7 @@ class ActivityPub::Activity::Update < ActivityPub::Activity
|
|||
def update_account
|
||||
return reject_payload! if @account.uri != object_uri
|
||||
|
||||
ActivityPub::ProcessAccountService.new.call(@account.username, @account.domain, @object, signed_with_known_key: true, request_id: @options[:request_id])
|
||||
ActivityPub::ProcessAccountService.new.call(@account.username, @account.domain, @object, signed_with_known_key: true, request_id: @options[:request_id], allow_username_update: true)
|
||||
end
|
||||
|
||||
def update_status
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class ActivityPub::ProcessAccountService < BaseService
|
|||
@options[:request_id] ||= "#{Time.now.utc.to_i}-#{username}@#{domain}"
|
||||
|
||||
with_redis_lock("process_account:#{@uri}") do
|
||||
@account = Account.remote.find_by(uri: @uri) if @options[:only_key]
|
||||
@account = Account.remote.find_by(uri: @uri) if find_remote_account_by_uri?
|
||||
@account ||= Account.find_remote(@username, @domain)
|
||||
@old_public_key = @account&.public_key
|
||||
@old_protocol = @account&.protocol
|
||||
|
|
@ -69,6 +69,10 @@ class ActivityPub::ProcessAccountService < BaseService
|
|||
|
||||
private
|
||||
|
||||
def find_remote_account_by_uri?
|
||||
@options[:only_key] || @options[:allow_username_update]
|
||||
end
|
||||
|
||||
def create_account
|
||||
@account = Account.new
|
||||
@account.protocol = :activitypub
|
||||
|
|
@ -131,6 +135,7 @@ class ActivityPub::ProcessAccountService < BaseService
|
|||
@account.indexable = @json['indexable'] || false
|
||||
@account.memorial = @json['memorial'] || false
|
||||
@account.attribution_domains = as_array(@json['attributionDomains'] || []).map { |item| value_or_id(item) }
|
||||
@account.username = @json['preferredUsername'] if @options[:allow_username_update]
|
||||
end
|
||||
|
||||
def set_fetchable_key!
|
||||
|
|
|
|||
|
|
@ -178,10 +178,10 @@ RSpec.describe ActivityPub::InboxesController, :sidekiq_inline do
|
|||
end.to(not_change { Account.count })
|
||||
end
|
||||
|
||||
it 'does not update the remote actors username' do
|
||||
it 'updates the remote actors username' do
|
||||
post "/users/#{local_actor.username}/inbox", params: json.to_json, headers: headers
|
||||
expect(response).to have_http_status(202)
|
||||
expect(remote_actor.reload.username).to eq(remote_actor_original_username)
|
||||
expect(remote_actor.reload.username).to eq(remote_actor_new_username)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user