diff options
Diffstat (limited to 'server/controllers/api/users')
-rw-r--r-- | server/controllers/api/users/index.ts | 5 | ||||
-rw-r--r-- | server/controllers/api/users/me.ts | 13 | ||||
-rw-r--r-- | server/controllers/api/users/my-history.ts | 1 |
3 files changed, 4 insertions, 15 deletions
diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts index ae40e86f8..27351c1a9 100644 --- a/server/controllers/api/users/index.ts +++ b/server/controllers/api/users/index.ts | |||
@@ -48,6 +48,7 @@ import { CONFIG } from '../../../initializers/config' | |||
48 | import { sequelizeTypescript } from '../../../initializers/database' | 48 | import { sequelizeTypescript } from '../../../initializers/database' |
49 | import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' | 49 | import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' |
50 | import { UserRegister } from '../../../../shared/models/users/user-register.model' | 50 | import { UserRegister } from '../../../../shared/models/users/user-register.model' |
51 | import { MUser, MUserAccountDefault } from '@server/typings/models' | ||
51 | 52 | ||
52 | const auditLogger = auditLoggerFactory('users') | 53 | const auditLogger = auditLoggerFactory('users') |
53 | 54 | ||
@@ -195,7 +196,7 @@ async function createUser (req: express.Request, res: express.Response) { | |||
195 | videoQuota: body.videoQuota, | 196 | videoQuota: body.videoQuota, |
196 | videoQuotaDaily: body.videoQuotaDaily, | 197 | videoQuotaDaily: body.videoQuotaDaily, |
197 | adminFlags: body.adminFlags || UserAdminFlag.NONE | 198 | adminFlags: body.adminFlags || UserAdminFlag.NONE |
198 | }) | 199 | }) as MUser |
199 | 200 | ||
200 | const { user, account } = await createUserAccountAndChannelAndPlaylist({ userToCreate: userToCreate }) | 201 | const { user, account } = await createUserAccountAndChannelAndPlaylist({ userToCreate: userToCreate }) |
201 | 202 | ||
@@ -359,7 +360,7 @@ function success (req: express.Request, res: express.Response) { | |||
359 | res.end() | 360 | res.end() |
360 | } | 361 | } |
361 | 362 | ||
362 | async function changeUserBlock (res: express.Response, user: UserModel, block: boolean, reason?: string) { | 363 | async function changeUserBlock (res: express.Response, user: MUserAccountDefault, block: boolean, reason?: string) { |
363 | const oldUserAuditView = new UserAuditView(user.toFormattedJSON()) | 364 | const oldUserAuditView = new UserAuditView(user.toFormattedJSON()) |
364 | 365 | ||
365 | user.blocked = block | 366 | user.blocked = block |
diff --git a/server/controllers/api/users/me.ts b/server/controllers/api/users/me.ts index e7ed3de64..78e1e7fa3 100644 --- a/server/controllers/api/users/me.ts +++ b/server/controllers/api/users/me.ts | |||
@@ -23,15 +23,12 @@ import { createReqFiles } from '../../../helpers/express-utils' | |||
23 | import { UserVideoQuota } from '../../../../shared/models/users/user-video-quota.model' | 23 | import { UserVideoQuota } from '../../../../shared/models/users/user-video-quota.model' |
24 | import { updateAvatarValidator } from '../../../middlewares/validators/avatar' | 24 | import { updateAvatarValidator } from '../../../middlewares/validators/avatar' |
25 | import { updateActorAvatarFile } from '../../../lib/avatar' | 25 | import { updateActorAvatarFile } from '../../../lib/avatar' |
26 | import { auditLoggerFactory, getAuditIdFromRes, UserAuditView } from '../../../helpers/audit-logger' | ||
27 | import { VideoImportModel } from '../../../models/video/video-import' | 26 | import { VideoImportModel } from '../../../models/video/video-import' |
28 | import { AccountModel } from '../../../models/account/account' | 27 | import { AccountModel } from '../../../models/account/account' |
29 | import { CONFIG } from '../../../initializers/config' | 28 | import { CONFIG } from '../../../initializers/config' |
30 | import { sequelizeTypescript } from '../../../initializers/database' | 29 | import { sequelizeTypescript } from '../../../initializers/database' |
31 | import { sendVerifyUserEmail } from '../../../lib/user' | 30 | import { sendVerifyUserEmail } from '../../../lib/user' |
32 | 31 | ||
33 | const auditLogger = auditLoggerFactory('users-me') | ||
34 | |||
35 | const reqAvatarFile = createReqFiles([ 'avatarfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.TMP_DIR }) | 32 | const reqAvatarFile = createReqFiles([ 'avatarfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.TMP_DIR }) |
36 | 33 | ||
37 | const meRouter = express.Router() | 34 | const meRouter = express.Router() |
@@ -147,7 +144,7 @@ async function getUserVideoQuotaUsed (req: express.Request, res: express.Respons | |||
147 | } | 144 | } |
148 | 145 | ||
149 | async function getUserVideoRating (req: express.Request, res: express.Response) { | 146 | async function getUserVideoRating (req: express.Request, res: express.Response) { |
150 | const videoId = res.locals.video.id | 147 | const videoId = res.locals.videoId.id |
151 | const accountId = +res.locals.oauth.token.User.Account.id | 148 | const accountId = +res.locals.oauth.token.User.Account.id |
152 | 149 | ||
153 | const ratingObj = await AccountVideoRateModel.load(accountId, videoId, null) | 150 | const ratingObj = await AccountVideoRateModel.load(accountId, videoId, null) |
@@ -165,8 +162,6 @@ async function deleteMe (req: express.Request, res: express.Response) { | |||
165 | 162 | ||
166 | await user.destroy() | 163 | await user.destroy() |
167 | 164 | ||
168 | auditLogger.delete(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON({}))) | ||
169 | |||
170 | return res.sendStatus(204) | 165 | return res.sendStatus(204) |
171 | } | 166 | } |
172 | 167 | ||
@@ -175,7 +170,6 @@ async function updateMe (req: express.Request, res: express.Response) { | |||
175 | let sendVerificationEmail = false | 170 | let sendVerificationEmail = false |
176 | 171 | ||
177 | const user = res.locals.oauth.token.user | 172 | const user = res.locals.oauth.token.user |
178 | const oldUserAuditView = new UserAuditView(user.toFormattedJSON({})) | ||
179 | 173 | ||
180 | if (body.password !== undefined) user.password = body.password | 174 | if (body.password !== undefined) user.password = body.password |
181 | if (body.nsfwPolicy !== undefined) user.nsfwPolicy = body.nsfwPolicy | 175 | if (body.nsfwPolicy !== undefined) user.nsfwPolicy = body.nsfwPolicy |
@@ -204,8 +198,6 @@ async function updateMe (req: express.Request, res: express.Response) { | |||
204 | await userAccount.save({ transaction: t }) | 198 | await userAccount.save({ transaction: t }) |
205 | 199 | ||
206 | await sendUpdateActor(userAccount, t) | 200 | await sendUpdateActor(userAccount, t) |
207 | |||
208 | auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON({})), oldUserAuditView) | ||
209 | }) | 201 | }) |
210 | 202 | ||
211 | if (sendVerificationEmail === true) { | 203 | if (sendVerificationEmail === true) { |
@@ -218,13 +210,10 @@ async function updateMe (req: express.Request, res: express.Response) { | |||
218 | async function updateMyAvatar (req: express.Request, res: express.Response) { | 210 | async function updateMyAvatar (req: express.Request, res: express.Response) { |
219 | const avatarPhysicalFile = req.files[ 'avatarfile' ][ 0 ] | 211 | const avatarPhysicalFile = req.files[ 'avatarfile' ][ 0 ] |
220 | const user = res.locals.oauth.token.user | 212 | const user = res.locals.oauth.token.user |
221 | const oldUserAuditView = new UserAuditView(user.toFormattedJSON({})) | ||
222 | 213 | ||
223 | const userAccount = await AccountModel.load(user.Account.id) | 214 | const userAccount = await AccountModel.load(user.Account.id) |
224 | 215 | ||
225 | const avatar = await updateActorAvatarFile(avatarPhysicalFile, userAccount) | 216 | const avatar = await updateActorAvatarFile(avatarPhysicalFile, userAccount) |
226 | 217 | ||
227 | auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON({})), oldUserAuditView) | ||
228 | |||
229 | return res.json({ avatar: avatar.toFormattedJSON() }) | 218 | return res.json({ avatar: avatar.toFormattedJSON() }) |
230 | } | 219 | } |
diff --git a/server/controllers/api/users/my-history.ts b/server/controllers/api/users/my-history.ts index 7025c0ff1..4da1f3496 100644 --- a/server/controllers/api/users/my-history.ts +++ b/server/controllers/api/users/my-history.ts | |||
@@ -7,7 +7,6 @@ import { | |||
7 | setDefaultPagination, | 7 | setDefaultPagination, |
8 | userHistoryRemoveValidator | 8 | userHistoryRemoveValidator |
9 | } from '../../../middlewares' | 9 | } from '../../../middlewares' |
10 | import { UserModel } from '../../../models/account/user' | ||
11 | import { getFormattedObjects } from '../../../helpers/utils' | 10 | import { getFormattedObjects } from '../../../helpers/utils' |
12 | import { UserVideoHistoryModel } from '../../../models/account/user-video-history' | 11 | import { UserVideoHistoryModel } from '../../../models/account/user-video-history' |
13 | import { sequelizeTypescript } from '../../../initializers' | 12 | import { sequelizeTypescript } from '../../../initializers' |