From 6451b853e76cf2059e8605e8db553efce9c86927 Mon Sep 17 00:00:00 2001 From: KMY Date: Fri, 13 Oct 2023 18:37:43 +0900 Subject: [PATCH] =?UTF-8?q?Change:=20#82=20=E3=83=95=E3=83=AC=E3=83=B3?= =?UTF-8?q?=E3=83=89=E7=94=B3=E8=AB=8B=E6=99=82=E3=80=81=E8=87=AA=E5=88=86?= =?UTF-8?q?=E3=81=AE=E3=82=B5=E3=83=BC=E3=83=90=E3=83=BC=E3=81=AEInbox=20U?= =?UTF-8?q?RL=E3=82=92=E4=BC=9D=E3=81=88=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/lib/activitypub/activity/follow.rb | 2 +- app/models/friend_domain.rb | 11 +++++------ spec/lib/activitypub/activity/follow_spec.rb | 20 ++++++++++++++++++++ spec/models/friend_domain_spec.rb | 1 + 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/app/lib/activitypub/activity/follow.rb b/app/lib/activitypub/activity/follow.rb index f5a0250163404e..fdded984402323 100644 --- a/app/lib/activitypub/activity/follow.rb +++ b/app/lib/activitypub/activity/follow.rb @@ -53,7 +53,7 @@ def request_follow_for_friend friend.update!(passive_state: :pending, active_state: :idle, passive_follow_activity_id: @json['id']) else @friend = FriendDomain.new(domain: @account.domain, passive_state: :pending, passive_follow_activity_id: @json['id']) - @friend.initialize_inbox_url! + @friend.inbox_url = @json['inboxUrl'].presence || @friend.default_inbox_url @friend.save! end diff --git a/app/models/friend_domain.rb b/app/models/friend_domain.rb index 28cc59b334469a..084250003303de 100644 --- a/app/models/friend_domain.rb +++ b/app/models/friend_domain.rb @@ -93,16 +93,12 @@ def destroy_without_signal! destroy! end - def initialize_inbox_url! - self.inbox_url = default_inbox_url - end - - private - def default_inbox_url "https://#{domain}/inbox" end + private + def delete_for_friend! activity_id = ActivityPub::TagManager.instance.generate_uri_for(nil) payload = Oj.dump(delete_follow_activity(activity_id)) @@ -118,6 +114,9 @@ def follow_activity(activity_id) type: 'Follow', actor: ActivityPub::TagManager.instance.uri_for(some_local_account), object: ActivityPub::TagManager::COLLECTIONS[:public], + + # Cannot use inbox_url method because this model also has inbox_url column + inboxUrl: "https://#{Rails.configuration.x.web_domain}/inbox", } end diff --git a/spec/lib/activitypub/activity/follow_spec.rb b/spec/lib/activitypub/activity/follow_spec.rb index c27696ebaf1165..53ce9a29a6a4cd 100644 --- a/spec/lib/activitypub/activity/follow_spec.rb +++ b/spec/lib/activitypub/activity/follow_spec.rb @@ -310,6 +310,7 @@ let!(:friend) { Fabricate(:friend_domain, domain: 'abc.com', passive_state: :idle) } let!(:owner_user) { Fabricate(:user, role: UserRole.find_by(name: 'Owner')) } let!(:patch_user) { Fabricate(:user, role: Fabricate(:user_role, name: 'OhagiOps', permissions: UserRole::FLAGS[:manage_federation])) } + let(:inbox_url) { nil } let(:json) do { @@ -318,6 +319,7 @@ type: 'Follow', actor: ActivityPub::TagManager.instance.uri_for(sender), object: 'https://www.w3.org/ns/activitystreams#Public', + inboxUrl: inbox_url, }.with_indifferent_access end @@ -343,6 +345,24 @@ end end + context 'when no record and inbox_url is specified' do + let(:inbox_url) { 'https://ohagi.com/inbox' } + + before do + friend.update(domain: 'def.com') + end + + it 'marks the friend as pending' do + subject.perform + + friend = FriendDomain.find_by(domain: 'abc.com') + expect(friend).to_not be_nil + expect(friend.they_are_pending?).to be true + expect(friend.passive_follow_activity_id).to eq 'foo' + expect(friend.inbox_url).to eq 'https://ohagi.com/inbox' + end + end + context 'when my server is pending' do before do friend.update(active_state: :pending) diff --git a/spec/models/friend_domain_spec.rb b/spec/models/friend_domain_spec.rb index 647c39e5a8d5fd..65d090f9a7a652 100644 --- a/spec/models/friend_domain_spec.rb +++ b/spec/models/friend_domain_spec.rb @@ -21,6 +21,7 @@ type: 'Follow', actor: 'https://cb6e6126.ngrok.io/actor', object: 'https://www.w3.org/ns/activitystreams#Public', + inboxUrl: 'https://cb6e6126.ngrok.io/inbox', }))).to have_been_made.once end end