diff options
author | Chocobozzz <me@florianbigard.com> | 2019-04-08 14:04:57 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-04-08 14:06:23 +0200 |
commit | 5b9c965d5aa747f29b081289f930ee215fdc23c8 (patch) | |
tree | 1c726117525230d74235e7fa986eb72e7376fb6c /server/lib/activitypub | |
parent | 594d0c6a7c64b045c11508bb4e4b19b75b3fc557 (diff) | |
download | PeerTube-5b9c965d5aa747f29b081289f930ee215fdc23c8.tar.gz PeerTube-5b9c965d5aa747f29b081289f930ee215fdc23c8.tar.zst PeerTube-5b9c965d5aa747f29b081289f930ee215fdc23c8.zip |
Add ability to forbid followers
Diffstat (limited to 'server/lib/activitypub')
-rw-r--r-- | server/lib/activitypub/process/process-follow.ts | 10 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-accept.ts | 2 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-follow.ts | 2 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-reject.ts | 18 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-undo.ts | 2 | ||||
-rw-r--r-- | server/lib/activitypub/url.ts | 12 |
6 files changed, 25 insertions, 21 deletions
diff --git a/server/lib/activitypub/process/process-follow.ts b/server/lib/activitypub/process/process-follow.ts index 0cd537187..cecf09b47 100644 --- a/server/lib/activitypub/process/process-follow.ts +++ b/server/lib/activitypub/process/process-follow.ts | |||
@@ -1,12 +1,13 @@ | |||
1 | import { ActivityFollow } from '../../../../shared/models/activitypub' | 1 | import { ActivityFollow } from '../../../../shared/models/activitypub' |
2 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | 2 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
3 | import { logger } from '../../../helpers/logger' | 3 | import { logger } from '../../../helpers/logger' |
4 | import { sequelizeTypescript } from '../../../initializers' | 4 | import { sequelizeTypescript, CONFIG } from '../../../initializers' |
5 | import { ActorModel } from '../../../models/activitypub/actor' | 5 | import { ActorModel } from '../../../models/activitypub/actor' |
6 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | 6 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' |
7 | import { sendAccept } from '../send' | 7 | import { sendAccept, sendReject } from '../send' |
8 | import { Notifier } from '../../notifier' | 8 | import { Notifier } from '../../notifier' |
9 | import { getAPId } from '../../../helpers/activitypub' | 9 | import { getAPId } from '../../../helpers/activitypub' |
10 | import { getServerActor } from '../../../helpers/utils' | ||
10 | 11 | ||
11 | async function processFollowActivity (activity: ActivityFollow, byActor: ActorModel) { | 12 | async function processFollowActivity (activity: ActivityFollow, byActor: ActorModel) { |
12 | const activityObject = getAPId(activity.object) | 13 | const activityObject = getAPId(activity.object) |
@@ -29,6 +30,11 @@ async function processFollow (actor: ActorModel, targetActorURL: string) { | |||
29 | if (!targetActor) throw new Error('Unknown actor') | 30 | if (!targetActor) throw new Error('Unknown actor') |
30 | if (targetActor.isOwned() === false) throw new Error('This is not a local actor.') | 31 | if (targetActor.isOwned() === false) throw new Error('This is not a local actor.') |
31 | 32 | ||
33 | const serverActor = await getServerActor() | ||
34 | if (targetActor.id === serverActor.id && CONFIG.FOLLOWERS.INSTANCE.ENABLED === false) { | ||
35 | return sendReject(actor, targetActor) | ||
36 | } | ||
37 | |||
32 | const [ actorFollow, created ] = await ActorFollowModel.findOrCreate({ | 38 | const [ actorFollow, created ] = await ActorFollowModel.findOrCreate({ |
33 | where: { | 39 | where: { |
34 | actorId: actor.id, | 40 | actorId: actor.id, |
diff --git a/server/lib/activitypub/send/send-accept.ts b/server/lib/activitypub/send/send-accept.ts index b6abde13d..388a9ed23 100644 --- a/server/lib/activitypub/send/send-accept.ts +++ b/server/lib/activitypub/send/send-accept.ts | |||
@@ -17,7 +17,7 @@ async function sendAccept (actorFollow: ActorFollowModel) { | |||
17 | 17 | ||
18 | logger.info('Creating job to accept follower %s.', follower.url) | 18 | logger.info('Creating job to accept follower %s.', follower.url) |
19 | 19 | ||
20 | const followUrl = getActorFollowActivityPubUrl(actorFollow) | 20 | const followUrl = getActorFollowActivityPubUrl(follower, me) |
21 | const followData = buildFollowActivity(followUrl, follower, me) | 21 | const followData = buildFollowActivity(followUrl, follower, me) |
22 | 22 | ||
23 | const url = getActorFollowAcceptActivityPubUrl(actorFollow) | 23 | const url = getActorFollowAcceptActivityPubUrl(actorFollow) |
diff --git a/server/lib/activitypub/send/send-follow.ts b/server/lib/activitypub/send/send-follow.ts index 170b46b48..2c3d02014 100644 --- a/server/lib/activitypub/send/send-follow.ts +++ b/server/lib/activitypub/send/send-follow.ts | |||
@@ -14,7 +14,7 @@ function sendFollow (actorFollow: ActorFollowModel) { | |||
14 | 14 | ||
15 | logger.info('Creating job to send follow request to %s.', following.url) | 15 | logger.info('Creating job to send follow request to %s.', following.url) |
16 | 16 | ||
17 | const url = getActorFollowActivityPubUrl(actorFollow) | 17 | const url = getActorFollowActivityPubUrl(me, following) |
18 | const data = buildFollowActivity(url, me, following) | 18 | const data = buildFollowActivity(url, me, following) |
19 | 19 | ||
20 | return unicastTo(data, me, following.inboxUrl) | 20 | return unicastTo(data, me, following.inboxUrl) |
diff --git a/server/lib/activitypub/send/send-reject.ts b/server/lib/activitypub/send/send-reject.ts index db8c2d86d..bac7ff556 100644 --- a/server/lib/activitypub/send/send-reject.ts +++ b/server/lib/activitypub/send/send-reject.ts | |||
@@ -1,15 +1,11 @@ | |||
1 | import { ActivityFollow, ActivityReject } from '../../../../shared/models/activitypub' | 1 | import { ActivityFollow, ActivityReject } from '../../../../shared/models/activitypub' |
2 | import { ActorModel } from '../../../models/activitypub/actor' | 2 | import { ActorModel } from '../../../models/activitypub/actor' |
3 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | 3 | import { getActorFollowActivityPubUrl, getActorFollowRejectActivityPubUrl } from '../url' |
4 | import { getActorFollowAcceptActivityPubUrl, getActorFollowActivityPubUrl } from '../url' | ||
5 | import { unicastTo } from './utils' | 4 | import { unicastTo } from './utils' |
6 | import { buildFollowActivity } from './send-follow' | 5 | import { buildFollowActivity } from './send-follow' |
7 | import { logger } from '../../../helpers/logger' | 6 | import { logger } from '../../../helpers/logger' |
8 | 7 | ||
9 | async function sendReject (actorFollow: ActorFollowModel) { | 8 | async function sendReject (follower: ActorModel, following: ActorModel) { |
10 | const follower = actorFollow.ActorFollower | ||
11 | const me = actorFollow.ActorFollowing | ||
12 | |||
13 | if (!follower.serverId) { // This should never happen | 9 | if (!follower.serverId) { // This should never happen |
14 | logger.warn('Do not sending reject to local follower.') | 10 | logger.warn('Do not sending reject to local follower.') |
15 | return | 11 | return |
@@ -17,13 +13,13 @@ async function sendReject (actorFollow: ActorFollowModel) { | |||
17 | 13 | ||
18 | logger.info('Creating job to reject follower %s.', follower.url) | 14 | logger.info('Creating job to reject follower %s.', follower.url) |
19 | 15 | ||
20 | const followUrl = getActorFollowActivityPubUrl(actorFollow) | 16 | const followUrl = getActorFollowActivityPubUrl(follower, following) |
21 | const followData = buildFollowActivity(followUrl, follower, me) | 17 | const followData = buildFollowActivity(followUrl, follower, following) |
22 | 18 | ||
23 | const url = getActorFollowAcceptActivityPubUrl(actorFollow) | 19 | const url = getActorFollowRejectActivityPubUrl(follower, following) |
24 | const data = buildRejectActivity(url, me, followData) | 20 | const data = buildRejectActivity(url, following, followData) |
25 | 21 | ||
26 | return unicastTo(data, me, follower.inboxUrl) | 22 | return unicastTo(data, following, follower.inboxUrl) |
27 | } | 23 | } |
28 | 24 | ||
29 | // --------------------------------------------------------------------------- | 25 | // --------------------------------------------------------------------------- |
diff --git a/server/lib/activitypub/send/send-undo.ts b/server/lib/activitypub/send/send-undo.ts index ecbf605d6..8727a121e 100644 --- a/server/lib/activitypub/send/send-undo.ts +++ b/server/lib/activitypub/send/send-undo.ts | |||
@@ -31,7 +31,7 @@ async function sendUndoFollow (actorFollow: ActorFollowModel, t: Transaction) { | |||
31 | 31 | ||
32 | logger.info('Creating job to send an unfollow request to %s.', following.url) | 32 | logger.info('Creating job to send an unfollow request to %s.', following.url) |
33 | 33 | ||
34 | const followUrl = getActorFollowActivityPubUrl(actorFollow) | 34 | const followUrl = getActorFollowActivityPubUrl(me, following) |
35 | const undoUrl = getUndoActivityPubUrl(followUrl) | 35 | const undoUrl = getUndoActivityPubUrl(followUrl) |
36 | 36 | ||
37 | const followActivity = buildFollowActivity(followUrl, me, following) | 37 | const followActivity = buildFollowActivity(followUrl, me, following) |
diff --git a/server/lib/activitypub/url.ts b/server/lib/activitypub/url.ts index 7c2ee5bc6..401b83fc2 100644 --- a/server/lib/activitypub/url.ts +++ b/server/lib/activitypub/url.ts | |||
@@ -74,11 +74,8 @@ function getVideoDislikesActivityPubUrl (video: VideoModel) { | |||
74 | return video.url + '/dislikes' | 74 | return video.url + '/dislikes' |
75 | } | 75 | } |
76 | 76 | ||
77 | function getActorFollowActivityPubUrl (actorFollow: ActorFollowModel) { | 77 | function getActorFollowActivityPubUrl (follower: ActorModel, following: ActorModel) { |
78 | const me = actorFollow.ActorFollower | 78 | return follower.url + '/follows/' + following.id |
79 | const following = actorFollow.ActorFollowing | ||
80 | |||
81 | return me.url + '/follows/' + following.id | ||
82 | } | 79 | } |
83 | 80 | ||
84 | function getActorFollowAcceptActivityPubUrl (actorFollow: ActorFollowModel) { | 81 | function getActorFollowAcceptActivityPubUrl (actorFollow: ActorFollowModel) { |
@@ -88,6 +85,10 @@ function getActorFollowAcceptActivityPubUrl (actorFollow: ActorFollowModel) { | |||
88 | return follower.url + '/accepts/follows/' + me.id | 85 | return follower.url + '/accepts/follows/' + me.id |
89 | } | 86 | } |
90 | 87 | ||
88 | function getActorFollowRejectActivityPubUrl (follower: ActorModel, following: ActorModel) { | ||
89 | return follower.url + '/rejects/follows/' + following.id | ||
90 | } | ||
91 | |||
91 | function getVideoAnnounceActivityPubUrl (byActor: ActorModel, video: VideoModel) { | 92 | function getVideoAnnounceActivityPubUrl (byActor: ActorModel, video: VideoModel) { |
92 | return video.url + '/announces/' + byActor.id | 93 | return video.url + '/announces/' + byActor.id |
93 | } | 94 | } |
@@ -120,6 +121,7 @@ export { | |||
120 | getVideoViewActivityPubUrl, | 121 | getVideoViewActivityPubUrl, |
121 | getVideoLikeActivityPubUrl, | 122 | getVideoLikeActivityPubUrl, |
122 | getVideoDislikeActivityPubUrl, | 123 | getVideoDislikeActivityPubUrl, |
124 | getActorFollowRejectActivityPubUrl, | ||
123 | getVideoCommentActivityPubUrl, | 125 | getVideoCommentActivityPubUrl, |
124 | getDeleteActivityPubUrl, | 126 | getDeleteActivityPubUrl, |
125 | getVideoSharesActivityPubUrl, | 127 | getVideoSharesActivityPubUrl, |