|
| 1 | +import type { FromSchema } from 'json-schema-to-ts'; |
| 2 | +import { userSchema } from './user-schema'; |
| 3 | +import { roleSchema } from './role-schema'; |
| 4 | + |
| 5 | +const permission = { |
| 6 | + type: 'object', |
| 7 | + required: ['id', 'name', 'displayName', 'type'], |
| 8 | + additionalProperties: false, |
| 9 | + properties: { |
| 10 | + id: { |
| 11 | + type: 'integer', |
| 12 | + description: 'The ID of the permission', |
| 13 | + example: 1, |
| 14 | + }, |
| 15 | + name: { |
| 16 | + type: 'string', |
| 17 | + description: 'The name of the permission', |
| 18 | + example: 'CREATE_FEATURE_STRATEGY', |
| 19 | + }, |
| 20 | + displayName: { |
| 21 | + type: 'string', |
| 22 | + description: 'The display name of the permission', |
| 23 | + example: 'Create activation strategies', |
| 24 | + }, |
| 25 | + type: { |
| 26 | + type: 'string', |
| 27 | + description: 'The type of the permission', |
| 28 | + example: 'environment', |
| 29 | + }, |
| 30 | + environment: { |
| 31 | + type: 'string', |
| 32 | + nullable: true, |
| 33 | + description: 'The environment that the permission applies to', |
| 34 | + example: 'dev', |
| 35 | + }, |
| 36 | + }, |
| 37 | +} as const; |
| 38 | + |
| 39 | +const permissionWithHasPermission = { |
| 40 | + ...permission, |
| 41 | + required: [...permission.required, 'hasPermission'], |
| 42 | + properties: { |
| 43 | + ...permission.properties, |
| 44 | + hasPermission: { |
| 45 | + type: 'boolean', |
| 46 | + description: 'Whether the user has this permission', |
| 47 | + example: true, |
| 48 | + }, |
| 49 | + }, |
| 50 | +} as const; |
| 51 | + |
| 52 | +export const userAccessOverviewSchema = { |
| 53 | + $id: '#/components/schemas/userAccessOverviewSchema', |
| 54 | + type: 'object', |
| 55 | + required: ['overview', 'user', 'rootRole', 'projectRoles'], |
| 56 | + additionalProperties: false, |
| 57 | + description: |
| 58 | + 'Describes the access overview (list of permissions and metadata) for a user.', |
| 59 | + properties: { |
| 60 | + overview: { |
| 61 | + type: 'object', |
| 62 | + required: ['root', 'project', 'environment'], |
| 63 | + additionalProperties: false, |
| 64 | + description: |
| 65 | + 'The access overview (list of permissions) for the user', |
| 66 | + properties: { |
| 67 | + root: { |
| 68 | + type: 'array', |
| 69 | + description: 'The list of root permissions', |
| 70 | + items: permissionWithHasPermission, |
| 71 | + }, |
| 72 | + project: { |
| 73 | + type: 'array', |
| 74 | + description: 'The list of project permissions', |
| 75 | + items: permissionWithHasPermission, |
| 76 | + }, |
| 77 | + environment: { |
| 78 | + type: 'array', |
| 79 | + description: 'The list of environment permissions', |
| 80 | + items: permissionWithHasPermission, |
| 81 | + }, |
| 82 | + }, |
| 83 | + }, |
| 84 | + user: { |
| 85 | + description: 'The user that this access overview is for', |
| 86 | + $ref: userSchema.$id, |
| 87 | + }, |
| 88 | + rootRole: { |
| 89 | + description: 'The name of the root role that this user has', |
| 90 | + $ref: roleSchema.$id, |
| 91 | + }, |
| 92 | + projectRoles: { |
| 93 | + type: 'array', |
| 94 | + description: |
| 95 | + 'The list of project roles that this user has in the selected project', |
| 96 | + items: { |
| 97 | + type: 'object', |
| 98 | + required: [...roleSchema.required, 'permissions'], |
| 99 | + additionalProperties: false, |
| 100 | + properties: { |
| 101 | + ...roleSchema.properties, |
| 102 | + permissions: { |
| 103 | + type: 'array', |
| 104 | + description: 'The permissions that this role has', |
| 105 | + items: permission, |
| 106 | + }, |
| 107 | + }, |
| 108 | + }, |
| 109 | + }, |
| 110 | + }, |
| 111 | + components: { |
| 112 | + schemas: { |
| 113 | + userSchema, |
| 114 | + roleSchema, |
| 115 | + }, |
| 116 | + }, |
| 117 | +} as const; |
| 118 | + |
| 119 | +export type UserAccessOverviewSchema = FromSchema< |
| 120 | + typeof userAccessOverviewSchema |
| 121 | +>; |
0 commit comments