From a37e9e74ff07b057370d1ed6c0b391a02be8a6d2 Mon Sep 17 00:00:00 2001 From: kontrollanten <6680299+kontrollanten@users.noreply.github.com> Date: Mon, 13 Dec 2021 15:29:13 +0100 Subject: Give moderators access to edit channels (#4608) * give admins access to edit all channels closes #4598 * test(channels): +admin update another users channel * Fix tests * fix(server): delete another users channel Since the channel owner isn't necessary the auth user we need to check the right account whether it's the last video or not. * REMOVE_ANY_VIDEO_CHANNEL > MANAGE_ANY_VIDEO_CHANNEL Merge REMOVE_ANY_VIDEO_CHANNEL and MANY_VIDEO_CHANNELS to MANAGE_ANY_VIDEO_CHANNEL. * user-right: moderator can't manage admins channel * client: MyVideoChannelCreateComponent > VideoChannelCreateComponent * client: MyVideoChannelEdit > VideoChannelEdit * Revert "user-right: moderator can't manage admins channel" This reverts commit 2c627c154e2bfe6af2e0f45efb27faf4117572f3. * server: clean dupl validator functionality * fix ensureUserCanManageChannel usage It's not async anymore. * server: merge channel validator middleares ensureAuthUserOwnsChannelValidator & ensureUserCanManageChannel gets merged into one middleware. * client(VideoChannelEdit): redirect to prev route * fix(VideoChannels): handle anon users * client: new routes for create/update channel * Refactor channel validators Co-authored-by: Chocobozzz --- server/controllers/activitypub/client.ts | 23 ++++++++++++++--------- server/controllers/activitypub/inbox.ts | 14 +++++++++++--- server/controllers/activitypub/outbox.ts | 13 +++++++------ 3 files changed, 32 insertions(+), 18 deletions(-) (limited to 'server/controllers/activitypub') diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts index c4e3cec6b..4e6bd5e25 100644 --- a/server/controllers/activitypub/client.ts +++ b/server/controllers/activitypub/client.ts @@ -20,7 +20,8 @@ import { asyncMiddleware, executeIfActivityPub, localAccountValidator, - localVideoChannelValidator, + videoChannelsNameWithHostValidator, + ensureIsLocalChannel, videosCustomGetValidator, videosShareValidator } from '../../middlewares' @@ -123,24 +124,28 @@ activityPubClientRouter.get('/videos/watch/:videoId/comments/:commentId/activity ) activityPubClientRouter.get( - [ '/video-channels/:name', '/video-channels/:name/videos', '/c/:name', '/c/:name/videos' ], + [ '/video-channels/:nameWithHost', '/video-channels/:nameWithHost/videos', '/c/:nameWithHost', '/c/:nameWithHost/videos' ], executeIfActivityPub, - asyncMiddleware(localVideoChannelValidator), + asyncMiddleware(videoChannelsNameWithHostValidator), + ensureIsLocalChannel, videoChannelController ) -activityPubClientRouter.get('/video-channels/:name/followers', +activityPubClientRouter.get('/video-channels/:nameWithHost/followers', executeIfActivityPub, - asyncMiddleware(localVideoChannelValidator), + asyncMiddleware(videoChannelsNameWithHostValidator), + ensureIsLocalChannel, asyncMiddleware(videoChannelFollowersController) ) -activityPubClientRouter.get('/video-channels/:name/following', +activityPubClientRouter.get('/video-channels/:nameWithHost/following', executeIfActivityPub, - asyncMiddleware(localVideoChannelValidator), + asyncMiddleware(videoChannelsNameWithHostValidator), + ensureIsLocalChannel, asyncMiddleware(videoChannelFollowingController) ) -activityPubClientRouter.get('/video-channels/:name/playlists', +activityPubClientRouter.get('/video-channels/:nameWithHost/playlists', executeIfActivityPub, - asyncMiddleware(localVideoChannelValidator), + asyncMiddleware(videoChannelsNameWithHostValidator), + ensureIsLocalChannel, asyncMiddleware(videoChannelPlaylistsController) ) diff --git a/server/controllers/activitypub/inbox.ts b/server/controllers/activitypub/inbox.ts index ece4edff0..5995b8f3a 100644 --- a/server/controllers/activitypub/inbox.ts +++ b/server/controllers/activitypub/inbox.ts @@ -4,7 +4,14 @@ import { Activity, ActivityPubCollection, ActivityPubOrderedCollection, RootActi import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' import { isActivityValid } from '../../helpers/custom-validators/activitypub/activity' import { logger } from '../../helpers/logger' -import { asyncMiddleware, checkSignature, localAccountValidator, localVideoChannelValidator, signatureValidator } from '../../middlewares' +import { + asyncMiddleware, + checkSignature, + ensureIsLocalChannel, + localAccountValidator, + signatureValidator, + videoChannelsNameWithHostValidator +} from '../../middlewares' import { activityPubValidator } from '../../middlewares/validators/activitypub/activity' const inboxRouter = express.Router() @@ -23,10 +30,11 @@ inboxRouter.post('/accounts/:name/inbox', asyncMiddleware(activityPubValidator), inboxController ) -inboxRouter.post('/video-channels/:name/inbox', +inboxRouter.post('/video-channels/:nameWithHost/inbox', signatureValidator, asyncMiddleware(checkSignature), - asyncMiddleware(localVideoChannelValidator), + asyncMiddleware(videoChannelsNameWithHostValidator), + ensureIsLocalChannel, asyncMiddleware(activityPubValidator), inboxController ) diff --git a/server/controllers/activitypub/outbox.ts b/server/controllers/activitypub/outbox.ts index bdf9d138b..cdef8e969 100644 --- a/server/controllers/activitypub/outbox.ts +++ b/server/controllers/activitypub/outbox.ts @@ -1,15 +1,15 @@ import express from 'express' +import { MActorLight } from '@server/types/models' import { Activity } from '../../../shared/models/activitypub/activity' import { VideoPrivacy } from '../../../shared/models/videos' import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub' import { logger } from '../../helpers/logger' -import { buildAnnounceActivity, buildCreateActivity } from '../../lib/activitypub/send' import { buildAudience } from '../../lib/activitypub/audience' -import { asyncMiddleware, localAccountValidator, localVideoChannelValidator } from '../../middlewares' +import { buildAnnounceActivity, buildCreateActivity } from '../../lib/activitypub/send' +import { asyncMiddleware, ensureIsLocalChannel, localAccountValidator, videoChannelsNameWithHostValidator } from '../../middlewares' +import { apPaginationValidator } from '../../middlewares/validators/activitypub' import { VideoModel } from '../../models/video/video' import { activityPubResponse } from './utils' -import { MActorLight } from '@server/types/models' -import { apPaginationValidator } from '../../middlewares/validators/activitypub' const outboxRouter = express.Router() @@ -19,9 +19,10 @@ outboxRouter.get('/accounts/:name/outbox', asyncMiddleware(outboxController) ) -outboxRouter.get('/video-channels/:name/outbox', +outboxRouter.get('/video-channels/:nameWithHost/outbox', apPaginationValidator, - localVideoChannelValidator, + asyncMiddleware(videoChannelsNameWithHostValidator), + ensureIsLocalChannel, asyncMiddleware(outboxController) ) -- cgit v1.2.3