diff options
Diffstat (limited to 'server/lib/activitypub/process/process-delete.ts')
-rw-r--r-- | server/lib/activitypub/process/process-delete.ts | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/server/lib/activitypub/process/process-delete.ts b/server/lib/activitypub/process/process-delete.ts index 3c830abea..038d8c4d3 100644 --- a/server/lib/activitypub/process/process-delete.ts +++ b/server/lib/activitypub/process/process-delete.ts | |||
@@ -7,41 +7,41 @@ import { ActorModel } from '../../../models/activitypub/actor' | |||
7 | import { VideoModel } from '../../../models/video/video' | 7 | import { VideoModel } from '../../../models/video/video' |
8 | import { VideoChannelModel } from '../../../models/video/video-channel' | 8 | import { VideoChannelModel } from '../../../models/video/video-channel' |
9 | import { VideoCommentModel } from '../../../models/video/video-comment' | 9 | import { VideoCommentModel } from '../../../models/video/video-comment' |
10 | import { getOrCreateActorAndServerAndModel } from '../actor' | ||
11 | import { forwardActivity } from '../send/utils' | 10 | import { forwardActivity } from '../send/utils' |
12 | 11 | ||
13 | async function processDeleteActivity (activity: ActivityDelete) { | 12 | async function processDeleteActivity (activity: ActivityDelete, byActor: ActorModel) { |
14 | const objectUrl = typeof activity.object === 'string' ? activity.object : activity.object.id | 13 | const objectUrl = typeof activity.object === 'string' ? activity.object : activity.object.id |
15 | 14 | ||
16 | if (activity.actor === objectUrl) { | 15 | if (activity.actor === objectUrl) { |
17 | let actor = await ActorModel.loadByUrl(activity.actor) | 16 | // We need more attributes (all the account and channel) |
18 | if (!actor) return undefined | 17 | const byActorFull = await ActorModel.loadByUrlAndPopulateAccountAndChannel(byActor.url) |
19 | 18 | ||
20 | if (actor.type === 'Person') { | 19 | if (byActorFull.type === 'Person') { |
21 | if (!actor.Account) throw new Error('Actor ' + actor.url + ' is a person but we cannot find it in database.') | 20 | if (!byActorFull.Account) throw new Error('Actor ' + byActorFull.url + ' is a person but we cannot find it in database.') |
22 | 21 | ||
23 | actor.Account.Actor = await actor.Account.$get('Actor') as ActorModel | 22 | byActorFull.Account.Actor = await byActorFull.Account.$get('Actor') as ActorModel |
24 | return retryTransactionWrapper(processDeleteAccount, actor.Account) | 23 | return retryTransactionWrapper(processDeleteAccount, byActorFull.Account) |
25 | } else if (actor.type === 'Group') { | 24 | } else if (byActorFull.type === 'Group') { |
26 | if (!actor.VideoChannel) throw new Error('Actor ' + actor.url + ' is a group but we cannot find it in database.') | 25 | if (!byActorFull.VideoChannel) throw new Error('Actor ' + byActorFull.url + ' is a group but we cannot find it in database.') |
27 | 26 | ||
28 | actor.VideoChannel.Actor = await actor.VideoChannel.$get('Actor') as ActorModel | 27 | byActorFull.VideoChannel.Actor = await byActorFull.VideoChannel.$get('Actor') as ActorModel |
29 | return retryTransactionWrapper(processDeleteVideoChannel, actor.VideoChannel) | 28 | return retryTransactionWrapper(processDeleteVideoChannel, byActorFull.VideoChannel) |
30 | } | 29 | } |
31 | } | 30 | } |
32 | 31 | ||
33 | const actor = await getOrCreateActorAndServerAndModel(activity.actor) | ||
34 | { | 32 | { |
35 | const videoCommentInstance = await VideoCommentModel.loadByUrlAndPopulateAccount(objectUrl) | 33 | const videoCommentInstance = await VideoCommentModel.loadByUrlAndPopulateAccount(objectUrl) |
36 | if (videoCommentInstance) { | 34 | if (videoCommentInstance) { |
37 | return retryTransactionWrapper(processDeleteVideoComment, actor, videoCommentInstance, activity) | 35 | return retryTransactionWrapper(processDeleteVideoComment, byActor, videoCommentInstance, activity) |
38 | } | 36 | } |
39 | } | 37 | } |
40 | 38 | ||
41 | { | 39 | { |
42 | const videoInstance = await VideoModel.loadByUrlAndPopulateAccount(objectUrl) | 40 | const videoInstance = await VideoModel.loadByUrlAndPopulateAccount(objectUrl) |
43 | if (videoInstance) { | 41 | if (videoInstance) { |
44 | return retryTransactionWrapper(processDeleteVideo, actor, videoInstance) | 42 | if (videoInstance.isOwned()) throw new Error(`Remote instance cannot delete owned video ${videoInstance.url}.`) |
43 | |||
44 | return retryTransactionWrapper(processDeleteVideo, byActor, videoInstance) | ||
45 | } | 45 | } |
46 | } | 46 | } |
47 | 47 | ||
@@ -94,6 +94,10 @@ function processDeleteVideoComment (byActor: ActorModel, videoComment: VideoComm | |||
94 | logger.debug('Removing remote video comment "%s".', videoComment.url) | 94 | logger.debug('Removing remote video comment "%s".', videoComment.url) |
95 | 95 | ||
96 | return sequelizeTypescript.transaction(async t => { | 96 | return sequelizeTypescript.transaction(async t => { |
97 | if (videoComment.Account.id !== byActor.Account.id) { | ||
98 | throw new Error('Account ' + byActor.url + ' does not own video comment ' + videoComment.url) | ||
99 | } | ||
100 | |||
97 | await videoComment.destroy({ transaction: t }) | 101 | await videoComment.destroy({ transaction: t }) |
98 | 102 | ||
99 | if (videoComment.Video.isOwned()) { | 103 | if (videoComment.Video.isOwned()) { |