a37e9e74ff
* 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 2c627c154e
.
* 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 <me@florianbigard.com>
76 lines
2.9 KiB
TypeScript
76 lines
2.9 KiB
TypeScript
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 { buildAudience } from '../../lib/activitypub/audience'
|
|
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'
|
|
|
|
const outboxRouter = express.Router()
|
|
|
|
outboxRouter.get('/accounts/:name/outbox',
|
|
apPaginationValidator,
|
|
localAccountValidator,
|
|
asyncMiddleware(outboxController)
|
|
)
|
|
|
|
outboxRouter.get('/video-channels/:nameWithHost/outbox',
|
|
apPaginationValidator,
|
|
asyncMiddleware(videoChannelsNameWithHostValidator),
|
|
ensureIsLocalChannel,
|
|
asyncMiddleware(outboxController)
|
|
)
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export {
|
|
outboxRouter
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
async function outboxController (req: express.Request, res: express.Response) {
|
|
const accountOrVideoChannel = res.locals.account || res.locals.videoChannel
|
|
const actor = accountOrVideoChannel.Actor
|
|
const actorOutboxUrl = actor.url + '/outbox'
|
|
|
|
logger.info('Receiving outbox request for %s.', actorOutboxUrl)
|
|
|
|
const handler = (start: number, count: number) => buildActivities(actor, start, count)
|
|
const json = await activityPubCollectionPagination(actorOutboxUrl, handler, req.query.page, req.query.size)
|
|
|
|
return activityPubResponse(activityPubContextify(json), res)
|
|
}
|
|
|
|
async function buildActivities (actor: MActorLight, start: number, count: number) {
|
|
const data = await VideoModel.listAllAndSharedByActorForOutbox(actor.id, start, count)
|
|
const activities: Activity[] = []
|
|
|
|
for (const video of data.data) {
|
|
const byActor = video.VideoChannel.Account.Actor
|
|
const createActivityAudience = buildAudience([ byActor.followersUrl ], video.privacy === VideoPrivacy.PUBLIC)
|
|
|
|
// This is a shared video
|
|
if (video.VideoShares !== undefined && video.VideoShares.length !== 0) {
|
|
const videoShare = video.VideoShares[0]
|
|
const announceActivity = buildAnnounceActivity(videoShare.url, actor, video.url, createActivityAudience)
|
|
|
|
activities.push(announceActivity)
|
|
} else {
|
|
const videoObject = video.toActivityPubObject()
|
|
const createActivity = buildCreateActivity(video.url, byActor, videoObject, createActivityAudience)
|
|
|
|
activities.push(createActivity)
|
|
}
|
|
}
|
|
|
|
return {
|
|
data: activities,
|
|
total: data.total
|
|
}
|
|
}
|