1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-04 02:09:37 +02:00

Implement user blocking on server side

This commit is contained in:
Chocobozzz 2018-08-08 14:58:21 +02:00
parent 6b09aba90d
commit e69219184b
No known key found for this signature in database
GPG key ID: 583A612D890159BE
15 changed files with 287 additions and 59 deletions

View file

@ -32,6 +32,7 @@ import {
import {
deleteMeValidator,
usersAskResetPasswordValidator,
usersBlockingValidator,
usersResetPasswordValidator,
videoImportsSortValidator,
videosSortValidator
@ -108,6 +109,19 @@ usersRouter.get('/',
asyncMiddleware(listUsers)
)
usersRouter.post('/:id/block',
authenticate,
ensureUserHasRight(UserRight.MANAGE_USERS),
asyncMiddleware(usersBlockingValidator),
asyncMiddleware(blockUser)
)
usersRouter.post('/:id/unblock',
authenticate,
ensureUserHasRight(UserRight.MANAGE_USERS),
asyncMiddleware(usersBlockingValidator),
asyncMiddleware(unblockUser)
)
usersRouter.get('/:id',
authenticate,
ensureUserHasRight(UserRight.MANAGE_USERS),
@ -278,6 +292,22 @@ async function getUserVideoQuotaUsed (req: express.Request, res: express.Respons
return res.json(data)
}
async function unblockUser (req: express.Request, res: express.Response, next: express.NextFunction) {
const user: UserModel = res.locals.user
await changeUserBlock(res, user, false)
return res.status(204).end()
}
async function blockUser (req: express.Request, res: express.Response, next: express.NextFunction) {
const user: UserModel = res.locals.user
await changeUserBlock(res, user, true)
return res.status(204).end()
}
function getUser (req: express.Request, res: express.Response, next: express.NextFunction) {
return res.json((res.locals.user as UserModel).toFormattedJSON())
}
@ -423,3 +453,21 @@ async function resetUserPassword (req: express.Request, res: express.Response, n
function success (req: express.Request, res: express.Response, next: express.NextFunction) {
res.end()
}
async function changeUserBlock (res: express.Response, user: UserModel, block: boolean) {
const oldUserAuditView = new UserAuditView(user.toFormattedJSON())
user.blocked = block
await sequelizeTypescript.transaction(async t => {
await OAuthTokenModel.deleteUserToken(user.id, t)
await user.save({ transaction: t })
})
auditLogger.update(
res.locals.oauth.token.User.Account.Actor.getIdentifier(),
new UserAuditView(user.toFormattedJSON()),
oldUserAuditView
)
}