@cdmbase/wiki-browser 12.0.18-alpha.10 → 12.0.18-alpha.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,838 @@
|
|
|
1
|
+
# How to Add Roles and Permissions Through Preferences
|
|
2
|
+
|
|
3
|
+
> **AI Agent Note**: This document is structured for both human and LLM consumption. Look for `[AI-PARSEABLE]` sections for structured schemas and `[EXAMPLE-CODE]` for implementation patterns.
|
|
4
|
+
|
|
5
|
+
This guide explains how to add new roles and their associated permissions using the preferences system, based on the tenantAdmin implementation.
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
The role and permission system consists of three main components:
|
|
10
|
+
1. **Role Definitions** - Define the roles in the system
|
|
11
|
+
2. **Permission Definitions** - Define what permissions exist
|
|
12
|
+
3. **Permission Overwrites** - Map which permissions each role has
|
|
13
|
+
|
|
14
|
+
### [AI-PARSEABLE] System Components Schema
|
|
15
|
+
|
|
16
|
+
```json
|
|
17
|
+
{
|
|
18
|
+
"system": "role-permission-preferences",
|
|
19
|
+
"components": {
|
|
20
|
+
"roles": {
|
|
21
|
+
"file": "preferences/roles/accounts-roles.ts",
|
|
22
|
+
"type": "IConfigurationSchemaMap",
|
|
23
|
+
"purpose": "Define role configurations"
|
|
24
|
+
},
|
|
25
|
+
"permissions": {
|
|
26
|
+
"file": "preferences/permissions/accounts-permissions.ts",
|
|
27
|
+
[AI-PARSEABLE] Role Definition Schema
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
interface RoleDefinition {
|
|
31
|
+
[key: string]: {
|
|
32
|
+
title: string; // Human-readable display name
|
|
33
|
+
value: ApplicationRoles; // Enum value from ApplicationRoles
|
|
34
|
+
default: ApplicationRoles; // Default value (usually same as value)
|
|
35
|
+
scope: ConfigurationScope; // APPLICATION | WINDOW | RESOURCE
|
|
36
|
+
description: string; // Purpose and access level description
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### [EXAMPLE-CODE]: "IConfigurationSchemaMap",
|
|
42
|
+
"purpose": "Define permission configurations"
|
|
43
|
+
},
|
|
44
|
+
"permissionOverwrites": {
|
|
45
|
+
"file": "preferences/roles/accounts-roles-permission-overwrite.ts",
|
|
46
|
+
"type": "Record<ApplicationRoles, ApplicationPermissions[]>",
|
|
47
|
+
"purpose": "Map roles to their permission sets"
|
|
48
|
+
},
|
|
49
|
+
"migration": {
|
|
50
|
+
"file": "migrations/dbMigrations/AddAccountsConfigurationsMigration.ts",
|
|
51
|
+
"type": "BaseConfigurationsMigration",
|
|
52
|
+
"purpose": "Register and persist configurations"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
## Architecture
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
preferences/
|
|
61
|
+
├── roles/
|
|
62
|
+
│ ├── accounts-roles.ts # Role definitions
|
|
63
|
+
│ └── accounts-roles-permission-overwrite.ts # Permission mappings
|
|
64
|
+
└── permissions/
|
|
65
|
+
└── accounts-permissions.ts # Permission definitions
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Step 1: Define Your Role
|
|
69
|
+
|
|
70
|
+
Roles are defined in `accounts-roles.ts` using the `IConfigurationSchemaMap` interface.
|
|
71
|
+
|
|
72
|
+
### Example: Adding a TenantAdmin Role
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
import { IConfigurationSchemaMap } from '@adminide-stack/core';
|
|
76
|
+
import { ApplicationRoles, ConfigurationScope } from 'common/server';
|
|
77
|
+
import { capitalize } from 'lodash-es';
|
|
78
|
+
|
|
79
|
+
const formatName = (str: string) =>
|
|
80
|
+
str
|
|
81
|
+
.split('_')
|
|
82
|
+
.map((word) => capitalize(word))
|
|
83
|
+
.join(' ');
|
|
84
|
+
|
|
85
|
+
export const AccountRolesContribution: IConfigurationSchemaMap = {
|
|
86
|
+
// Application Level Role
|
|
87
|
+
'account.role.tenantadmin': {
|
|
88
|
+
title: 'Super Admin', // Display name
|
|
89
|
+
value: ApplicationRoles.TenantAdmin, // Enum value
|
|
90
|
+
default: ApplicationRoles.TenantAdmin, // Default value
|
|
91
|
+
scope: ConfigurationScope.APPLICATION, // Scope level
|
|
92
|
+
description: 'Super Admin with full system access across all organizations',
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
// Organization Level Role
|
|
96
|
+
'organization.role.owner': {
|
|
97
|
+
title: formatName(ApplicationRoles.Owner),
|
|
98
|
+
value: ApplicationRoles.Owner,
|
|
99
|
+
default: ApplicationRoles.Owner,
|
|
100
|
+
scope: ConfigurationScope.WINDOW, // Organization scope
|
|
101
|
+
description: 'Owner of the Organization',
|
|
102
|
+
[AI-PARSEABLE] Configuration Key Naming Convention
|
|
103
|
+
|
|
104
|
+
```json
|
|
105
|
+
{
|
|
106
|
+
"namingPatterns": {
|
|
107
|
+
"applicationLevel": {
|
|
108
|
+
"pattern": "account.role.{rolename}",
|
|
109
|
+
"scope": "ConfigurationScope.APPLICATION",
|
|
110
|
+
"examples": [
|
|
111
|
+
"account.role.tenantadmin",
|
|
112
|
+
"account.role.user",
|
|
113
|
+
"account.role.guest"
|
|
114
|
+
]
|
|
115
|
+
},
|
|
116
|
+
"organizationLevel": {
|
|
117
|
+
"pattern": "organization.role.{rolename}",
|
|
118
|
+
"scope": "ConfigurationScope.WINDOW",
|
|
119
|
+
"examples": [
|
|
120
|
+
"organization.role.owner",
|
|
121
|
+
"organization.role.admin",
|
|
122
|
+
"organization.role.manager"
|
|
123
|
+
]
|
|
124
|
+
},
|
|
125
|
+
"teamLevel": {
|
|
126
|
+
"pattern": "organization.teams.role.{rolename}",
|
|
127
|
+
"scope": "ConfigurationScope.WINDOW",
|
|
128
|
+
"examples": [
|
|
129
|
+
"organization.teams.role.maintainer",
|
|
130
|
+
|
|
131
|
+
### [AI-PARSEABLE] Permission Definition Schema
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
interface PermissionDefinition {
|
|
135
|
+
[key: string]: {
|
|
136
|
+
title: string; // Human-readable display name
|
|
137
|
+
value: ApplicationPermissions; // Enum value from ApplicationPermissions
|
|
138
|
+
default: ApplicationPermissions; // Default value (usually same as value)
|
|
139
|
+
scope: ConfigurationScope; // APPLICATION | WINDOW | RESOURCE
|
|
140
|
+
description: string; // What action this permission allows
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### [EXAMPLE-CODE] Permission Definitions
|
|
146
|
+
"organization.teams.role.member"
|
|
147
|
+
]
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
"rules": {
|
|
151
|
+
"keyFormat": "lowercase with dots as separators",
|
|
152
|
+
"rolenameFormat": "lowercase, no spaces or special chars",
|
|
153
|
+
"enumFormat": "SCREAMING_SNAKE_CASE"
|
|
154
|
+
}[AI-PARSEABLE] Permission Naming Convention
|
|
155
|
+
|
|
156
|
+
```json
|
|
157
|
+
{
|
|
158
|
+
"namingPatterns": {
|
|
159
|
+
"applicationLevel": {
|
|
160
|
+
"pattern": "account.permission.{permission_name}",
|
|
161
|
+
"examples": [
|
|
162
|
+
"account.permission.create_organization",
|
|
163
|
+
|
|
164
|
+
### [AI-PARSEABLE] Permission Overwrite Schema
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
interface PermissionOverwrite {
|
|
168
|
+
[role: ApplicationRoles]: ApplicationPermissions[];
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Example structure
|
|
172
|
+
const overwrites: PermissionOverwrite = {
|
|
173
|
+
[ApplicationRoles.TenantAdmin]: [
|
|
174
|
+
/* all system permissions */
|
|
175
|
+
],
|
|
176
|
+
[ApplicationRoles.Owner]: [
|
|
177
|
+
/* organization-level permissions */
|
|
178
|
+
]
|
|
179
|
+
};
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### [EXAMPLE-CODE] Mapping Permissions to TenantAdmin
|
|
183
|
+
"account.permission.manage_users",
|
|
184
|
+
"account.permission.manage_system_settings"
|
|
185
|
+
]
|
|
186
|
+
},
|
|
187
|
+
"organizationLevel": {
|
|
188
|
+
"pattern": "organization.permission.{permission_name}",
|
|
189
|
+
"examples": [
|
|
190
|
+
"organization.permission.manage_members",
|
|
191
|
+
"organization.permission.delete_resources"
|
|
192
|
+
]
|
|
193
|
+
},
|
|
194
|
+
"resourceSpecific": {
|
|
195
|
+
"pattern": "{resource}.permission.{permission_name}",
|
|
196
|
+
"examples": [
|
|
197
|
+
"project.permission.create",
|
|
198
|
+
"team.permission.manage_members"
|
|
199
|
+
]
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
### Configuration Key Naming Convention
|
|
205
|
+
|
|
206
|
+
- **Application Level**: `account.role.{rolename}`
|
|
207
|
+
- Example: `account.role.tenantadmin`, `account.role.user`
|
|
208
|
+
|
|
209
|
+
- **Organization Level**: `organization.role.{rolename}`
|
|
210
|
+
- Example: `organization.role.owner`, `organization.role.admin`
|
|
211
|
+
|
|
212
|
+
- **Team Level**: `organization.teams.role.{rolename}`
|
|
213
|
+
- Example: `organization.teams.role.maintainer`
|
|
214
|
+
|
|
215
|
+
## Step 2: Define Permissions
|
|
216
|
+
|
|
217
|
+
Permissions are defined in `accounts-permissions.ts`.
|
|
218
|
+
|
|
219
|
+
```typescript
|
|
220
|
+
import { IConfigurationSchemaMap } from '@adminide-stack/core';
|
|
221
|
+
import { ApplicationPermissions, ConfigurationScope } from 'common/server';
|
|
222
|
+
|
|
223
|
+
export const AccountPermissionsContribution: IConfigurationSchemaMap = {
|
|
224
|
+
'account.permission.create_organization': {
|
|
225
|
+
title: 'Create Organization',.
|
|
226
|
+
|
|
227
|
+
### [AI-PARSEABLE] Migration Registration Pattern
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
interface ConfigurationMigration {
|
|
231
|
+
name: string; // Migration name (e.g., 'account')
|
|
232
|
+
id: string; // Unique ID with timestamp
|
|
233
|
+
roles: IConfigurationSchemaMap; // Role definitions
|
|
234
|
+
permissions: IConfigurationSchemaMap; // Permission definitions
|
|
235
|
+
permissionsOverride: PermissionOverwrite; // Role-permission mappings
|
|
236
|
+
policies?: object; // Optional policy configurations
|
|
237
|
+
settings?: object; // Optional settings
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### [EXAMPLE-CODE] Migration Registration
|
|
242
|
+
value: ApplicationPermissions.CREATE_ORGANIZATION,
|
|
243
|
+
default: ApplicationPermissions.CREATE_ORGANIZATION,
|
|
244
|
+
scope: ConfigurationScope.APPLICATION,
|
|
245
|
+
description: 'Permission to create new organizations',
|
|
246
|
+
},
|
|
247
|
+
|
|
248
|
+
'account.permission.manage_users': {
|
|
249
|
+
title: 'Manage Users',
|
|
250
|
+
value: ApplicationPermissions.MANAGE_USERS,
|
|
251
|
+
default: ApplicationPermissions.MANAGE_USERS,
|
|
252
|
+
[AI-AGENT-WORKFLOW] Complete Example: Adding a New "Auditor" Role
|
|
253
|
+
|
|
254
|
+
### [AI-PARSEABLE] Implementation Checklist
|
|
255
|
+
|
|
256
|
+
```json
|
|
257
|
+
{
|
|
258
|
+
"workflow": {
|
|
259
|
+
"step1": {
|
|
260
|
+
"action": "Update ApplicationRoles enum",
|
|
261
|
+
"file": "common/server (or equivalent)",
|
|
262
|
+
"required": true
|
|
263
|
+
},
|
|
264
|
+
"step2": {
|
|
265
|
+
"action": "Add role definition",
|
|
266
|
+
"file": "preferences/roles/accounts-roles.ts",
|
|
267
|
+
"required": true
|
|
268
|
+
},
|
|
269
|
+
"step3": {
|
|
270
|
+
"action": "Define new permissions if needed",
|
|
271
|
+
"file": "preferences/permissions/accounts-permissions.ts",
|
|
272
|
+
"required": false
|
|
273
|
+
},
|
|
274
|
+
"step4": {
|
|
275
|
+
"action": "Map permissions to role",
|
|
276
|
+
"file": "preferences/roles/accounts-roles-permission-overwrite.ts",
|
|
277
|
+
"required": true
|
|
278
|
+
},
|
|
279
|
+
"step5": {
|
|
280
|
+
"action": "Update migration ID",
|
|
281
|
+
"[STEP-2] file": "migrations/dbMigrations/AddAccountsConfigurationsMigration.ts",
|
|
282
|
+
"required": true,
|
|
283
|
+
"note": "Change timestamp in migration ID to trigger re-run"
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### 1. [STEP-1]
|
|
290
|
+
};
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
### Permission Naming Convention
|
|
294
|
+
|
|
295
|
+
- **Application Level**: `account.permission.{permission_name}`
|
|
296
|
+
- **Organization Level**: `organization.permission.{permission_name}`
|
|
297
|
+
- **Resource Specific**: `{resource}.permission.{permission_name}`
|
|
298
|
+
[STEP-3]
|
|
299
|
+
## Step 3: Map Permissions to Roles
|
|
300
|
+
|
|
301
|
+
Permission overwrites are defined in `accounts-roles-permission-overwrite.ts`.
|
|
302
|
+
|
|
303
|
+
```typescript
|
|
304
|
+
import { ApplicationRoles, ApplicationPermissions } from 'common/server';
|
|
305
|
+
|
|
306
|
+
export const AccountRolesPermissionOverwrite = {
|
|
307
|
+
[ApplicationRoles.TenantAdmin]: [
|
|
308
|
+
// System Management
|
|
309
|
+
ApplicationPermissions.CREATE_ORGANIZATION,
|
|
310
|
+
ApplicationPermissions.DELETE_ORGANIZATION,
|
|
311
|
+
ApplicationPermissions.MANAGE_USERS,
|
|
312
|
+
ApplicationPermissions.MANAGE_SYSTEM_SETTINGS,
|
|
313
|
+
|
|
314
|
+
// Billing & Subscriptions
|
|
315
|
+
ApplicationPermissions.MANAGE_SUBSCRIPTIONS,
|
|
316
|
+
ApplicationPermissions.VIEW_BILLING,
|
|
317
|
+
|
|
318
|
+
// Full Organization Access
|
|
319
|
+
ApplicationPermissions.OWNER_PERMISSIONS,
|
|
320
|
+
ApplicationPermissions.ADMIN_PERMISSIONS,
|
|
321
|
+
|
|
322
|
+
// ... all other permissions
|
|
323
|
+
],
|
|
324
|
+
|
|
325
|
+
[ApplicationRoles.Owner]: [
|
|
326
|
+
ApplicationPermissions.OWNER_PERMISSIONS,
|
|
327
|
+
ApplicationPermissions.MANAGE_ORGANIZATION,
|
|
328
|
+
ApplicationPermissions.INVITE_MEMBERS,
|
|
329
|
+
// ... organization-level permissions
|
|
330
|
+
],
|
|
331
|
+
};
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
## Step 4: Register in Migration
|
|
335
|
+
|
|
336
|
+
Register your roles and permissions in the migration class:
|
|
337
|
+
|
|
338
|
+
```typescript
|
|
339
|
+
import [STEP-4] {
|
|
340
|
+
AccountPermissionsContribution,
|
|
341
|
+
AccountRolesContribution,
|
|
342
|
+
AccountRolesPermissionOverwrite,
|
|
343
|
+
} from '../../preferences';
|
|
344
|
+
|
|
345
|
+
@injectable()
|
|
346
|
+
export class AddAccountsConfigurationsMigration extends BaseConfigurationsMigration {
|
|
347
|
+
name = 'account';
|
|
348
|
+
|
|
349
|
+
get roles() {
|
|
350
|
+
return AccountRolesContribution;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
get permissions() {
|
|
354
|
+
return AccountPermissionsContribution;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
[AI-PARSEABLE] Scope Definitions
|
|
358
|
+
|
|
359
|
+
```json
|
|
360
|
+
{
|
|
361
|
+
"scopes": {
|
|
362
|
+
"APPLICATION": {
|
|
363
|
+
"value": "ConfigurationScope.APPLICATION",
|
|
364
|
+
"level": "system-wide",
|
|
365
|
+
"appliesTo": "entire system across all organizations",
|
|
366
|
+
"useCases": [
|
|
367
|
+
"System administrator roles",
|
|
368
|
+
"Global permissions",
|
|
369
|
+
"Cross-organization access"
|
|
370
|
+
],
|
|
371
|
+
"examples": [
|
|
372
|
+
"ApplicationRoles.TenantAdmin",
|
|
373
|
+
"ApplicationRoles.User",
|
|
374
|
+
"ApplicationRoles.Guest"
|
|
375
|
+
]
|
|
376
|
+
},
|
|
377
|
+
"WINDOW": {
|
|
378
|
+
"value": "ConfigurationScope.WINDOW",
|
|
379
|
+
"level": "organization-specific",
|
|
380
|
+
"appliesTo": "single organization context",
|
|
381
|
+
"useCases": [
|
|
382
|
+
"Organization management roles",
|
|
383
|
+
"Team-level permissions",
|
|
384
|
+
"Organization-scoped access"
|
|
385
|
+
],
|
|
386
|
+
"examples": [
|
|
387
|
+
"ApplicationRoles.Owner",
|
|
388
|
+
"ApplicationRoles.Admin",
|
|
389
|
+
"ApplicationRoles.Manager",
|
|
390
|
+
"ApplicationRoles.Member"
|
|
391
|
+
]
|
|
392
|
+
},
|
|
393
|
+
"RESOURCE": {
|
|
394
|
+
[AI-PARSEABLE] Role Hierarchy Structure
|
|
395
|
+
|
|
396
|
+
```json
|
|
397
|
+
{
|
|
398
|
+
"roleHierarchy": {
|
|
399
|
+
"TenantAdmin": {
|
|
400
|
+
"level": "SYSTEM",
|
|
401
|
+
"scope": "APPLICATION",
|
|
402
|
+
"permissions": "ALL",
|
|
403
|
+
"children": ["Owner", "TeamMaintainer"]
|
|
404
|
+
},
|
|
405
|
+
"Owner": {
|
|
406
|
+
"level": "ORGANIZATION",
|
|
407
|
+
"scope": "WINDOW",
|
|
408
|
+
"permissions": "ORGANIZATION_ALL",
|
|
409
|
+
"children": ["Admin"]
|
|
410
|
+
},
|
|
411
|
+
"Admin": {
|
|
412
|
+
"level": "ORGANIZATION",
|
|
413
|
+
"scope": "WINDOW",
|
|
414
|
+
"permissions": "ORGANIZATION_MANAGEMENT",
|
|
415
|
+
"children": ["Manager"]
|
|
416
|
+
},
|
|
417
|
+
"Manager": {
|
|
418
|
+
"level": "ORGANIZATION",
|
|
419
|
+
"scope": "WINDOW",
|
|
420
|
+
"permissions": "ORGANIZATION_OPERATIONS",
|
|
421
|
+
"children": ["Contributor", "Member"]
|
|
422
|
+
},
|
|
423
|
+
"Contributor": {
|
|
424
|
+
"level": "ORGANIZATION",
|
|
425
|
+
"scope": "WINDOW",
|
|
426
|
+
"permissions": "READ_WRITE",
|
|
427
|
+
"children": []
|
|
428
|
+
},
|
|
429
|
+
"Member": {
|
|
430
|
+
"level": "ORGANIZATION",
|
|
431
|
+
"scope": "WINDOW",
|
|
432
|
+
"permissions": "READ_ONLY",
|
|
433
|
+
"children": []
|
|
434
|
+
},
|
|
435
|
+
"Guest": {
|
|
436
|
+
"level": "PUBLIC",
|
|
437
|
+
"scope": "APPLICATION",
|
|
438
|
+
"permissions": "PUBLIC_ONLY",
|
|
439
|
+
"children": []
|
|
440
|
+
},
|
|
441
|
+
"TeamMaintainer": {
|
|
442
|
+
"level": "TEAM",
|
|
443
|
+
[AI-AGENT-WORKFLOW] Migration Process
|
|
444
|
+
|
|
445
|
+
### [AI-PARSEABLE] Migration Workflow
|
|
446
|
+
|
|
447
|
+
```json
|
|
448
|
+
{
|
|
449
|
+
"migrationWorkflow": {
|
|
450
|
+
"step1_updateEnums": {
|
|
451
|
+
"order": 1,
|
|
452
|
+
"action": "Add new values to ApplicationRoles or ApplicationPermissions enum",
|
|
453
|
+
"location": "common/server or equivalent",
|
|
454
|
+
"format": "SCREAMING_SNAKE_CASE",
|
|
455
|
+
"example": "ApplicationRoles.Auditor = 'AUDITOR'",
|
|
456
|
+
"critical": true
|
|
457
|
+
},
|
|
458
|
+
"step2_defineConfiguration": {
|
|
459
|
+
"order": 2,
|
|
460
|
+
"action": "Add role/permission definitions to preference files",
|
|
461
|
+
"locations": [
|
|
462
|
+
"preferences/roles/accounts-roles.ts",
|
|
463
|
+
"preferences/permissions/accounts-permissions.ts",
|
|
464
|
+
"preferences/roles/accounts-roles-permission-overwrite.ts"
|
|
465
|
+
],
|
|
466
|
+
"critical": true
|
|
467
|
+
},
|
|
468
|
+
"step3_updateMigrationId": {
|
|
469
|
+
"order": 3,
|
|
470
|
+
"action": "Update migration ID with new timestamp",
|
|
471
|
+
"location": "migrations/dbMigrations/AddAccountsConfigurationsMigration.ts",
|
|
472
|
+
"property": "get id()",
|
|
473
|
+
"format": "${ClassName}_YYYYMMDD",
|
|
474
|
+
[AI-PARSEABLE] Troubleshooting Guide
|
|
475
|
+
|
|
476
|
+
```json
|
|
477
|
+
{
|
|
478
|
+
"troubleshooting": {
|
|
479
|
+
"roleNotAppearing": {
|
|
480
|
+
"symptoms": ["Role not visible in UI", "Role not available for assignment"],
|
|
481
|
+
"diagnosticChecks": [
|
|
482
|
+
{
|
|
483
|
+
"check": "Enum definition exists",
|
|
484
|
+
"location": "common/server ApplicationRoles enum",
|
|
485
|
+
"fix": "Add role to ApplicationRoles enum"
|
|
486
|
+
},
|
|
487
|
+
{
|
|
488
|
+
"check": "Configuration key naming correct",
|
|
489
|
+
"expected": "account.role.{rolename} or organization.role.{rolename}",
|
|
490
|
+
"fix": "Verify naming follows convention"
|
|
491
|
+
},
|
|
492
|
+
{
|
|
493
|
+
"check": "Migration has been run",
|
|
494
|
+
[AI-PARSEABLE] Quick Reference Card
|
|
495
|
+
|
|
496
|
+
```json
|
|
497
|
+
{
|
|
498
|
+
"quickReference": {
|
|
499
|
+
"files": {
|
|
500
|
+
"roleDefinitions": "preferences/roles/accounts-roles.ts",
|
|
501
|
+
"permissionDefinitions": "preferences/permissions/accounts-permissions.ts",
|
|
502
|
+
"permissionMappings": "preferences/roles/accounts-roles-permission-overwrite.ts",
|
|
503
|
+
"migration": "migrations/dbMigrations/AddAccountsConfigurationsMigration.ts",
|
|
504
|
+
"enums": "common/server (or equivalent package)"
|
|
505
|
+
},
|
|
506
|
+
"keyInterfaces": {
|
|
507
|
+
"IConfigurationSchemaMap": "@adminide-stack/core",
|
|
508
|
+
"ConfigurationScope": "common/server",
|
|
509
|
+
"ApplicationRoles": "common/server",
|
|
510
|
+
"ApplicationPermissions": "common/server",
|
|
511
|
+
"BaseConfigurationsMigration": "@adminide-stack/platform-server"
|
|
512
|
+
},
|
|
513
|
+
"namingConventions": {
|
|
514
|
+
"roleConfigKey": "account.role.{rolename} | organization.role.{rolename}",
|
|
515
|
+
"permissionConfigKey": "account.permission.{permname} | organization.permission.{permname}",
|
|
516
|
+
"enumFormat": "SCREAMING_SNAKE_CASE",
|
|
517
|
+
"migrationIdFormat": "${ClassName}_YYYYMMDD"
|
|
518
|
+
},
|
|
519
|
+
"scopes": {
|
|
520
|
+
"APPLICATION": "System-wide, across all organizations",
|
|
521
|
+
"WINDOW": "Organization or team level",
|
|
522
|
+
"RESOURCE": "Specific to individual entities"
|
|
523
|
+
},
|
|
524
|
+
"workflow": [
|
|
525
|
+
"1. Update ApplicationRoles/ApplicationPermissions enum",
|
|
526
|
+
"2. Add to accounts-roles.ts or accounts-permissions.ts",
|
|
527
|
+
"3. Map in accounts-roles-permission-overwrite.ts",
|
|
528
|
+
"4. Update migration ID timestamp",
|
|
529
|
+
"5. Run migration"
|
|
530
|
+
]
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
## References
|
|
536
|
+
|
|
537
|
+
- [accounts-roles.ts](./accounts-roles.ts) - Role definitions
|
|
538
|
+
- [accounts-roles-permission-overwrite.ts](./accounts-roles-permission-overwrite.ts) - Permission mappings
|
|
539
|
+
- [AddAccountsConfigurationsMigration.ts](../../migrations/dbMigrations/AddAccountsConfigurationsMigration.ts) - Migration implementation
|
|
540
|
+
- Configuration Registry: `@adminide-stack/core`
|
|
541
|
+
- Common Types: `common/server`
|
|
542
|
+
|
|
543
|
+
---
|
|
544
|
+
|
|
545
|
+
## AI Agent Usage Notes
|
|
546
|
+
|
|
547
|
+
This document includes:
|
|
548
|
+
- **[AI-PARSEABLE]** sections with structured JSON schemas for machine parsing
|
|
549
|
+
- **[EXAMPLE-CODE]** sections with complete implementation examples
|
|
550
|
+
- **[AI-AGENT-WORKFLOW]** sections with step-by-step process definitions
|
|
551
|
+
- **[STEP-N]** markers for sequential task execution
|
|
552
|
+
- JSON schemas for all key data structures
|
|
553
|
+
- Structured troubleshooting decision trees
|
|
554
|
+
- Quick reference card for rapid lookups
|
|
555
|
+
|
|
556
|
+
AI agents can extract structured information from JSON blocks and follow the workflow markers for automated implementation tasks.amp in migration ID"
|
|
557
|
+
}
|
|
558
|
+
]
|
|
559
|
+
},
|
|
560
|
+
"permissionsNotWorking": {
|
|
561
|
+
"symptoms": ["Access denied", "Permissions not taking effect"],
|
|
562
|
+
"diagnosticChecks": [
|
|
563
|
+
{
|
|
564
|
+
"check": "Permission listed in permissionsOverride",
|
|
565
|
+
"location": "accounts-roles-permission-overwrite.ts",
|
|
566
|
+
"fix": "Add permission to role's permission array"
|
|
567
|
+
},
|
|
568
|
+
{
|
|
569
|
+
"check": "Role hierarchy correct",
|
|
570
|
+
"validation": "Check if higher roles include lower role permissions",
|
|
571
|
+
"fix": "Review and update permission inheritance"
|
|
572
|
+
},
|
|
573
|
+
{
|
|
574
|
+
"check": "ApplicationPermissions enum updated",
|
|
575
|
+
"location": "common/server ApplicationPermissions enum",
|
|
576
|
+
"fix": "Add permission to enum"
|
|
577
|
+
},
|
|
578
|
+
{
|
|
579
|
+
"check": "Redis cache cleared",
|
|
580
|
+
"command": "Clear Redis cache manually or restart",
|
|
581
|
+
"fix": "Clear cache via redisCacheManager"
|
|
582
|
+
}
|
|
583
|
+
]
|
|
584
|
+
},
|
|
585
|
+
"migrationNotRunning": {
|
|
586
|
+
"symptoms": ["New configurations not in database", "Changes not reflected"],
|
|
587
|
+
"diagnosticChecks": [
|
|
588
|
+
{
|
|
589
|
+
"check": "Migration ID updated with new timestamp",
|
|
590
|
+
"location": "get id() method",
|
|
591
|
+
"fix": "Change date suffix: _20260128"
|
|
592
|
+
},
|
|
593
|
+
{
|
|
594
|
+
"check": "Database connection working",
|
|
595
|
+
"command": "Verify MongoDB connection",
|
|
596
|
+
"fix": "Check connection string and credentials"
|
|
597
|
+
},
|
|
598
|
+
{
|
|
599
|
+
"check": "Migration logs",
|
|
600
|
+
"location": "Application logs",
|
|
601
|
+
"fix": "Review error messages in migration logs"
|
|
602
|
+
},
|
|
603
|
+
{
|
|
604
|
+
"check": "Inheritance from BaseConfigurationsMigration",
|
|
605
|
+
"location": "Class declaration",
|
|
606
|
+
"fix": "Ensure extends BaseConfigurationsMigration"
|
|
607
|
+
}
|
|
608
|
+
]
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
```
|
|
613
|
+
|
|
614
|
+
### Common Issues
|
|
615
|
+
|
|
616
|
+
#### Role Not Appearing
|
|
617
|
+
- Check enum definition in common/server
|
|
618
|
+
- Verify configuration key naming
|
|
619
|
+
- Ensure migration has been run
|
|
620
|
+
- Check migration ID has been updated
|
|
621
|
+
|
|
622
|
+
#### Permissions Not Working
|
|
623
|
+
- Verify permission is listed in permissionsOverride
|
|
624
|
+
- Check role hierarchy
|
|
625
|
+
- Ensure ApplicationPermissions enum is updated
|
|
626
|
+
- Clear Redis cache if needed
|
|
627
|
+
|
|
628
|
+
# "manual": "Can be done via redisCacheManager if needed"
|
|
629
|
+
}
|
|
630
|
+
},
|
|
631
|
+
"migrationIdFormat": {
|
|
632
|
+
"pattern": "${MigrationClassName}_${YYYYMMDD}",
|
|
633
|
+
"examples": [
|
|
634
|
+
"AddAccountsConfigurationsMigration_20260113",
|
|
635
|
+
"AddAccountsConfigurationsMigration_20260128"
|
|
636
|
+
],
|
|
637
|
+
"requirement": "Must change to trigger re-run"
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
```
|
|
641
|
+
|
|
642
|
+
### Implementation Steps
|
|
643
|
+
},
|
|
644
|
+
"TeamMember": {
|
|
645
|
+
"level": "TEAM",
|
|
646
|
+
"scope": "WINDOW",
|
|
647
|
+
"permissions": "TEAM_ACCESS",
|
|
648
|
+
"children": []
|
|
649
|
+
}
|
|
650
|
+
},
|
|
651
|
+
"hierarchyRules": {
|
|
652
|
+
"inheritance": "Higher roles include all permissions of lower roles",
|
|
653
|
+
"tenantAdminRule": "TenantAdmin has all system permissions",
|
|
654
|
+
"ownerRule": "Owner has all organization permissions within their org"
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
```
|
|
658
|
+
|
|
659
|
+
### Visuale": "ConfigurationScope.RESOURCE",
|
|
660
|
+
"level": "resource-specific",
|
|
661
|
+
"appliesTo": "individual entities",
|
|
662
|
+
"useCases": [
|
|
663
|
+
"Project-specific roles",
|
|
664
|
+
"Document-level permissions",
|
|
665
|
+
"Fine-grained access control"
|
|
666
|
+
],
|
|
667
|
+
"examples": [
|
|
668
|
+
"Project-specific roles",
|
|
669
|
+
"Document owners"
|
|
670
|
+
]
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
}ole
|
|
674
|
+
Owner = 'OWNER',
|
|
675
|
+
// ... other roles
|
|
676
|
+
}
|
|
677
|
+
```
|
|
678
|
+
|
|
679
|
+
### 2. Add Role Definition
|
|
680
|
+
|
|
681
|
+
```typescript
|
|
682
|
+
// In accounts-roles.ts
|
|
683
|
+
export const AccountRolesContribution: IConfigurationSchemaMap = {
|
|
684
|
+
// ... existing roles
|
|
685
|
+
|
|
686
|
+
'account.role.auditor': {
|
|
687
|
+
title: 'Auditor',
|
|
688
|
+
value: ApplicationRoles.Auditor,
|
|
689
|
+
default: ApplicationRoles.Auditor,
|
|
690
|
+
scope: ConfigurationScope.APPLICATION,
|
|
691
|
+
description: 'Read-only access to audit logs and system reports',
|
|
692
|
+
},
|
|
693
|
+
};
|
|
694
|
+
```
|
|
695
|
+
|
|
696
|
+
### 3. Define Auditor Permissions
|
|
697
|
+
|
|
698
|
+
```typescript
|
|
699
|
+
// In accounts-permissions.ts
|
|
700
|
+
export const AccountPermissionsContribution: IConfigurationSchemaMap = {
|
|
701
|
+
// ... existing permissions
|
|
702
|
+
|
|
703
|
+
'account.permission.view_audit_logs': {
|
|
704
|
+
title: 'View Audit Logs',
|
|
705
|
+
value: ApplicationPermissions.VIEW_AUDIT_LOGS,
|
|
706
|
+
default: ApplicationPermissions.VIEW_AUDIT_LOGS,
|
|
707
|
+
scope: ConfigurationScope.APPLICATION,
|
|
708
|
+
description: 'Permission to view system audit logs',
|
|
709
|
+
},
|
|
710
|
+
};
|
|
711
|
+
```
|
|
712
|
+
|
|
713
|
+
### 4. Map Permissions to Auditor Role
|
|
714
|
+
|
|
715
|
+
```typescript
|
|
716
|
+
// In accounts-roles-permission-overwrite.ts
|
|
717
|
+
export const AccountRolesPermissionOverwrite = {
|
|
718
|
+
// ... existing role mappings
|
|
719
|
+
|
|
720
|
+
[ApplicationRoles.Auditor]: [
|
|
721
|
+
ApplicationPermissions.VIEW_AUDIT_LOGS,
|
|
722
|
+
ApplicationPermissions.VIEW_REPORTS,
|
|
723
|
+
ApplicationPermissions.VIEW_ORGANIZATIONS,
|
|
724
|
+
// Read-only permissions only
|
|
725
|
+
],
|
|
726
|
+
};
|
|
727
|
+
```
|
|
728
|
+
|
|
729
|
+
## Configuration Scopes
|
|
730
|
+
|
|
731
|
+
### APPLICATION Scope
|
|
732
|
+
- System-wide settings
|
|
733
|
+
- Apply across all organizations
|
|
734
|
+
- Examples: TenantAdmin, User, Guest
|
|
735
|
+
|
|
736
|
+
### WINDOW Scope (Organization)
|
|
737
|
+
- Organization-specific settings
|
|
738
|
+
- Apply within a single organization context
|
|
739
|
+
- Examples: Owner, Admin, Manager, Member
|
|
740
|
+
|
|
741
|
+
### RESOURCE Scope
|
|
742
|
+
- Specific to individual resources
|
|
743
|
+
- Apply to particular entities
|
|
744
|
+
- Examples: Project-specific roles
|
|
745
|
+
|
|
746
|
+
## Best Practices
|
|
747
|
+
|
|
748
|
+
### 1. Role Hierarchy
|
|
749
|
+
```
|
|
750
|
+
TenantAdmin (System Level)
|
|
751
|
+
├── Owner (Organization Level)
|
|
752
|
+
│ ├── Admin (Organization Level)
|
|
753
|
+
│ │ ├── Manager (Organization Level)
|
|
754
|
+
│ │ │ ├── Contributor (Organization Level)
|
|
755
|
+
│ │ │ └── Member (Organization Level)
|
|
756
|
+
│ └── Guest (Public Access)
|
|
757
|
+
└── TeamMaintainer (Team Level)
|
|
758
|
+
└── TeamMember (Team Level)
|
|
759
|
+
```
|
|
760
|
+
|
|
761
|
+
### 2. Permission Inheritance
|
|
762
|
+
- Higher roles should include all permissions of lower roles
|
|
763
|
+
- TenantAdmin should have all system permissions
|
|
764
|
+
- Owner should have all organization permissions
|
|
765
|
+
|
|
766
|
+
### 3. Naming Conventions
|
|
767
|
+
- Use SCREAMING_SNAKE_CASE for enum values
|
|
768
|
+
- Use lowercase with underscores for configuration keys
|
|
769
|
+
- Use descriptive names that indicate the action
|
|
770
|
+
|
|
771
|
+
### 4. Documentation
|
|
772
|
+
- Always include meaningful descriptions
|
|
773
|
+
- Explain the scope and purpose of each role
|
|
774
|
+
- Document permission sets clearly
|
|
775
|
+
|
|
776
|
+
### 5. Testing
|
|
777
|
+
```typescript
|
|
778
|
+
// Test role registration
|
|
779
|
+
describe('Role Configuration', () => {
|
|
780
|
+
it('should register TenantAdmin role', () => {
|
|
781
|
+
const role = AccountRolesContribution['account.role.tenantadmin'];
|
|
782
|
+
expect(role.value).toBe(ApplicationRoles.TenantAdmin);
|
|
783
|
+
expect(role.scope).toBe(ConfigurationScope.APPLICATION);
|
|
784
|
+
});
|
|
785
|
+
});
|
|
786
|
+
|
|
787
|
+
// Test permission mapping
|
|
788
|
+
describe('Permission Overwrite', () => {
|
|
789
|
+
it('should grant full permissions to TenantAdmin', () => {
|
|
790
|
+
const permissions = AccountRolesPermissionOverwrite[ApplicationRoles.TenantAdmin];
|
|
791
|
+
expect(permissions).toContain(ApplicationPermissions.CREATE_ORGANIZATION);
|
|
792
|
+
expect(permissions).toContain(ApplicationPermissions.MANAGE_SYSTEM_SETTINGS);
|
|
793
|
+
});
|
|
794
|
+
});
|
|
795
|
+
```
|
|
796
|
+
|
|
797
|
+
## Migration Process
|
|
798
|
+
|
|
799
|
+
When adding new roles/permissions:
|
|
800
|
+
|
|
801
|
+
1. **Update Enums** - Add to ApplicationRoles/ApplicationPermissions
|
|
802
|
+
2. **Define Configuration** - Add to preference files
|
|
803
|
+
3. **Update Migration ID** - Change migration ID to trigger re-run
|
|
804
|
+
```typescript
|
|
805
|
+
get id() {
|
|
806
|
+
return `${AddAccountsConfigurationsMigration.name}_20260128`; // Update date
|
|
807
|
+
}
|
|
808
|
+
```
|
|
809
|
+
4. **Run Migration** - System will automatically register new configurations
|
|
810
|
+
5. **Clear Cache** - Redis cache will be cleared automatically
|
|
811
|
+
|
|
812
|
+
## Troubleshooting
|
|
813
|
+
|
|
814
|
+
### Role Not Appearing
|
|
815
|
+
- Check enum definition in common/server
|
|
816
|
+
- Verify configuration key naming
|
|
817
|
+
- Ensure migration has been run
|
|
818
|
+
- Check migration ID has been updated
|
|
819
|
+
|
|
820
|
+
### Permissions Not Working
|
|
821
|
+
- Verify permission is listed in permissionsOverride
|
|
822
|
+
- Check role hierarchy
|
|
823
|
+
- Ensure ApplicationPermissions enum is updated
|
|
824
|
+
- Clear Redis cache if needed
|
|
825
|
+
|
|
826
|
+
### Migration Not Running
|
|
827
|
+
- Update migration ID with new timestamp
|
|
828
|
+
- Check database connection
|
|
829
|
+
- Review migration logs
|
|
830
|
+
- Verify BaseConfigurationsMigration inheritance
|
|
831
|
+
|
|
832
|
+
## References
|
|
833
|
+
|
|
834
|
+
- [accounts-roles.ts](./accounts-roles.ts) - Role definitions
|
|
835
|
+
- [accounts-roles-permission-overwrite.ts](./accounts-roles-permission-overwrite.ts) - Permission mappings
|
|
836
|
+
- [AddAccountsConfigurationsMigration.ts](../../migrations/dbMigrations/AddAccountsConfigurationsMigration.ts) - Migration implementation
|
|
837
|
+
- Configuration Registry: `@adminide-stack/core`
|
|
838
|
+
- Common Types: `common/server`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cdmbase/wiki-browser",
|
|
3
|
-
"version": "12.0.18-alpha.
|
|
3
|
+
"version": "12.0.18-alpha.13",
|
|
4
4
|
"description": "Sample core for higher packages to depend on",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "CDMBase LLC",
|
|
@@ -21,13 +21,13 @@
|
|
|
21
21
|
"watch": "yarn build:lib:watch"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@admin-layout/tailwind-ui": "12.2.4-alpha.
|
|
24
|
+
"@admin-layout/tailwind-ui": "12.2.4-alpha.12",
|
|
25
25
|
"@react-icons/all-files": "^4.1.0",
|
|
26
26
|
"marked": "7.0.5",
|
|
27
27
|
"openai": "^4.52.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"common": "12.0.18-alpha.
|
|
30
|
+
"common": "12.0.18-alpha.13"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"@common-stack/client-react": ">0.5.16",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
}
|
|
65
65
|
]
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "81310a170f55f20287cae9207b66af4d7e49376c",
|
|
68
68
|
"typescript": {
|
|
69
69
|
"definition": "lib/index.d.ts"
|
|
70
70
|
}
|