From 1eddc9a74f9a80fa5d0cb25fceb3fc47a1a3c14a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 15 Apr 2019 10:49:46 +0200 Subject: Add user adminFlags --- server/controllers/api/users/index.ts | 9 ++++++--- server/controllers/api/users/me.ts | 12 ++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) (limited to 'server/controllers/api/users') diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts index 28c8de303..0aafba66e 100644 --- a/server/controllers/api/users/index.ts +++ b/server/controllers/api/users/index.ts @@ -45,6 +45,7 @@ import { Notifier } from '../../../lib/notifier' import { mySubscriptionsRouter } from './my-subscriptions' import { CONFIG } from '../../../initializers/config' import { sequelizeTypescript } from '../../../initializers/database' +import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' const auditLogger = auditLoggerFactory('users') @@ -175,7 +176,8 @@ async function createUser (req: express.Request, res: express.Response) { autoPlayVideo: true, role: body.role, videoQuota: body.videoQuota, - videoQuotaDaily: body.videoQuotaDaily + videoQuotaDaily: body.videoQuotaDaily, + adminFlags: body.adminFlags || UserAdminFlag.NONE }) const { user, account } = await createUserAccountAndChannelAndPlaylist(userToCreate) @@ -241,7 +243,7 @@ async function blockUser (req: express.Request, res: express.Response) { } function getUser (req: express.Request, res: express.Response) { - return res.json(res.locals.user.toFormattedJSON()) + return res.json(res.locals.user.toFormattedJSON({ withAdminFlags: true })) } async function autocompleteUsers (req: express.Request, res: express.Response) { @@ -253,7 +255,7 @@ async function autocompleteUsers (req: express.Request, res: express.Response) { async function listUsers (req: express.Request, res: express.Response) { const resultList = await UserModel.listForApi(req.query.start, req.query.count, req.query.sort, req.query.search) - return res.json(getFormattedObjects(resultList.data, resultList.total)) + return res.json(getFormattedObjects(resultList.data, resultList.total, { withAdminFlags: true })) } async function removeUser (req: express.Request, res: express.Response) { @@ -278,6 +280,7 @@ async function updateUser (req: express.Request, res: express.Response) { if (body.videoQuota !== undefined) userToUpdate.videoQuota = body.videoQuota if (body.videoQuotaDaily !== undefined) userToUpdate.videoQuotaDaily = body.videoQuotaDaily if (body.role !== undefined) userToUpdate.role = body.role + if (body.adminFlags !== undefined) userToUpdate.adminFlags = body.adminFlags const user = await userToUpdate.save() diff --git a/server/controllers/api/users/me.ts b/server/controllers/api/users/me.ts index ce9e78463..ddb239e7b 100644 --- a/server/controllers/api/users/me.ts +++ b/server/controllers/api/users/me.ts @@ -129,7 +129,7 @@ async function getUserInformation (req: express.Request, res: express.Response) // We did not load channels in res.locals.user const user = await UserModel.loadByUsernameAndPopulateChannels(res.locals.oauth.token.user.username) - return res.json(user.toFormattedJSON()) + return res.json(user.toFormattedJSON({})) } async function getUserVideoQuotaUsed (req: express.Request, res: express.Response) { @@ -164,7 +164,7 @@ async function deleteMe (req: express.Request, res: express.Response) { await user.destroy() - auditLogger.delete(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON())) + auditLogger.delete(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON({}))) return res.sendStatus(204) } @@ -173,7 +173,7 @@ async function updateMe (req: express.Request, res: express.Response) { const body: UserUpdateMe = req.body const user = res.locals.oauth.token.user - const oldUserAuditView = new UserAuditView(user.toFormattedJSON()) + const oldUserAuditView = new UserAuditView(user.toFormattedJSON({})) if (body.password !== undefined) user.password = body.password if (body.email !== undefined) user.email = body.email @@ -193,7 +193,7 @@ async function updateMe (req: express.Request, res: express.Response) { await sendUpdateActor(userAccount, t) - auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()), oldUserAuditView) + auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON({})), oldUserAuditView) }) return res.sendStatus(204) @@ -202,13 +202,13 @@ async function updateMe (req: express.Request, res: express.Response) { async function updateMyAvatar (req: express.Request, res: express.Response) { const avatarPhysicalFile = req.files[ 'avatarfile' ][ 0 ] const user = res.locals.oauth.token.user - const oldUserAuditView = new UserAuditView(user.toFormattedJSON()) + const oldUserAuditView = new UserAuditView(user.toFormattedJSON({})) const userAccount = await AccountModel.load(user.Account.id) const avatar = await updateActorAvatarFile(avatarPhysicalFile, userAccount) - auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()), oldUserAuditView) + auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON({})), oldUserAuditView) return res.json({ avatar: avatar.toFormattedJSON() }) } -- cgit v1.2.3