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:
parent
6b09aba90d
commit
e69219184b
15 changed files with 287 additions and 59 deletions
|
@ -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
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue