diff options
author | Chocobozzz <me@florianbigard.com> | 2018-01-11 17:37:49 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-01-11 17:45:57 +0100 |
commit | 4bbc373f134ecbf53f0198277663a25b26a19cc8 (patch) | |
tree | 77bb92e0f7003fcdf0746695d314bfaf19625daa /server | |
parent | cfe1efd200f80239e19f94335364ac9ef3813c19 (diff) | |
download | PeerTube-4bbc373f134ecbf53f0198277663a25b26a19cc8.tar.gz PeerTube-4bbc373f134ecbf53f0198277663a25b26a19cc8.tar.zst PeerTube-4bbc373f134ecbf53f0198277663a25b26a19cc8.zip |
Add reject processing for activitypub
Diffstat (limited to 'server')
4 files changed, 48 insertions, 1 deletions
diff --git a/server/helpers/custom-validators/activitypub/activity.ts b/server/helpers/custom-validators/activitypub/activity.ts index 577cf4b52..632f14223 100644 --- a/server/helpers/custom-validators/activitypub/activity.ts +++ b/server/helpers/custom-validators/activitypub/activity.ts | |||
@@ -1,6 +1,9 @@ | |||
1 | import * as validator from 'validator' | 1 | import * as validator from 'validator' |
2 | import { Activity, ActivityType } from '../../../../shared/models/activitypub' | 2 | import { Activity, ActivityType } from '../../../../shared/models/activitypub' |
3 | import { isActorAcceptActivityValid, isActorDeleteActivityValid, isActorFollowActivityValid, isActorUpdateActivityValid } from './actor' | 3 | import { |
4 | isActorAcceptActivityValid, isActorDeleteActivityValid, isActorFollowActivityValid, isActorRejectActivityValid, | ||
5 | isActorUpdateActivityValid | ||
6 | } from './actor' | ||
4 | import { isAnnounceActivityValid } from './announce' | 7 | import { isAnnounceActivityValid } from './announce' |
5 | import { isActivityPubUrlValid } from './misc' | 8 | import { isActivityPubUrlValid } from './misc' |
6 | import { isDislikeActivityValid, isLikeActivityValid } from './rate' | 9 | import { isDislikeActivityValid, isLikeActivityValid } from './rate' |
@@ -33,6 +36,7 @@ const activityCheckers: { [ P in ActivityType ]: (activity: Activity) => boolean | |||
33 | Delete: checkDeleteActivity, | 36 | Delete: checkDeleteActivity, |
34 | Follow: checkFollowActivity, | 37 | Follow: checkFollowActivity, |
35 | Accept: checkAcceptActivity, | 38 | Accept: checkAcceptActivity, |
39 | Reject: checkRejectActivity, | ||
36 | Announce: checkAnnounceActivity, | 40 | Announce: checkAnnounceActivity, |
37 | Undo: checkUndoActivity, | 41 | Undo: checkUndoActivity, |
38 | Like: checkLikeActivity | 42 | Like: checkLikeActivity |
@@ -82,6 +86,10 @@ function checkAcceptActivity (activity: any) { | |||
82 | return isActorAcceptActivityValid(activity) | 86 | return isActorAcceptActivityValid(activity) |
83 | } | 87 | } |
84 | 88 | ||
89 | function checkRejectActivity (activity: any) { | ||
90 | return isActorRejectActivityValid(activity) | ||
91 | } | ||
92 | |||
85 | function checkAnnounceActivity (activity: any) { | 93 | function checkAnnounceActivity (activity: any) { |
86 | return isAnnounceActivityValid(activity) | 94 | return isAnnounceActivityValid(activity) |
87 | } | 95 | } |
diff --git a/server/helpers/custom-validators/activitypub/actor.ts b/server/helpers/custom-validators/activitypub/actor.ts index e1a4b5b8f..df0edc30e 100644 --- a/server/helpers/custom-validators/activitypub/actor.ts +++ b/server/helpers/custom-validators/activitypub/actor.ts | |||
@@ -78,6 +78,10 @@ function isActorAcceptActivityValid (activity: any) { | |||
78 | return isBaseActivityValid(activity, 'Accept') | 78 | return isBaseActivityValid(activity, 'Accept') |
79 | } | 79 | } |
80 | 80 | ||
81 | function isActorRejectActivityValid (activity: any) { | ||
82 | return isBaseActivityValid(activity, 'Reject') | ||
83 | } | ||
84 | |||
81 | function isActorUpdateActivityValid (activity: any) { | 85 | function isActorUpdateActivityValid (activity: any) { |
82 | return isBaseActivityValid(activity, 'Update') && | 86 | return isBaseActivityValid(activity, 'Update') && |
83 | isActorObjectValid(activity.object) | 87 | isActorObjectValid(activity.object) |
@@ -97,6 +101,7 @@ export { | |||
97 | isActorFollowersCountValid, | 101 | isActorFollowersCountValid, |
98 | isActorFollowActivityValid, | 102 | isActorFollowActivityValid, |
99 | isActorAcceptActivityValid, | 103 | isActorAcceptActivityValid, |
104 | isActorRejectActivityValid, | ||
100 | isActorDeleteActivityValid, | 105 | isActorDeleteActivityValid, |
101 | isActorUpdateActivityValid | 106 | isActorUpdateActivityValid |
102 | } | 107 | } |
diff --git a/server/lib/activitypub/process/process-reject.ts b/server/lib/activitypub/process/process-reject.ts new file mode 100644 index 000000000..b2de28d79 --- /dev/null +++ b/server/lib/activitypub/process/process-reject.ts | |||
@@ -0,0 +1,32 @@ | |||
1 | import { ActivityReject } from '../../../../shared/models/activitypub/activity' | ||
2 | import { sequelizeTypescript } from '../../../initializers' | ||
3 | import { ActorModel } from '../../../models/activitypub/actor' | ||
4 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | ||
5 | |||
6 | async function processRejectActivity (activity: ActivityReject, inboxActor?: ActorModel) { | ||
7 | if (inboxActor === undefined) throw new Error('Need to reject on explicit inbox.') | ||
8 | |||
9 | const targetActor = await ActorModel.loadByUrl(activity.actor) | ||
10 | |||
11 | return processReject(inboxActor, targetActor) | ||
12 | } | ||
13 | |||
14 | // --------------------------------------------------------------------------- | ||
15 | |||
16 | export { | ||
17 | processRejectActivity | ||
18 | } | ||
19 | |||
20 | // --------------------------------------------------------------------------- | ||
21 | |||
22 | async function processReject (actor: ActorModel, targetActor: ActorModel) { | ||
23 | return sequelizeTypescript.transaction(async t => { | ||
24 | const actorFollow = await ActorFollowModel.loadByActorAndTarget(actor.id, targetActor.id, t) | ||
25 | |||
26 | if (!actorFollow) throw new Error(`'Unknown actor follow ${actor.id} -> ${targetActor.id}.`) | ||
27 | |||
28 | await actorFollow.destroy({ transaction: t }) | ||
29 | |||
30 | return undefined | ||
31 | }) | ||
32 | } | ||
diff --git a/server/lib/activitypub/process/process.ts b/server/lib/activitypub/process/process.ts index 62d310f21..810c28e26 100644 --- a/server/lib/activitypub/process/process.ts +++ b/server/lib/activitypub/process/process.ts | |||
@@ -7,6 +7,7 @@ import { processCreateActivity } from './process-create' | |||
7 | import { processDeleteActivity } from './process-delete' | 7 | import { processDeleteActivity } from './process-delete' |
8 | import { processFollowActivity } from './process-follow' | 8 | import { processFollowActivity } from './process-follow' |
9 | import { processLikeActivity } from './process-like' | 9 | import { processLikeActivity } from './process-like' |
10 | import { processRejectActivity } from './process-reject' | ||
10 | import { processUndoActivity } from './process-undo' | 11 | import { processUndoActivity } from './process-undo' |
11 | import { processUpdateActivity } from './process-update' | 12 | import { processUpdateActivity } from './process-update' |
12 | 13 | ||
@@ -16,6 +17,7 @@ const processActivity: { [ P in ActivityType ]: (activity: Activity, inboxActor? | |||
16 | Delete: processDeleteActivity, | 17 | Delete: processDeleteActivity, |
17 | Follow: processFollowActivity, | 18 | Follow: processFollowActivity, |
18 | Accept: processAcceptActivity, | 19 | Accept: processAcceptActivity, |
20 | Reject: processRejectActivity, | ||
19 | Announce: processAnnounceActivity, | 21 | Announce: processAnnounceActivity, |
20 | Undo: processUndoActivity, | 22 | Undo: processUndoActivity, |
21 | Like: processLikeActivity | 23 | Like: processLikeActivity |