@@ -62,9 +62,11 @@ export async function syncGitHubAppsData(openApiSource, sourceSchemas, progAcces
62
62
}
63
63
64
64
// permissions
65
- for ( const [ permissionName , readOrWrite ] of Object . entries (
66
- progAccessData [ operation . operationId ] . permissions ,
67
- ) ) {
65
+ const allPermissions = {
66
+ ...progAccessData [ operation . operationId ] . permissions . and ,
67
+ ...progAccessData [ operation . operationId ] . permissions . or ,
68
+ }
69
+ for ( const [ permissionName , readOrWrite ] of Object . entries ( allPermissions ) ) {
68
70
const tempTitle = permissionName . replace ( / _ / g, ' ' )
69
71
const permissionNameExists = progActorResources [ permissionName ]
70
72
if ( ! permissionNameExists ) {
@@ -76,9 +78,8 @@ export async function syncGitHubAppsData(openApiSource, sourceSchemas, progAcces
76
78
const resourceGroup = progActorResources [ permissionName ] ?. resource_group || ''
77
79
const displayTitle = getDisplayTitle ( title , resourceGroup )
78
80
const relatedPermissionNames = Object . keys (
79
- progAccessData [ operation . operationId ] . permissions ,
81
+ progAccessData [ operation . operationId ] . permissions . and ,
80
82
) . filter ( ( permission ) => permission !== permissionName )
81
-
82
83
// github app permissions
83
84
const serverToServerPermissions = githubAppsData [ 'server-to-server-permissions' ]
84
85
if ( ! serverToServerPermissions [ permissionName ] ) {
@@ -182,11 +183,41 @@ async function getProgAccessData(progAccessSource) {
182
183
183
184
const progAccessData = { }
184
185
for ( const operation of progAccessDataRaw ) {
185
- const permissions = { }
186
+ const permissions = { or : { } , and : { } }
186
187
if ( operation . permission_sets ) {
187
- operation . permission_sets . forEach ( ( permissionSet ) => {
188
- Object . assign ( permissions , permissionSet )
189
- } )
188
+ // Currently there is only a length of up to 2 permission_sets
189
+ // OR permission_sets are dashed lists in yaml
190
+ // e.g.
191
+ // permission_sets:
192
+ // - admin: write
193
+ // - contents: read
194
+ // This becomes: [{admin: write}, {contents: read}] with yaml.load
195
+ if ( operation . permission_sets . length === 2 ) {
196
+ // There's currently only one scenario where you have an OR permission_set where one of the OR permissions is an AND permission_set
197
+ // In this scenario, we want the AND permission_set
198
+ if (
199
+ Object . keys ( operation . permission_sets [ 0 ] ) . length > 1 ||
200
+ Object . keys ( operation . permission_sets [ 1 ] ) . length > 1
201
+ ) {
202
+ const andPermissionSet =
203
+ Object . keys ( operation . permission_sets [ 0 ] ) . length > 1
204
+ ? operation . permission_sets [ 0 ]
205
+ : operation . permission_sets [ 1 ]
206
+ Object . assign ( permissions . and , andPermissionSet )
207
+ } else {
208
+ operation . permission_sets . forEach ( ( permissionSet ) => {
209
+ Object . assign ( permissions . or , permissionSet )
210
+ } )
211
+ }
212
+ // AND permission_sets are under the same dash in yaml
213
+ // e.g.
214
+ // permission_sets:
215
+ // - admin: write
216
+ // contents: read
217
+ // This becomes: [{admin: write, contents: read}] with yaml.load
218
+ } else if ( operation . permission_sets . length === 1 ) {
219
+ Object . assign ( permissions . and , operation . permission_sets [ 0 ] )
220
+ }
190
221
}
191
222
192
223
const userToServerRest = operation . user_to_server . enabled
0 commit comments