Skip to content

Commit

Permalink
fix: RoleServiceからPackを通して型RolePoliciesに依存させないように
Browse files Browse the repository at this point in the history
  • Loading branch information
hideki0403 committed Jan 14, 2024
1 parent cfc0e9f commit fd6dd69
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/backend/src/core/RoleService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@ import type { GlobalEvents } from '@/core/GlobalEventService.js';
import { GlobalEventService } from '@/core/GlobalEventService.js';
import { IdService } from '@/core/IdService.js';
import { ModerationLogService } from '@/core/ModerationLogService.js';
import type { Packed, KeyOf } from '@/misc/json-schema.js';
import type { Packed } from '@/misc/json-schema.js';
import { FanoutTimelineService } from '@/core/FanoutTimelineService.js';
import { NotificationService } from '@/core/NotificationService.js';
import type { OnApplicationShutdown, OnModuleInit } from '@nestjs/common';

export type RolePolicies = Packed<'RolePolicies'>;

export const DEFAULT_POLICIES: RolePolicies = {
export const DEFAULT_POLICIES = {
gtlAvailable: true,
ltlAvailable: true,
canPublicNote: true,
Expand All @@ -60,6 +58,8 @@ export const DEFAULT_POLICIES: RolePolicies = {
avatarDecorationLimit: 1,
};

export type RolePolicies = typeof DEFAULT_POLICIES;

@Injectable()
export class RoleService implements OnApplicationShutdown, OnModuleInit {
private rolesCache: MemorySingleCache<MiRole[]>;
Expand Down Expand Up @@ -280,7 +280,7 @@ export class RoleService implements OnApplicationShutdown, OnModuleInit {

const roles = await this.getUserRoles(userId);

function calc<T extends KeyOf<'RolePolicies'>>(name: T, aggregate: (values: RolePolicies[T][]) => RolePolicies[T]) {
function calc<T extends keyof RolePolicies>(name: T, aggregate: (values: RolePolicies[T][]) => RolePolicies[T]) {
if (roles.length === 0) return basePolicies[name];

const policies = roles.map(role => role.policies[name] ?? { priority: 0, useDefault: true });
Expand Down

0 comments on commit fd6dd69

Please sign in to comment.