refactor: rename role.options -> role.policies

This commit is contained in:
syuilo
2023-01-15 20:52:53 +09:00
parent 518b3e2f73
commit 81f11d8f86
53 changed files with 254 additions and 232 deletions

View File

@@ -8,7 +8,7 @@ export const meta = {
tags: ['admin'],
requireCredential: true,
requireRoleOption: 'canManageCustomEmojis',
requireRolePolicy: 'canManageCustomEmojis',
} as const;
export const paramDef = {

View File

@@ -14,7 +14,7 @@ export const meta = {
tags: ['admin'],
requireCredential: true,
requireRoleOption: 'canManageCustomEmojis',
requireRolePolicy: 'canManageCustomEmojis',
errors: {
noSuchFile: {

View File

@@ -14,7 +14,7 @@ export const meta = {
tags: ['admin'],
requireCredential: true,
requireRoleOption: 'canManageCustomEmojis',
requireRolePolicy: 'canManageCustomEmojis',
errors: {
noSuchEmoji: {

View File

@@ -9,7 +9,7 @@ export const meta = {
tags: ['admin'],
requireCredential: true,
requireRoleOption: 'canManageCustomEmojis',
requireRolePolicy: 'canManageCustomEmojis',
} as const;
export const paramDef = {

View File

@@ -10,7 +10,7 @@ export const meta = {
tags: ['admin'],
requireCredential: true,
requireRoleOption: 'canManageCustomEmojis',
requireRolePolicy: 'canManageCustomEmojis',
errors: {
noSuchEmoji: {

View File

@@ -5,7 +5,7 @@ import { QueueService } from '@/core/QueueService.js';
export const meta = {
secure: true,
requireCredential: true,
requireRoleOption: 'canManageCustomEmojis',
requireRolePolicy: 'canManageCustomEmojis',
} as const;
export const paramDef = {

View File

@@ -11,7 +11,7 @@ export const meta = {
tags: ['admin'],
requireCredential: true,
requireRoleOption: 'canManageCustomEmojis',
requireRolePolicy: 'canManageCustomEmojis',
res: {
type: 'array',

View File

@@ -11,7 +11,7 @@ export const meta = {
tags: ['admin'],
requireCredential: true,
requireRoleOption: 'canManageCustomEmojis',
requireRolePolicy: 'canManageCustomEmojis',
res: {
type: 'array',

View File

@@ -8,7 +8,7 @@ export const meta = {
tags: ['admin'],
requireCredential: true,
requireRoleOption: 'canManageCustomEmojis',
requireRolePolicy: 'canManageCustomEmojis',
} as const;
export const paramDef = {

View File

@@ -8,7 +8,7 @@ export const meta = {
tags: ['admin'],
requireCredential: true,
requireRoleOption: 'canManageCustomEmojis',
requireRolePolicy: 'canManageCustomEmojis',
} as const;
export const paramDef = {

View File

@@ -8,7 +8,7 @@ export const meta = {
tags: ['admin'],
requireCredential: true,
requireRoleOption: 'canManageCustomEmojis',
requireRolePolicy: 'canManageCustomEmojis',
} as const;
export const paramDef = {

View File

@@ -9,7 +9,7 @@ export const meta = {
tags: ['admin'],
requireCredential: true,
requireRoleOption: 'canManageCustomEmojis',
requireRolePolicy: 'canManageCustomEmojis',
errors: {
noSuchEmoji: {

View File

@@ -4,7 +4,7 @@ import { Endpoint } from '@/server/api/endpoint-base.js';
import { MetaService } from '@/core/MetaService.js';
import type { Config } from '@/config.js';
import { DI } from '@/di-symbols.js';
import { DEFAULT_ROLE } from '@/core/RoleService.js';
import { DEFAULT_POLICIES } from '@/core/RoleService.js';
export const meta = {
tags: ['meta'],
@@ -440,7 +440,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
deeplIsPro: instance.deeplIsPro,
enableIpLogging: instance.enableIpLogging,
enableActiveEmailValidation: instance.enableActiveEmailValidation,
baseRole: { ...DEFAULT_ROLE, ...instance.defaultRoleOverride },
policies: { ...DEFAULT_POLICIES, ...instance.policies },
};
});
}

View File

@@ -25,7 +25,7 @@ export const paramDef = {
isModerator: { type: 'boolean' },
isAdministrator: { type: 'boolean' },
canEditMembersByModerator: { type: 'boolean' },
options: {
policies: {
type: 'object',
},
},
@@ -39,7 +39,7 @@ export const paramDef = {
'isModerator',
'isAdministrator',
'canEditMembersByModerator',
'options',
'policies',
],
} as const;
@@ -70,7 +70,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
isAdministrator: ps.isAdministrator,
isModerator: ps.isModerator,
canEditMembersByModerator: ps.canEditMembersByModerator,
options: ps.options,
policies: ps.policies,
}).then(x => this.rolesRepository.findOneByOrFail(x.identifiers[0]));
this.globalEventService.publishInternalEvent('roleCreated', created);

View File

@@ -16,12 +16,12 @@ export const meta = {
export const paramDef = {
type: 'object',
properties: {
options: {
policies: {
type: 'object',
},
},
required: [
'options',
'policies',
],
} as const;
@@ -34,9 +34,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
) {
super(meta, paramDef, async (ps) => {
await this.metaService.update({
defaultRoleOverride: ps.options,
policies: ps.policies,
});
this.globalEventService.publishInternalEvent('defaultRoleOverrideUpdated', ps.options);
this.globalEventService.publishInternalEvent('policiesUpdated', ps.policies);
});
}
}

View File

@@ -33,7 +33,7 @@ export const paramDef = {
isModerator: { type: 'boolean' },
isAdministrator: { type: 'boolean' },
canEditMembersByModerator: { type: 'boolean' },
options: {
policies: {
type: 'object',
},
},
@@ -48,7 +48,7 @@ export const paramDef = {
'isModerator',
'isAdministrator',
'canEditMembersByModerator',
'options',
'policies',
],
} as const;
@@ -79,7 +79,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
isModerator: ps.isModerator,
isAdministrator: ps.isAdministrator,
canEditMembersByModerator: ps.canEditMembersByModerator,
options: ps.options,
policies: ps.policies,
});
const updated = await this.rolesRepository.findOneByOrFail({ id: ps.roleId });
this.globalEventService.publishInternalEvent('roleUpdated', updated);

View File

@@ -52,7 +52,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
}
const isModerator = await this.roleService.isModerator(user);
const isSilenced = !(await this.roleService.getUserRoleOptions(user.id)).canPublicNote;
const isSilenced = !(await this.roleService.getUserPolicies(user.id)).canPublicNote;
const _me = await this.usersRepository.findOneByOrFail({ id: me.id });
if (!await this.roleService.isAdministrator(_me) && await this.roleService.isAdministrator(user)) {
@@ -94,6 +94,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
lastActiveDate: user.lastActiveDate,
moderationNote: profile.moderationNote,
signins,
policies: await this.roleService.getUserPolicies(user.id),
roles: await this.roleEntityService.packMany(roles, me, { detail: false }),
};
});

View File

@@ -92,7 +92,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
const currentAntennasCount = await this.antennasRepository.countBy({
userId: me.id,
});
if (currentAntennasCount > (await this.roleService.getUserRoleOptions(me.id)).antennaLimit) {
if (currentAntennasCount > (await this.roleService.getUserPolicies(me.id)).antennaLimit) {
throw new ApiError(meta.errors.tooManyAntennas);
}

View File

@@ -97,7 +97,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
const currentCount = await this.clipNotesRepository.countBy({
clipId: clip.id,
});
if (currentCount > (await this.roleService.getUserRoleOptions(me.id)).noteEachClipsLimit) {
if (currentCount > (await this.roleService.getUserPolicies(me.id)).noteEachClipsLimit) {
throw new ApiError(meta.errors.tooManyClipNotes);
}

View File

@@ -54,7 +54,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
const currentCount = await this.clipsRepository.countBy({
userId: me.id,
});
if (currentCount > (await this.roleService.getUserRoleOptions(me.id)).clipLimit) {
if (currentCount > (await this.roleService.getUserPolicies(me.id)).clipLimit) {
throw new ApiError(meta.errors.tooManyClips);
}

View File

@@ -47,10 +47,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
// Calculate drive usage
const usage = await this.driveFileEntityService.calcDriveUsageOf(me.id);
const myRole = await this.roleService.getUserRoleOptions(me.id);
const policies = await this.roleService.getUserPolicies(me.id);
return {
capacity: 1024 * 1024 * myRole.driveCapacityMb,
capacity: 1024 * 1024 * policies.driveCapacityMb,
usage: usage,
};
});

View File

@@ -173,7 +173,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
if (ps.mutedWords !== undefined) {
// TODO: ちゃんと数える
const length = JSON.stringify(ps.mutedWords).length;
if (length > (await this.roleService.getUserRoleOptions(user.id)).wordMuteLimit) {
if (length > (await this.roleService.getUserPolicies(user.id)).wordMuteLimit) {
throw new ApiError(meta.errors.tooManyMutedWords);
}

View File

@@ -54,7 +54,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
const currentWebhooksCount = await this.webhooksRepository.countBy({
userId: me.id,
});
if (currentWebhooksCount > (await this.roleService.getUserRoleOptions(me.id)).webhookLimit) {
if (currentWebhooksCount > (await this.roleService.getUserPolicies(me.id)).webhookLimit) {
throw new ApiError(meta.errors.tooManyWebhooks);
}

View File

@@ -9,7 +9,7 @@ export const meta = {
tags: ['meta'],
requireCredential: true,
requireRoleOption: 'canInvite',
requireRolePolicy: 'canInvite',
res: {
type: 'object',

View File

@@ -7,7 +7,7 @@ import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { MetaService } from '@/core/MetaService.js';
import type { Config } from '@/config.js';
import { DI } from '@/di-symbols.js';
import { DEFAULT_ROLE } from '@/core/RoleService.js';
import { DEFAULT_POLICIES } from '@/core/RoleService.js';
export const meta = {
tags: ['meta'],
@@ -334,7 +334,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
translatorAvailable: instance.deeplAuthKey != null,
baseRole: { ...DEFAULT_ROLE, ...instance.defaultRoleOverride },
policies: { ...DEFAULT_POLICIES, ...instance.policies },
...(ps.detail ? {
pinnedPages: instance.pinnedPages,

View File

@@ -62,8 +62,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
private activeUsersChart: ActiveUsersChart,
) {
super(meta, paramDef, async (ps, me) => {
const role = await this.roleService.getUserRoleOptions(me ? me.id : null);
if (!role.gtlAvailable) {
const policies = await this.roleService.getUserPolicies(me ? me.id : null);
if (!policies.gtlAvailable) {
throw new ApiError(meta.errors.gtlDisabled);
}

View File

@@ -71,8 +71,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
private activeUsersChart: ActiveUsersChart,
) {
super(meta, paramDef, async (ps, me) => {
const role = await this.roleService.getUserRoleOptions(me.id);
if (!role.ltlAvailable) {
const policies = await this.roleService.getUserPolicies(me.id);
if (!policies.ltlAvailable) {
throw new ApiError(meta.errors.stlDisabled);
}

View File

@@ -67,8 +67,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
private activeUsersChart: ActiveUsersChart,
) {
super(meta, paramDef, async (ps, me) => {
const role = await this.roleService.getUserRoleOptions(me ? me.id : null);
if (!role.ltlAvailable) {
const policies = await this.roleService.getUserPolicies(me ? me.id : null);
if (!policies.ltlAvailable) {
throw new ApiError(meta.errors.ltlDisabled);
}

View File

@@ -55,7 +55,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
const currentCount = await this.userListsRepository.countBy({
userId: me.id,
});
if (currentCount > (await this.roleService.getUserRoleOptions(me.id)).userListLimit) {
if (currentCount > (await this.roleService.getUserPolicies(me.id)).userListLimit) {
throw new ApiError(meta.errors.tooManyUserLists);
}