@@ -6,6 +6,7 @@ const path = require('path');
66const ROOT = path . resolve ( __dirname , '..' , '..' ) ;
77const STATE_FILE = path . join ( ROOT , 'ccd-definition' , 'State.json' ) ;
88const CASE_EVENT_DIR = path . join ( ROOT , 'ccd-definition' , 'CaseEvent' ) ;
9+ const AUTH_DIR = path . join ( ROOT , 'ccd-definition' , 'AuthorisationCaseEvent' ) ;
910
1011const 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+
92123function 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
0 commit comments