mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2026-09-03 20:53:09 -05:00
Only owner can display stats
This commit is contained in:
@@ -93,6 +93,40 @@ describe('Test video channels API validator', function () {
|
|||||||
expectedStatus: HttpStatusCode.OK_200
|
expectedStatus: HttpStatusCode.OK_200
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('Should fail to list withStats without being authenticated', async function () {
|
||||||
|
await server.channels.listByAccount({
|
||||||
|
accountName: 'fake',
|
||||||
|
withStats: true,
|
||||||
|
token: null,
|
||||||
|
expectedStatus: HttpStatusCode.UNAUTHORIZED_401
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Should fail to list withStats of another account', async function () {
|
||||||
|
await server.channels.listByAccount({
|
||||||
|
accountName: 'fake',
|
||||||
|
withStats: true,
|
||||||
|
token: server.accessToken,
|
||||||
|
expectedStatus: HttpStatusCode.OK_200
|
||||||
|
})
|
||||||
|
|
||||||
|
await server.channels.listByAccount({
|
||||||
|
accountName: 'root',
|
||||||
|
withStats: true,
|
||||||
|
token: userInfo.accessToken,
|
||||||
|
expectedStatus: HttpStatusCode.FORBIDDEN_403
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Should succeed to list withStats of its own account', async function () {
|
||||||
|
await server.channels.listByAccount({
|
||||||
|
accountName: 'fake',
|
||||||
|
withStats: true,
|
||||||
|
token: userInfo.accessToken,
|
||||||
|
expectedStatus: HttpStatusCode.OK_200
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('When adding a video channel', function () {
|
describe('When adding a video channel', function () {
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ accountsRouter.get(
|
|||||||
|
|
||||||
accountsRouter.get(
|
accountsRouter.get(
|
||||||
'/:handle/video-channels',
|
'/:handle/video-channels',
|
||||||
|
optionalAuthenticate,
|
||||||
asyncMiddleware(accountHandleGetValidatorFactory({ checkIsLocal: false, checkCanManage: false })),
|
asyncMiddleware(accountHandleGetValidatorFactory({ checkIsLocal: false, checkCanManage: false })),
|
||||||
listAccountChannelsValidator,
|
listAccountChannelsValidator,
|
||||||
paginationValidator,
|
paginationValidator,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { HttpStatusCode, VideosImportInChannelCreate } from '@peertube/peertube-models'
|
import { HttpStatusCode, UserRight, VideosImportInChannelCreate } from '@peertube/peertube-models'
|
||||||
import { isUrlValid } from '@server/helpers/custom-validators/activitypub/misc.js'
|
import { isUrlValid } from '@server/helpers/custom-validators/activitypub/misc.js'
|
||||||
import { CONFIG } from '@server/initializers/config.js'
|
import { CONFIG } from '@server/initializers/config.js'
|
||||||
import { loadReservedActorName } from '@server/lib/local-actor.js'
|
import { loadReservedActorName } from '@server/lib/local-actor.js'
|
||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
isVideoChannelUsernameValid
|
isVideoChannelUsernameValid
|
||||||
} from '../../../helpers/custom-validators/video-channels.js'
|
} from '../../../helpers/custom-validators/video-channels.js'
|
||||||
import { VideoChannelModel } from '../../../models/video/video-channel.js'
|
import { VideoChannelModel } from '../../../models/video/video-channel.js'
|
||||||
import { areValidationErrors, checkUserQuota, doesChannelHandleExist } from '../shared/index.js'
|
import { areValidationErrors, checkCanManageAccount, checkUserQuota, doesChannelHandleExist } from '../shared/index.js'
|
||||||
import { doesVideoChannelSyncIdExist } from '../shared/video-channel-syncs.js'
|
import { doesVideoChannelSyncIdExist } from '../shared/video-channel-syncs.js'
|
||||||
|
|
||||||
export const videoChannelsAddValidator = [
|
export const videoChannelsAddValidator = [
|
||||||
@@ -115,6 +115,12 @@ export const listAccountChannelsValidator = [
|
|||||||
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||||
if (areValidationErrors(req, res)) return
|
if (areValidationErrors(req, res)) return
|
||||||
|
|
||||||
|
if (req.query.withStats === true) {
|
||||||
|
const user = res.locals.oauth?.token.User
|
||||||
|
|
||||||
|
if (!checkCanManageAccount({ account: res.locals.account, user, specialRight: UserRight.MANAGE_USERS, req, res })) return
|
||||||
|
}
|
||||||
|
|
||||||
return next()
|
return next()
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user