From df0b219d36bf6852cdf2a7ad09ed4a41c6bccefa Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 5 Mar 2019 10:58:44 +0100 Subject: Add playlist rest tests --- server/lib/activitypub/playlist.ts | 4 +++- server/lib/activitypub/process/process-delete.ts | 24 ++++++++++++++++++++++++ server/lib/activitypub/send/send-create.ts | 2 +- server/lib/activitypub/send/send-delete.ts | 7 ++++++- server/lib/activitypub/send/send-update.ts | 4 ++-- 5 files changed, 36 insertions(+), 5 deletions(-) (limited to 'server/lib/activitypub') diff --git a/server/lib/activitypub/playlist.ts b/server/lib/activitypub/playlist.ts index c9b428c92..70389044e 100644 --- a/server/lib/activitypub/playlist.ts +++ b/server/lib/activitypub/playlist.ts @@ -28,7 +28,9 @@ function playlistObjectToDBAttributes (playlistObject: PlaylistObject, byAccount url: playlistObject.id, uuid: playlistObject.uuid, ownerAccountId: byAccount.id, - videoChannelId: null + videoChannelId: null, + createdAt: new Date(playlistObject.published), + updatedAt: new Date(playlistObject.updated) } } diff --git a/server/lib/activitypub/process/process-delete.ts b/server/lib/activitypub/process/process-delete.ts index 155d2ffcc..76f07fd8a 100644 --- a/server/lib/activitypub/process/process-delete.ts +++ b/server/lib/activitypub/process/process-delete.ts @@ -8,6 +8,7 @@ import { VideoModel } from '../../../models/video/video' import { VideoChannelModel } from '../../../models/video/video-channel' import { VideoCommentModel } from '../../../models/video/video-comment' import { forwardVideoRelatedActivity } from '../send/utils' +import { VideoPlaylistModel } from '../../../models/video/video-playlist' async function processDeleteActivity (activity: ActivityDelete, byActor: ActorModel) { const objectUrl = typeof activity.object === 'string' ? activity.object : activity.object.id @@ -45,6 +46,15 @@ async function processDeleteActivity (activity: ActivityDelete, byActor: ActorMo } } + { + const videoPlaylist = await VideoPlaylistModel.loadByUrlAndPopulateAccount(objectUrl) + if (videoPlaylist) { + if (videoPlaylist.isOwned()) throw new Error(`Remote instance cannot delete owned playlist ${videoPlaylist.url}.`) + + return retryTransactionWrapper(processDeleteVideoPlaylist, byActor, videoPlaylist) + } + } + return undefined } @@ -70,6 +80,20 @@ async function processDeleteVideo (actor: ActorModel, videoToDelete: VideoModel) logger.info('Remote video with uuid %s removed.', videoToDelete.uuid) } +async function processDeleteVideoPlaylist (actor: ActorModel, playlistToDelete: VideoPlaylistModel) { + logger.debug('Removing remote video playlist "%s".', playlistToDelete.uuid) + + await sequelizeTypescript.transaction(async t => { + if (playlistToDelete.OwnerAccount.Actor.id !== actor.id) { + throw new Error('Account ' + actor.url + ' does not own video playlist ' + playlistToDelete.url) + } + + await playlistToDelete.destroy({ transaction: t }) + }) + + logger.info('Remote video playlist with uuid %s removed.', playlistToDelete.uuid) +} + async function processDeleteAccount (accountToRemove: AccountModel) { logger.debug('Removing remote account "%s".', accountToRemove.Actor.uuid) diff --git a/server/lib/activitypub/send/send-create.ts b/server/lib/activitypub/send/send-create.ts index bacdb97e3..28f18595b 100644 --- a/server/lib/activitypub/send/send-create.ts +++ b/server/lib/activitypub/send/send-create.ts @@ -45,7 +45,7 @@ async function sendCreateVideoPlaylist (playlist: VideoPlaylistModel, t: Transac const byActor = playlist.OwnerAccount.Actor const audience = getAudience(byActor, playlist.privacy === VideoPlaylistPrivacy.PUBLIC) - const object = await playlist.toActivityPubObject() + const object = await playlist.toActivityPubObject(null, t) const createActivity = buildCreateActivity(playlist.url, byActor, object, audience) const serverActor = await getServerActor() diff --git a/server/lib/activitypub/send/send-delete.ts b/server/lib/activitypub/send/send-delete.ts index 016811e60..7bf5ca520 100644 --- a/server/lib/activitypub/send/send-delete.ts +++ b/server/lib/activitypub/send/send-delete.ts @@ -31,7 +31,12 @@ async function sendDeleteActor (byActor: ActorModel, t: Transaction) { const url = getDeleteActivityPubUrl(byActor.url) const activity = buildDeleteActivity(url, byActor.url, byActor) - const actorsInvolved = await VideoShareModel.loadActorsByVideoOwner(byActor.id, t) + const actorsInvolved = await VideoShareModel.loadActorsWhoSharedVideosOf(byActor.id, t) + + // In case the actor did not have any videos + const serverActor = await getServerActor() + actorsInvolved.push(serverActor) + actorsInvolved.push(byActor) return broadcastToFollowers(activity, byActor, actorsInvolved, t) diff --git a/server/lib/activitypub/send/send-update.ts b/server/lib/activitypub/send/send-update.ts index 3eb2704fd..7411c08d5 100644 --- a/server/lib/activitypub/send/send-update.ts +++ b/server/lib/activitypub/send/send-update.ts @@ -52,7 +52,7 @@ async function sendUpdateActor (accountOrChannel: AccountModel | VideoChannelMod let actorsInvolved: ActorModel[] if (accountOrChannel instanceof AccountModel) { // Actors that shared my videos are involved too - actorsInvolved = await VideoShareModel.loadActorsByVideoOwner(byActor.id, t) + actorsInvolved = await VideoShareModel.loadActorsWhoSharedVideosOf(byActor.id, t) } else { // Actors that shared videos of my channel are involved too actorsInvolved = await VideoShareModel.loadActorsByVideoChannel(accountOrChannel.id, t) @@ -87,7 +87,7 @@ async function sendUpdateVideoPlaylist (videoPlaylist: VideoPlaylistModel, t: Tr const url = getUpdateActivityPubUrl(videoPlaylist.url, videoPlaylist.updatedAt.toISOString()) - const object = await videoPlaylist.toActivityPubObject() + const object = await videoPlaylist.toActivityPubObject(null, t) const audience = getAudience(byActor, videoPlaylist.privacy === VideoPlaylistPrivacy.PUBLIC) const updateActivity = buildUpdateActivity(url, byActor, object, audience) -- cgit v1.2.3