Skip to content

Commit 4751e53

Browse files
committed
DTSCCI-4116: Add auths to doc
1 parent ceee71f commit 4751e53

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

bin/utils/generate-state-event-model.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const path = require('path');
66
const ROOT = path.resolve(__dirname, '..', '..');
77
const STATE_FILE = path.join(ROOT, 'ccd-definition', 'State.json');
88
const CASE_EVENT_DIR = path.join(ROOT, 'ccd-definition', 'CaseEvent');
9+
const AUTH_DIR = path.join(ROOT, 'ccd-definition', 'AuthorisationCaseEvent');
910

1011
const SOURCE_DIRS = fs.readdirSync(CASE_EVENT_DIR)
1112
.filter(d => fs.statSync(path.join(CASE_EVENT_DIR, d)).isDirectory())
@@ -89,6 +90,36 @@ function readEventFiles() {
8990
return events;
9091
}
9192

93+
function parseAuthorisations() {
94+
const roleMap = {};
95+
const files = fs.readdirSync(AUTH_DIR).filter(f => f.endsWith('.json'));
96+
for (const file of files) {
97+
let content;
98+
try {
99+
content = JSON.parse(fs.readFileSync(path.join(AUTH_DIR, file), 'utf8'));
100+
} catch (_) {
101+
continue;
102+
}
103+
const items = Array.isArray(content) ? content : [content];
104+
for (const item of items) {
105+
const eventId = item.CaseEventID;
106+
if (!eventId) continue;
107+
if (!roleMap[eventId]) roleMap[eventId] = new Set();
108+
109+
if (item.AccessControl) {
110+
for (const ac of item.AccessControl) {
111+
if (ac.CRUD && ac.CRUD.includes('C')) {
112+
for (const role of ac.UserRoles) roleMap[eventId].add(role);
113+
}
114+
}
115+
} else if (item.UserRole && item.CRUD && item.CRUD.includes('C')) {
116+
roleMap[eventId].add(item.UserRole);
117+
}
118+
}
119+
}
120+
return roleMap;
121+
}
122+
92123
function computeEdges(events) {
93124
const edges = [];
94125

@@ -134,6 +165,11 @@ function main() {
134165

135166
const states = parseStates();
136167
const events = readEventFiles();
168+
const authMap = parseAuthorisations();
169+
for (const ev of events) {
170+
const roles = authMap[ev.id];
171+
ev.createRoles = roles ? [...roles].sort() : [];
172+
}
137173
const edges = computeEdges(events);
138174
const summary = computeSummary(states, events, edges);
139175

bin/utils/generate-state-event-svg.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,11 @@ function renderColumn(stateId, x, y) {
351351
// Pill background + event name (with suffix for duplicates)
352352
const displayName = displayNames.get(ev.id) || ev.name;
353353
const notifTarget = getNotifLink(ev.id);
354-
svg += `<rect x="${pillX}" y="${py}" width="${PILL_W}" height="${PILL_H}" rx="${PILL_R}" fill="${bg}" stroke="#bbb" stroke-width="0.5"/>`;
354+
const roles = ev.createRoles || [];
355+
const hasRoleTip = ev.sourceType === 'user' && roles.length > 0;
356+
svg += `<rect x="${pillX}" y="${py}" width="${PILL_W}" height="${PILL_H}" rx="${PILL_R}" fill="${bg}" stroke="#bbb" stroke-width="0.5">`;
357+
if (hasRoleTip) svg += `<title>Create: ${esc(roles.join(', '))}</title>`;
358+
svg += `</rect>`;
355359
svg += `<text x="${pillX+8}" y="${py+PILL_H/2+3}" font-size="${FONT}" fill="#333" font-family="Arial">${esc(displayName)}</text>`;
356360

357361
// Notification link icon (envelope)
@@ -448,7 +452,10 @@ let ccPillY = ccY + HDR_H + PILL_GAP;
448452
for (const ev of creationEvents) {
449453
const bg = pillBg(ev);
450454
const ccName = ccDisplayNames.get(ev.id) || ev.name;
451-
ccSvg += `<rect x="${ccPillX}" y="${ccPillY}" width="${PILL_W}" height="${PILL_H}" rx="${PILL_R}" fill="${bg}" stroke="#bbb" stroke-width="0.5"/>`;
455+
const ccRoles = ev.createRoles || [];
456+
ccSvg += `<rect x="${ccPillX}" y="${ccPillY}" width="${PILL_W}" height="${PILL_H}" rx="${PILL_R}" fill="${bg}" stroke="#bbb" stroke-width="0.5">`;
457+
if (ccRoles.length > 0) ccSvg += `<title>Create: ${esc(ccRoles.join(', '))}</title>`;
458+
ccSvg += `</rect>`;
452459
ccSvg += `<text x="${ccPillX+8}" y="${ccPillY+PILL_H/2+3}" font-size="${FONT}" fill="#333" font-family="Arial">${esc(ccName)}</text>`;
453460
ccPillY += PILL_H + PILL_GAP;
454461
}
@@ -511,7 +518,10 @@ let guPillY = guY + HDR_H + PILL_GAP;
511518
for (const ev of globalUserEvents) {
512519
const bg = pillBg(ev);
513520
const guName = guDisplayNames.get(ev.id) || ev.name;
514-
guSvg += `<rect x="${guPillX}" y="${guPillY}" width="${PILL_W}" height="${PILL_H}" rx="${PILL_R}" fill="${bg}" stroke="#bbb" stroke-width="0.5"/>`;
521+
const guRoles = ev.createRoles || [];
522+
guSvg += `<rect x="${guPillX}" y="${guPillY}" width="${PILL_W}" height="${PILL_H}" rx="${PILL_R}" fill="${bg}" stroke="#bbb" stroke-width="0.5">`;
523+
if (guRoles.length > 0) guSvg += `<title>Create: ${esc(guRoles.join(', '))}</title>`;
524+
guSvg += `</rect>`;
515525
guSvg += `<text x="${guPillX+8}" y="${guPillY+PILL_H/2+3}" font-size="${FONT}" fill="#333" font-family="Arial">${esc(guName)}</text>`;
516526
const guNotifTarget = getNotifLink(ev.id);
517527
if (guNotifTarget) {

0 commit comments

Comments
 (0)