2023-07-27 14:31:52 +09:00
|
|
|
/*
|
|
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
*/
|
|
|
|
|
|
2023-01-12 21:02:26 +09:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
|
|
|
|
import { RoleEntityService } from '@/core/entities/RoleEntityService.js';
|
2023-09-25 10:29:12 +09:00
|
|
|
import { RoleService } from '@/core/RoleService.js';
|
2023-01-12 21:02:26 +09:00
|
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
|
tags: ['admin', 'role'],
|
|
|
|
|
|
|
|
|
|
requireCredential: true,
|
|
|
|
|
requireAdmin: true,
|
|
|
|
|
} as const;
|
|
|
|
|
|
|
|
|
|
export const paramDef = {
|
|
|
|
|
type: 'object',
|
|
|
|
|
properties: {
|
|
|
|
|
name: { type: 'string' },
|
|
|
|
|
description: { type: 'string' },
|
|
|
|
|
color: { type: 'string', nullable: true },
|
2023-02-05 10:37:03 +09:00
|
|
|
iconUrl: { type: 'string', nullable: true },
|
2023-02-09 11:31:40 +09:00
|
|
|
target: { type: 'string', enum: ['manual', 'conditional'] },
|
2023-01-13 11:03:54 +09:00
|
|
|
condFormula: { type: 'object' },
|
2023-01-12 21:02:26 +09:00
|
|
|
isPublic: { type: 'boolean' },
|
|
|
|
|
isModerator: { type: 'boolean' },
|
|
|
|
|
isAdministrator: { type: 'boolean' },
|
2023-04-20 16:09:54 +00:00
|
|
|
isExplorable: { type: 'boolean', default: false }, // optional for backward compatibility
|
2023-02-05 10:37:03 +09:00
|
|
|
asBadge: { type: 'boolean' },
|
2023-01-12 21:02:26 +09:00
|
|
|
canEditMembersByModerator: { type: 'boolean' },
|
2023-03-12 16:38:08 +09:00
|
|
|
displayOrder: { type: 'number' },
|
2023-01-15 20:52:53 +09:00
|
|
|
policies: {
|
2023-01-12 21:02:26 +09:00
|
|
|
type: 'object',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
required: [
|
|
|
|
|
'name',
|
|
|
|
|
'description',
|
|
|
|
|
'color',
|
2023-02-05 10:37:03 +09:00
|
|
|
'iconUrl',
|
2023-01-13 11:03:54 +09:00
|
|
|
'target',
|
|
|
|
|
'condFormula',
|
2023-01-12 21:02:26 +09:00
|
|
|
'isPublic',
|
|
|
|
|
'isModerator',
|
|
|
|
|
'isAdministrator',
|
2023-02-05 10:37:03 +09:00
|
|
|
'asBadge',
|
2023-01-12 21:02:26 +09:00
|
|
|
'canEditMembersByModerator',
|
2023-03-12 16:38:08 +09:00
|
|
|
'displayOrder',
|
2023-01-15 20:52:53 +09:00
|
|
|
'policies',
|
2023-01-12 21:02:26 +09:00
|
|
|
],
|
|
|
|
|
} as const;
|
|
|
|
|
|
|
|
|
|
@Injectable()
|
2023-08-17 21:20:58 +09:00
|
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
|
2023-01-12 21:02:26 +09:00
|
|
|
constructor(
|
|
|
|
|
private roleEntityService: RoleEntityService,
|
2023-09-25 10:29:12 +09:00
|
|
|
private roleService: RoleService,
|
2023-01-12 21:02:26 +09:00
|
|
|
) {
|
|
|
|
|
super(meta, paramDef, async (ps, me) => {
|
2023-09-25 10:29:12 +09:00
|
|
|
const created = await this.roleService.create(ps, me);
|
2023-01-12 21:02:26 +09:00
|
|
|
|
|
|
|
|
return await this.roleEntityService.pack(created, me);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|