diff options
author | Chocobozzz <me@florianbigard.com> | 2019-04-15 10:49:46 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-04-15 14:39:52 +0200 |
commit | 1eddc9a74f9a80fa5d0cb25fceb3fc47a1a3c14a (patch) | |
tree | 91a10310cdf924779527525d39f8eb7e09e4ba49 /server/controllers/api/users | |
parent | 31b48aad478506d4214586f02792816efa968e4b (diff) | |
download | PeerTube-1eddc9a74f9a80fa5d0cb25fceb3fc47a1a3c14a.tar.gz PeerTube-1eddc9a74f9a80fa5d0cb25fceb3fc47a1a3c14a.tar.zst PeerTube-1eddc9a74f9a80fa5d0cb25fceb3fc47a1a3c14a.zip |
Add user adminFlags
Diffstat (limited to 'server/controllers/api/users')
-rw-r--r-- | server/controllers/api/users/index.ts | 9 | ||||
-rw-r--r-- | server/controllers/api/users/me.ts | 12 |
2 files changed, 12 insertions, 9 deletions
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' | |||
45 | import { mySubscriptionsRouter } from './my-subscriptions' | 45 | import { mySubscriptionsRouter } from './my-subscriptions' |
46 | import { CONFIG } from '../../../initializers/config' | 46 | import { CONFIG } from '../../../initializers/config' |
47 | import { sequelizeTypescript } from '../../../initializers/database' | 47 | import { sequelizeTypescript } from '../../../initializers/database' |
48 | import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' | ||
48 | 49 | ||
49 | const auditLogger = auditLoggerFactory('users') | 50 | const auditLogger = auditLoggerFactory('users') |
50 | 51 | ||
@@ -175,7 +176,8 @@ async function createUser (req: express.Request, res: express.Response) { | |||
175 | autoPlayVideo: true, | 176 | autoPlayVideo: true, |
176 | role: body.role, | 177 | role: body.role, |
177 | videoQuota: body.videoQuota, | 178 | videoQuota: body.videoQuota, |
178 | videoQuotaDaily: body.videoQuotaDaily | 179 | videoQuotaDaily: body.videoQuotaDaily, |
180 | adminFlags: body.adminFlags || UserAdminFlag.NONE | ||
179 | }) | 181 | }) |
180 | 182 | ||
181 | const { user, account } = await createUserAccountAndChannelAndPlaylist(userToCreate) | 183 | const { user, account } = await createUserAccountAndChannelAndPlaylist(userToCreate) |
@@ -241,7 +243,7 @@ async function blockUser (req: express.Request, res: express.Response) { | |||
241 | } | 243 | } |
242 | 244 | ||
243 | function getUser (req: express.Request, res: express.Response) { | 245 | function getUser (req: express.Request, res: express.Response) { |
244 | return res.json(res.locals.user.toFormattedJSON()) | 246 | return res.json(res.locals.user.toFormattedJSON({ withAdminFlags: true })) |
245 | } | 247 | } |
246 | 248 | ||
247 | async function autocompleteUsers (req: express.Request, res: express.Response) { | 249 | async function autocompleteUsers (req: express.Request, res: express.Response) { |
@@ -253,7 +255,7 @@ async function autocompleteUsers (req: express.Request, res: express.Response) { | |||
253 | async function listUsers (req: express.Request, res: express.Response) { | 255 | async function listUsers (req: express.Request, res: express.Response) { |
254 | const resultList = await UserModel.listForApi(req.query.start, req.query.count, req.query.sort, req.query.search) | 256 | const resultList = await UserModel.listForApi(req.query.start, req.query.count, req.query.sort, req.query.search) |
255 | 257 | ||
256 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 258 | return res.json(getFormattedObjects(resultList.data, resultList.total, { withAdminFlags: true })) |
257 | } | 259 | } |
258 | 260 | ||
259 | async function removeUser (req: express.Request, res: express.Response) { | 261 | async function removeUser (req: express.Request, res: express.Response) { |
@@ -278,6 +280,7 @@ async function updateUser (req: express.Request, res: express.Response) { | |||
278 | if (body.videoQuota !== undefined) userToUpdate.videoQuota = body.videoQuota | 280 | if (body.videoQuota !== undefined) userToUpdate.videoQuota = body.videoQuota |
279 | if (body.videoQuotaDaily !== undefined) userToUpdate.videoQuotaDaily = body.videoQuotaDaily | 281 | if (body.videoQuotaDaily !== undefined) userToUpdate.videoQuotaDaily = body.videoQuotaDaily |
280 | if (body.role !== undefined) userToUpdate.role = body.role | 282 | if (body.role !== undefined) userToUpdate.role = body.role |
283 | if (body.adminFlags !== undefined) userToUpdate.adminFlags = body.adminFlags | ||
281 | 284 | ||
282 | const user = await userToUpdate.save() | 285 | const user = await userToUpdate.save() |
283 | 286 | ||
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) | |||
129 | // We did not load channels in res.locals.user | 129 | // We did not load channels in res.locals.user |
130 | const user = await UserModel.loadByUsernameAndPopulateChannels(res.locals.oauth.token.user.username) | 130 | const user = await UserModel.loadByUsernameAndPopulateChannels(res.locals.oauth.token.user.username) |
131 | 131 | ||
132 | return res.json(user.toFormattedJSON()) | 132 | return res.json(user.toFormattedJSON({})) |
133 | } | 133 | } |
134 | 134 | ||
135 | async function getUserVideoQuotaUsed (req: express.Request, res: express.Response) { | 135 | async function getUserVideoQuotaUsed (req: express.Request, res: express.Response) { |
@@ -164,7 +164,7 @@ async function deleteMe (req: express.Request, res: express.Response) { | |||
164 | 164 | ||
165 | await user.destroy() | 165 | await user.destroy() |
166 | 166 | ||
167 | auditLogger.delete(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON())) | 167 | auditLogger.delete(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON({}))) |
168 | 168 | ||
169 | return res.sendStatus(204) | 169 | return res.sendStatus(204) |
170 | } | 170 | } |
@@ -173,7 +173,7 @@ async function updateMe (req: express.Request, res: express.Response) { | |||
173 | const body: UserUpdateMe = req.body | 173 | const body: UserUpdateMe = req.body |
174 | 174 | ||
175 | const user = res.locals.oauth.token.user | 175 | const user = res.locals.oauth.token.user |
176 | const oldUserAuditView = new UserAuditView(user.toFormattedJSON()) | 176 | const oldUserAuditView = new UserAuditView(user.toFormattedJSON({})) |
177 | 177 | ||
178 | if (body.password !== undefined) user.password = body.password | 178 | if (body.password !== undefined) user.password = body.password |
179 | if (body.email !== undefined) user.email = body.email | 179 | if (body.email !== undefined) user.email = body.email |
@@ -193,7 +193,7 @@ async function updateMe (req: express.Request, res: express.Response) { | |||
193 | 193 | ||
194 | await sendUpdateActor(userAccount, t) | 194 | await sendUpdateActor(userAccount, t) |
195 | 195 | ||
196 | auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()), oldUserAuditView) | 196 | auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON({})), oldUserAuditView) |
197 | }) | 197 | }) |
198 | 198 | ||
199 | return res.sendStatus(204) | 199 | return res.sendStatus(204) |
@@ -202,13 +202,13 @@ async function updateMe (req: express.Request, res: express.Response) { | |||
202 | async function updateMyAvatar (req: express.Request, res: express.Response) { | 202 | async function updateMyAvatar (req: express.Request, res: express.Response) { |
203 | const avatarPhysicalFile = req.files[ 'avatarfile' ][ 0 ] | 203 | const avatarPhysicalFile = req.files[ 'avatarfile' ][ 0 ] |
204 | const user = res.locals.oauth.token.user | 204 | const user = res.locals.oauth.token.user |
205 | const oldUserAuditView = new UserAuditView(user.toFormattedJSON()) | 205 | const oldUserAuditView = new UserAuditView(user.toFormattedJSON({})) |
206 | 206 | ||
207 | const userAccount = await AccountModel.load(user.Account.id) | 207 | const userAccount = await AccountModel.load(user.Account.id) |
208 | 208 | ||
209 | const avatar = await updateActorAvatarFile(avatarPhysicalFile, userAccount) | 209 | const avatar = await updateActorAvatarFile(avatarPhysicalFile, userAccount) |
210 | 210 | ||
211 | auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()), oldUserAuditView) | 211 | auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON({})), oldUserAuditView) |
212 | 212 | ||
213 | return res.json({ avatar: avatar.toFormattedJSON() }) | 213 | return res.json({ avatar: avatar.toFormattedJSON() }) |
214 | } | 214 | } |