@@ -23,8 +23,8 @@ const COLLABORATION_TYPE_TO_ENTITY_TYPE_MAP: Partial<
23
23
[ COLLABORATION_TYPES . user ] : "user" ,
24
24
[ COLLABORATION_TYPES . group ] : "group" ,
25
25
[ COLLABORATION_TYPES . groupAdmin ] : "group" ,
26
- [ COLLABORATION_TYPES . org ] : "org " ,
27
- [ COLLABORATION_TYPES . orgAdmin ] : "org " ,
26
+ [ COLLABORATION_TYPES . org ] : "organization " ,
27
+ [ COLLABORATION_TYPES . orgAdmin ] : "organization " ,
28
28
} ;
29
29
30
30
const COLLABORATION_TYPE_TO_ROLE_MAP : Partial <
@@ -246,28 +246,51 @@ export const transformEntityPermissionPoliciesToUserFormValues = (
246
246
* Transforms an array of IEntityPermissionPolicy (Hub entity) objects to a IHubRoleConfigValue (entity editor) object
247
247
* representing the channel's owner permissions
248
248
* @param permissionPolicies An array of IEntityPermissionPolicy objects
249
+ * @param defaultOrgId The current user's orgId
249
250
* @returns an IHubRoleConfigValue object
250
251
*/
251
- export const transformEntityPermissionPoliciesToOwnerFormValue = (
252
- permissionPolicies : IEntityPermissionPolicy [ ]
253
- ) : IHubRoleConfigValue => {
254
- const ownerPermission = permissionPolicies . find (
255
- ( { permission } ) => permission === CHANNEL_PERMISSIONS . channelOwner
256
- ) ;
257
- return ownerPermission
258
- ? {
259
- key : ownerPermission . collaborationId ,
260
- entityId : ownerPermission . collaborationId ,
261
- entityType :
262
- COLLABORATION_TYPE_TO_ENTITY_TYPE_MAP [
263
- ownerPermission . collaborationType
264
- ] ,
265
- roles : {
266
- [ COLLABORATION_TYPE_TO_ROLE_MAP [ ownerPermission . collaborationType ] ] : {
267
- value : ownerPermission . permission ,
268
- id : ownerPermission . id ,
252
+ export const transformEntityPermissionPoliciesToOwnerFormValues = (
253
+ permissionPolicies : IEntityPermissionPolicy [ ] ,
254
+ defaultOrgId : string
255
+ ) : IHubRoleConfigValue [ ] => {
256
+ const ownerConfigs : IHubRoleConfigValue [ ] = permissionPolicies . reduce <
257
+ IHubRoleConfigValue [ ]
258
+ > ( ( acc , permissionPolicy ) => {
259
+ if ( permissionPolicy . permission === CHANNEL_PERMISSIONS . channelOwner ) {
260
+ return [
261
+ ...acc ,
262
+ {
263
+ key : permissionPolicy . collaborationId ,
264
+ entityId : permissionPolicy . collaborationId ,
265
+ entityType :
266
+ COLLABORATION_TYPE_TO_ENTITY_TYPE_MAP [
267
+ permissionPolicy . collaborationType
268
+ ] ,
269
+ roles : {
270
+ [ COLLABORATION_TYPE_TO_ROLE_MAP [
271
+ permissionPolicy . collaborationType
272
+ ] ] : {
273
+ value : permissionPolicy . permission ,
274
+ id : permissionPolicy . id ,
275
+ } ,
269
276
} ,
270
277
} ,
271
- }
272
- : null ;
278
+ ] ;
279
+ }
280
+ return acc ;
281
+ } , [ ] ) ;
282
+ if ( ! ownerConfigs . length ) {
283
+ ownerConfigs . push ( {
284
+ key : defaultOrgId ,
285
+ entityId : defaultOrgId ,
286
+ entityType : COLLABORATION_TYPE_TO_ENTITY_TYPE_MAP [ "org-admin" ] ,
287
+ roles : {
288
+ [ COLLABORATION_TYPE_TO_ROLE_MAP [ "org-admin" ] ] : {
289
+ value : CHANNEL_PERMISSIONS . channelOwner ,
290
+ id : undefined ,
291
+ } ,
292
+ } ,
293
+ } ) ;
294
+ }
295
+ return ownerConfigs ;
273
296
} ;
0 commit comments