@@ -233,6 +233,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
233
233
234
234
const updates = { } as Partial < MiUser > ;
235
235
const profileUpdates = { } as Partial < MiUserProfile > ;
236
+ const policy = await this . roleService . getUserPolicies ( user . id ) ;
236
237
237
238
const profile = await this . userProfilesRepository . findOneByOrFail ( { userId : user . id } ) ;
238
239
@@ -245,7 +246,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
245
246
if ( ps . followersVisibility !== undefined ) profileUpdates . followersVisibility = ps . followersVisibility ;
246
247
if ( ps . mutedWords !== undefined ) {
247
248
const length = ps . mutedWords . length ;
248
- if ( length > ( await this . roleService . getUserPolicies ( user . id ) ) . wordMuteLimit ) {
249
+ if ( length > policy . wordMuteLimit ) {
249
250
throw new ApiError ( meta . errors . tooManyMutedWords ) ;
250
251
}
251
252
@@ -279,13 +280,14 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
279
280
if ( typeof ps . injectFeaturedNote === 'boolean' ) profileUpdates . injectFeaturedNote = ps . injectFeaturedNote ;
280
281
if ( typeof ps . receiveAnnouncementEmail === 'boolean' ) profileUpdates . receiveAnnouncementEmail = ps . receiveAnnouncementEmail ;
281
282
if ( typeof ps . alwaysMarkNsfw === 'boolean' ) {
282
- if ( ( await roleService . getUserPolicies ( user . id ) ) . alwaysMarkNsfw ) throw new ApiError ( meta . errors . restrictedByRole ) ;
283
+ if ( policy . alwaysMarkNsfw ) throw new ApiError ( meta . errors . restrictedByRole ) ;
283
284
profileUpdates . alwaysMarkNsfw = ps . alwaysMarkNsfw ;
284
285
}
285
286
if ( typeof ps . autoSensitive === 'boolean' ) profileUpdates . autoSensitive = ps . autoSensitive ;
286
287
if ( ps . emailNotificationTypes !== undefined ) profileUpdates . emailNotificationTypes = ps . emailNotificationTypes ;
287
288
288
289
if ( ps . avatarId ) {
290
+ if ( ! policy . canUpdateAvatar ) throw new ApiError ( meta . errors . restrictedByRole ) ;
289
291
const avatar = await this . driveFilesRepository . findOneBy ( { id : ps . avatarId } ) ;
290
292
291
293
if ( avatar == null || avatar . userId !== user . id ) throw new ApiError ( meta . errors . noSuchAvatar ) ;
@@ -301,6 +303,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
301
303
}
302
304
303
305
if ( ps . bannerId ) {
306
+ if ( ! policy . canUpdateBanner ) throw new ApiError ( meta . errors . restrictedByRole ) ;
304
307
const banner = await this . driveFilesRepository . findOneBy ( { id : ps . bannerId } ) ;
305
308
306
309
if ( banner == null || banner . userId !== user . id ) throw new ApiError ( meta . errors . noSuchBanner ) ;
@@ -317,13 +320,13 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
317
320
318
321
if ( ps . avatarDecorations ) {
319
322
const decorations = await this . avatarDecorationService . getAll ( true ) ;
320
- const [ myRoles , myPolicies ] = await Promise . all ( [ this . roleService . getUserRoles ( user . id ) , this . roleService . getUserPolicies ( user . id ) ] ) ;
323
+ const myRoles = await this . roleService . getUserRoles ( user . id ) ;
321
324
const allRoles = await this . roleService . getRoles ( ) ;
322
325
const decorationIds = decorations
323
326
. filter ( d => d . roleIdsThatCanBeUsedThisDecoration . filter ( roleId => allRoles . some ( r => r . id === roleId ) ) . length === 0 || myRoles . some ( r => d . roleIdsThatCanBeUsedThisDecoration . includes ( r . id ) ) )
324
327
. map ( d => d . id ) ;
325
328
326
- if ( ps . avatarDecorations . length > myPolicies . avatarDecorationLimit ) throw new ApiError ( meta . errors . restrictedByRole ) ;
329
+ if ( ps . avatarDecorations . length > policy . avatarDecorationLimit ) throw new ApiError ( meta . errors . restrictedByRole ) ;
327
330
328
331
updates . avatarDecorations = ps . avatarDecorations . filter ( d => decorationIds . includes ( d . id ) ) . map ( d => ( {
329
332
id : d . id ,
0 commit comments