Skip to content

Commit

Permalink
feat: Roleに関するSchemaを追加 (#12572)
Browse files Browse the repository at this point in the history
* feat: Roleに関連するschemaを追加

* feat: 新しいRoleSchemaを使うように

* chore: misskey.jsのデータを更新

* chore: misskey-js.api.mdを更新
  • Loading branch information
yupix authored Dec 6, 2023
1 parent 00b11b1 commit e42c91d
Show file tree
Hide file tree
Showing 13 changed files with 429 additions and 71 deletions.
3 changes: 3 additions & 0 deletions packages/backend/src/misc/json-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { packedEmojiDetailedSchema, packedEmojiSimpleSchema } from '@/models/jso
import { packedFlashSchema } from '@/models/json-schema/flash.js';
import { packedAnnouncementSchema } from '@/models/json-schema/announcement.js';
import { packedSigninSchema } from '@/models/json-schema/signin.js';
import { packedRoleLiteSchema, packedRoleSchema } from '@/models/json-schema/role.js';

export const refs = {
UserLite: packedUserLiteSchema,
Expand Down Expand Up @@ -73,6 +74,8 @@ export const refs = {
EmojiDetailed: packedEmojiDetailedSchema,
Flash: packedFlashSchema,
Signin: packedSigninSchema,
RoleLite: packedRoleLiteSchema,
Role: packedRoleSchema,
};

export type Packed<x extends keyof typeof refs> = SchemaType<typeof refs[x]>;
Expand Down
157 changes: 157 additions & 0 deletions packages/backend/src/models/json-schema/role.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
const rolePolicyValue = {
type: 'object',
properties: {
value: {
oneOf: [
{
type: 'integer',
optional: false, nullable: false,
},
{
type: 'boolean',
optional: false, nullable: false,
},
],
},
priority: {
type: 'integer',
optional: false, nullable: false,
},
useDefault: {
type: 'boolean',
optional: false, nullable: false,
},
},
} as const;

export const packedRoleLiteSchema = {
type: 'object',
properties: {
id: {
type: 'string',
optional: false, nullable: false,
format: 'id',
example: 'xxxxxxxxxx',
},
name: {
type: 'string',
optional: false, nullable: false,
example: 'New Role',
},
color: {
type: 'string',
optional: false, nullable: true,
example: '#000000',
},
iconUrl: {
type: 'string',
optional: false, nullable: true,
},
description: {
type: 'string',
optional: false, nullable: false,
},
isModerator: {
type: 'boolean',
optional: false, nullable: false,
example: false,
},
isAdministrator: {
type: 'boolean',
optional: false, nullable: false,
example: false,
},
displayOrder: {
type: 'integer',
optional: false, nullable: false,
example: 0,
},
},
} as const;

export const packedRoleSchema = {
type: 'object',
allOf: [
{
type: 'object',
ref: 'RoleLite',
},
{
type: 'object',
properties: {
createdAt: {
type: 'string',
optional: false, nullable: false,
format: 'date-time',
},
updatedAt: {
type: 'string',
optional: false, nullable: false,
format: 'date-time',
},
target: {
type: 'string',
optional: false, nullable: false,
enum: ['manual', 'conditional'],
},
condFormula: {
type: 'object',
optional: false, nullable: false,
},
isPublic: {
type: 'boolean',
optional: false, nullable: false,
example: false,
},
isExplorable: {
type: 'boolean',
optional: false, nullable: false,
example: false,
},
asBadge: {
type: 'boolean',
optional: false, nullable: false,
example: false,
},
canEditMembersByModerator: {
type: 'boolean',
optional: false, nullable: false,
example: false,
},
policies: {
type: 'object',
optional: false, nullable: false,
properties: {
pinLimit: rolePolicyValue,
canInvite: rolePolicyValue,
clipLimit: rolePolicyValue,
canHideAds: rolePolicyValue,
inviteLimit: rolePolicyValue,
antennaLimit: rolePolicyValue,
gtlAvailable: rolePolicyValue,
ltlAvailable: rolePolicyValue,
webhookLimit: rolePolicyValue,
canPublicNote: rolePolicyValue,
userListLimit: rolePolicyValue,
wordMuteLimit: rolePolicyValue,
alwaysMarkNsfw: rolePolicyValue,
canSearchNotes: rolePolicyValue,
driveCapacityMb: rolePolicyValue,
rateLimitFactor: rolePolicyValue,
inviteLimitCycle: rolePolicyValue,
noteEachClipsLimit: rolePolicyValue,
inviteExpirationTime: rolePolicyValue,
canManageCustomEmojis: rolePolicyValue,
userEachUserListsLimit: rolePolicyValue,
canManageAvatarDecorations: rolePolicyValue,
canUseTranslator: rolePolicyValue,
},
},
usersCount: {
type: 'integer',
optional: false, nullable: false,
},
},
},
],
} as const;
36 changes: 1 addition & 35 deletions packages/backend/src/models/json-schema/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,41 +329,7 @@ export const packedUserDetailedNotMeOnlySchema = {
items: {
type: 'object',
nullable: false, optional: false,
properties: {
id: {
type: 'string',
nullable: false, optional: false,
format: 'id',
},
name: {
type: 'string',
nullable: false, optional: false,
},
color: {
type: 'string',
nullable: true, optional: false,
},
iconUrl: {
type: 'string',
nullable: true, optional: false,
},
description: {
type: 'string',
nullable: false, optional: false,
},
isModerator: {
type: 'boolean',
nullable: false, optional: false,
},
isAdministrator: {
type: 'boolean',
nullable: false, optional: false,
},
displayOrder: {
type: 'number',
nullable: false, optional: false,
},
},
ref: 'RoleLite',
},
},
memo: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ export const meta = {

requireCredential: true,
requireAdmin: true,

res: {
type: 'object',
optional: false, nullable: false,
ref: 'Role',
},
} as const;

export const paramDef = {
Expand Down
10 changes: 10 additions & 0 deletions packages/backend/src/server/api/endpoints/admin/roles/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ export const meta = {

requireCredential: true,
requireModerator: true,

res: {
type: 'array',
optional: false, nullable: false,
items: {
type: 'object',
optional: false, nullable: false,
ref: 'Role',
},
},
} as const;

export const paramDef = {
Expand Down
6 changes: 6 additions & 0 deletions packages/backend/src/server/api/endpoints/admin/roles/show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ export const meta = {
id: '07dc7d34-c0d8-49b7-96c6-db3ce64ee0b3',
},
},

res: {
type: 'object',
optional: false, nullable: false,
ref: 'Role',
},
} as const;

export const paramDef = {
Expand Down
10 changes: 10 additions & 0 deletions packages/backend/src/server/api/endpoints/roles/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ export const meta = {
tags: ['role'],

requireCredential: true,

res: {
type: 'array',
optional: false, nullable: false,
items: {
type: 'object',
optional: false, nullable: false,
ref: 'Role',
},
},
} as const;

export const paramDef = {
Expand Down
6 changes: 6 additions & 0 deletions packages/backend/src/server/api/endpoints/roles/show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ export const meta = {
id: 'de5502bf-009a-4639-86c1-fec349e46dcb',
},
},

res: {
type: 'object',
optional: false, nullable: false,
ref: 'Role',
},
} as const;

export const paramDef = {
Expand Down
30 changes: 29 additions & 1 deletion packages/misskey-js/etc/misskey-js.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,21 @@ type AdminRolesAssignRequest = operations['admin/roles/assign']['requestBody']['
// @public (undocumented)
type AdminRolesCreateRequest = operations['admin/roles/create']['requestBody']['content']['application/json'];

// @public (undocumented)
type AdminRolesCreateResponse = operations['admin/roles/create']['responses']['200']['content']['application/json'];

// @public (undocumented)
type AdminRolesDeleteRequest = operations['admin/roles/delete']['requestBody']['content']['application/json'];

// @public (undocumented)
type AdminRolesListResponse = operations['admin/roles/list']['responses']['200']['content']['application/json'];

// @public (undocumented)
type AdminRolesShowRequest = operations['admin/roles/show']['requestBody']['content']['application/json'];

// @public (undocumented)
type AdminRolesShowResponse = operations['admin/roles/show']['responses']['200']['content']['application/json'];

// @public (undocumented)
type AdminRolesUnassignRequest = operations['admin/roles/unassign']['requestBody']['content']['application/json'];

Expand Down Expand Up @@ -1099,8 +1108,11 @@ declare namespace entities {
AdminDeleteAccountResponse,
AdminUpdateUserNoteRequest,
AdminRolesCreateRequest,
AdminRolesCreateResponse,
AdminRolesDeleteRequest,
AdminRolesListResponse,
AdminRolesShowRequest,
AdminRolesShowResponse,
AdminRolesUpdateRequest,
AdminRolesAssignRequest,
AdminRolesUnassignRequest,
Expand Down Expand Up @@ -1414,7 +1426,9 @@ declare namespace entities {
PingResponse,
PinnedUsersResponse,
PromoReadRequest,
RolesListResponse,
RolesShowRequest,
RolesShowResponse,
RolesUsersRequest,
RolesNotesRequest,
RolesNotesResponse,
Expand Down Expand Up @@ -1519,7 +1533,9 @@ declare namespace entities {
EmojiSimple,
EmojiDetailed,
Flash,
Signin
Signin,
RoleLite,
Role
}
}
export { entities }
Expand Down Expand Up @@ -2312,6 +2328,15 @@ type ResetPasswordRequest = operations['reset-password']['requestBody']['content
// @public (undocumented)
type RetentionResponse = operations['retention']['responses']['200']['content']['application/json'];

// @public (undocumented)
type Role = components['schemas']['Role'];

// @public (undocumented)
type RoleLite = components['schemas']['RoleLite'];

// @public (undocumented)
type RolesListResponse = operations['roles/list']['responses']['200']['content']['application/json'];

// @public (undocumented)
type RolesNotesRequest = operations['roles/notes']['requestBody']['content']['application/json'];

Expand All @@ -2321,6 +2346,9 @@ type RolesNotesResponse = operations['roles/notes']['responses']['200']['content
// @public (undocumented)
type RolesShowRequest = operations['roles/show']['requestBody']['content']['application/json'];

// @public (undocumented)
type RolesShowResponse = operations['roles/show']['responses']['200']['content']['application/json'];

// @public (undocumented)
type RolesUsersRequest = operations['roles/users']['requestBody']['content']['application/json'];

Expand Down
Loading

0 comments on commit e42c91d

Please sign in to comment.