This commit is contained in:
tamaina
2023-05-27 19:17:29 +00:00
parent 8d36911f90
commit 654c93b0ce
6 changed files with 273 additions and 44 deletions

View File

@@ -8,6 +8,8 @@ import type { Role } from '@/models/entities/Role.js';
import { bindThis } from '@/decorators.js';
import { DEFAULT_POLICIES } from '@/core/RoleService.js';
import { UserEntityService } from './UserEntityService.js';
import { Packed } from 'misskey-js';
import { Serialized } from 'schema-type';
@Injectable()
export class RoleEntityService {
@@ -26,7 +28,7 @@ export class RoleEntityService {
public async pack(
src: Role['id'] | Role,
me?: { id: User['id'] } | null | undefined,
) {
): Promise<Serialized<Packed<'Role'>>> {
const role = typeof src === 'object' ? src : await this.rolesRepository.findOneByOrFail({ id: src });
const assignedCount = await this.roleAssignmentsRepository.createQueryBuilder('assign')
@@ -37,7 +39,7 @@ export class RoleEntityService {
}))
.getCount();
const policies = { ...role.policies };
const policies: { [x: string]: Packed<'RolePolicy'> } = { ...role.policies };
for (const [k, v] of Object.entries(DEFAULT_POLICIES)) {
if (policies[k] == null) policies[k] = {
useDefault: true,
@@ -72,8 +74,7 @@ export class RoleEntityService {
public packMany(
roles: any[],
me: { id: User['id'] },
) {
): Promise<Serialized<Packed<'Role'>>[]> {
return Promise.all(roles.map(x => this.pack(x, me)));
}
}