@@ -34,6 +34,7 @@ angular.module('manage').directive('connectionPermissionEditor', ['$injector',
34
34
var connectionGroupService = $injector . get ( 'connectionGroupService' ) ;
35
35
var dataSourceService = $injector . get ( 'dataSourceService' ) ;
36
36
var requestService = $injector . get ( 'requestService' ) ;
37
+ var $log = $injector . get ( '$log' ) ;
37
38
38
39
var directive = {
39
40
@@ -355,17 +356,20 @@ angular.module('manage').directive('connectionPermissionEditor', ['$injector',
355
356
* to reflect the addition of the given connection permission.
356
357
*
357
358
* @param {String } identifier
358
- * The identifier of the connection to add READ permission for.
359
+ * The identifier of the connection to add a permission for.
360
+ *
361
+ * @param {ObjectPermissionType } permission
362
+ * The permission to add.
359
363
*/
360
- var addConnectionPermission = function addConnectionPermission ( identifier ) {
364
+ var addConnectionPermission = function addConnectionPermission ( identifier , permission ) {
361
365
362
366
// If permission was previously removed, simply un-remove it
363
- if ( PermissionSet . hasConnectionPermission ( $scope . permissionsRemoved , PermissionSet . ObjectPermissionType . READ , identifier ) )
364
- PermissionSet . removeConnectionPermission ( $scope . permissionsRemoved , PermissionSet . ObjectPermissionType . READ , identifier ) ;
367
+ if ( PermissionSet . hasConnectionPermission ( $scope . permissionsRemoved , permission , identifier ) )
368
+ PermissionSet . removeConnectionPermission ( $scope . permissionsRemoved , permission , identifier ) ;
365
369
366
370
// Otherwise, explicitly add the permission
367
371
else
368
- PermissionSet . addConnectionPermission ( $scope . permissionsAdded , PermissionSet . ObjectPermissionType . READ , identifier ) ;
372
+ PermissionSet . addConnectionPermission ( $scope . permissionsAdded , permission , identifier ) ;
369
373
370
374
} ;
371
375
@@ -374,17 +378,20 @@ angular.module('manage').directive('connectionPermissionEditor', ['$injector',
374
378
* to reflect the removal of the given connection permission.
375
379
*
376
380
* @param {String } identifier
377
- * The identifier of the connection to remove READ permission for.
381
+ * The identifier of the connection to remove a permission for.
382
+ *
383
+ * @param {ObjectPermissionType } permission
384
+ * The permission to remove.
378
385
*/
379
- var removeConnectionPermission = function removeConnectionPermission ( identifier ) {
386
+ var removeConnectionPermission = function removeConnectionPermission ( identifier , permission ) {
380
387
381
388
// If permission was previously added, simply un-add it
382
- if ( PermissionSet . hasConnectionPermission ( $scope . permissionsAdded , PermissionSet . ObjectPermissionType . READ , identifier ) )
383
- PermissionSet . removeConnectionPermission ( $scope . permissionsAdded , PermissionSet . ObjectPermissionType . READ , identifier ) ;
389
+ if ( PermissionSet . hasConnectionPermission ( $scope . permissionsAdded , permission , identifier ) )
390
+ PermissionSet . removeConnectionPermission ( $scope . permissionsAdded , permission , identifier ) ;
384
391
385
392
// Otherwise, explicitly remove the permission
386
393
else
387
- PermissionSet . addConnectionPermission ( $scope . permissionsRemoved , PermissionSet . ObjectPermissionType . READ , identifier ) ;
394
+ PermissionSet . addConnectionPermission ( $scope . permissionsRemoved , permission , identifier ) ;
388
395
389
396
} ;
390
397
@@ -393,18 +400,20 @@ angular.module('manage').directive('connectionPermissionEditor', ['$injector',
393
400
* to reflect the addition of the given connection group permission.
394
401
*
395
402
* @param {String } identifier
396
- * The identifier of the connection group to add READ permission
397
- * for.
403
+ * The identifier of the connection group to add a permission for.
404
+ *
405
+ * @param {ObjectPermissionType } permission
406
+ * The permission to add.
398
407
*/
399
- var addConnectionGroupPermission = function addConnectionGroupPermission ( identifier ) {
408
+ var addConnectionGroupPermission = function addConnectionGroupPermission ( identifier , permission ) {
400
409
401
410
// If permission was previously removed, simply un-remove it
402
- if ( PermissionSet . hasConnectionGroupPermission ( $scope . permissionsRemoved , PermissionSet . ObjectPermissionType . READ , identifier ) )
403
- PermissionSet . removeConnectionGroupPermission ( $scope . permissionsRemoved , PermissionSet . ObjectPermissionType . READ , identifier ) ;
411
+ if ( PermissionSet . hasConnectionGroupPermission ( $scope . permissionsRemoved , permission , identifier ) )
412
+ PermissionSet . removeConnectionGroupPermission ( $scope . permissionsRemoved , permission , identifier ) ;
404
413
405
414
// Otherwise, explicitly add the permission
406
415
else
407
- PermissionSet . addConnectionGroupPermission ( $scope . permissionsAdded , PermissionSet . ObjectPermissionType . READ , identifier ) ;
416
+ PermissionSet . addConnectionGroupPermission ( $scope . permissionsAdded , permission , identifier ) ;
408
417
409
418
} ;
410
419
@@ -413,18 +422,20 @@ angular.module('manage').directive('connectionPermissionEditor', ['$injector',
413
422
* to reflect the removal of the given connection group permission.
414
423
*
415
424
* @param {String } identifier
416
- * The identifier of the connection group to remove READ permission
417
- * for.
425
+ * The identifier of the connection group to remove a permission for.
426
+ *
427
+ * @param {ObjectPermissionType } permission
428
+ * The permission to remove.
418
429
*/
419
- var removeConnectionGroupPermission = function removeConnectionGroupPermission ( identifier ) {
430
+ var removeConnectionGroupPermission = function removeConnectionGroupPermission ( identifier , permission ) {
420
431
421
432
// If permission was previously added, simply un-add it
422
- if ( PermissionSet . hasConnectionGroupPermission ( $scope . permissionsAdded , PermissionSet . ObjectPermissionType . READ , identifier ) )
423
- PermissionSet . removeConnectionGroupPermission ( $scope . permissionsAdded , PermissionSet . ObjectPermissionType . READ , identifier ) ;
433
+ if ( PermissionSet . hasConnectionGroupPermission ( $scope . permissionsAdded , permission , identifier ) )
434
+ PermissionSet . removeConnectionGroupPermission ( $scope . permissionsAdded , permission , identifier ) ;
424
435
425
436
// Otherwise, explicitly remove the permission
426
437
else
427
- PermissionSet . addConnectionGroupPermission ( $scope . permissionsRemoved , PermissionSet . ObjectPermissionType . READ , identifier ) ;
438
+ PermissionSet . addConnectionGroupPermission ( $scope . permissionsRemoved , permission , identifier ) ;
428
439
429
440
} ;
430
441
@@ -433,17 +444,20 @@ angular.module('manage').directive('connectionPermissionEditor', ['$injector',
433
444
* to reflect the addition of the given sharing profile permission.
434
445
*
435
446
* @param {String } identifier
436
- * The identifier of the sharing profile to add READ permission for.
447
+ * The identifier of the sharing profile to add a permission for.
448
+ *
449
+ * @param {ObjectPermissionType } permission
450
+ * The permission to add.
437
451
*/
438
- var addSharingProfilePermission = function addSharingProfilePermission ( identifier ) {
452
+ var addSharingProfilePermission = function addSharingProfilePermission ( identifier , permission ) {
439
453
440
454
// If permission was previously removed, simply un-remove it
441
- if ( PermissionSet . hasSharingProfilePermission ( $scope . permissionsRemoved , PermissionSet . ObjectPermissionType . READ , identifier ) )
442
- PermissionSet . removeSharingProfilePermission ( $scope . permissionsRemoved , PermissionSet . ObjectPermissionType . READ , identifier ) ;
455
+ if ( PermissionSet . hasSharingProfilePermission ( $scope . permissionsRemoved , permission , identifier ) )
456
+ PermissionSet . removeSharingProfilePermission ( $scope . permissionsRemoved , permission , identifier ) ;
443
457
444
458
// Otherwise, explicitly add the permission
445
459
else
446
- PermissionSet . addSharingProfilePermission ( $scope . permissionsAdded , PermissionSet . ObjectPermissionType . READ , identifier ) ;
460
+ PermissionSet . addSharingProfilePermission ( $scope . permissionsAdded , permission , identifier ) ;
447
461
448
462
} ;
449
463
@@ -452,18 +466,20 @@ angular.module('manage').directive('connectionPermissionEditor', ['$injector',
452
466
* to reflect the removal of the given sharing profile permission.
453
467
*
454
468
* @param {String } identifier
455
- * The identifier of the sharing profile to remove READ permission
456
- * for.
469
+ * The identifier of the sharing profile to remove a permission for.
470
+ *
471
+ * @param {ObjectPermissionType } permission
472
+ * The permission to remove.
457
473
*/
458
- var removeSharingProfilePermission = function removeSharingProfilePermission ( identifier ) {
474
+ var removeSharingProfilePermission = function removeSharingProfilePermission ( identifier , permission ) {
459
475
460
476
// If permission was previously added, simply un-add it
461
- if ( PermissionSet . hasSharingProfilePermission ( $scope . permissionsAdded , PermissionSet . ObjectPermissionType . READ , identifier ) )
462
- PermissionSet . removeSharingProfilePermission ( $scope . permissionsAdded , PermissionSet . ObjectPermissionType . READ , identifier ) ;
477
+ if ( PermissionSet . hasSharingProfilePermission ( $scope . permissionsAdded , permission , identifier ) )
478
+ PermissionSet . removeSharingProfilePermission ( $scope . permissionsAdded , permission , identifier ) ;
463
479
464
480
// Otherwise, explicitly remove the permission
465
481
else
466
- PermissionSet . addSharingProfilePermission ( $scope . permissionsRemoved , PermissionSet . ObjectPermissionType . READ , identifier ) ;
482
+ PermissionSet . addSharingProfilePermission ( $scope . permissionsRemoved , permission , identifier ) ;
467
483
468
484
} ;
469
485
@@ -493,14 +509,14 @@ angular.module('manage').directive('connectionPermissionEditor', ['$injector',
493
509
*/
494
510
connectionPermissionChanged : function connectionPermissionChanged ( identifier ) {
495
511
496
- // Determine current permission setting
497
- var granted = $scope . permissionFlags . connectionPermissions . READ [ identifier ] ;
512
+ // Loop through permissions to add or remove them as required.
513
+ for ( const [ key , value ] of Object . entries ( $scope . permissionFlags . connectionPermissions ) ) {
514
+ if ( value [ identifier ] )
515
+ addConnectionPermission ( identifier , PermissionSet . ObjectPermissionType [ key ] ) ;
516
+ else
517
+ removeConnectionPermission ( identifier , PermissionSet . ObjectPermissionType [ key ] ) ;
498
518
499
- // Add/remove permission depending on flag state
500
- if ( granted )
501
- addConnectionPermission ( identifier ) ;
502
- else
503
- removeConnectionPermission ( identifier ) ;
519
+ }
504
520
505
521
} ,
506
522
@@ -515,14 +531,14 @@ angular.module('manage').directive('connectionPermissionEditor', ['$injector',
515
531
*/
516
532
connectionGroupPermissionChanged : function connectionGroupPermissionChanged ( identifier ) {
517
533
518
- // Determine current permission setting
519
- var granted = $scope . permissionFlags . connectionGroupPermissions . READ [ identifier ] ;
534
+ // Loop through permissions and add or remove them as required.
535
+ for ( const [ key , value ] of Object . entries ( $scope . permissionFlags . connectionGroupPermissions ) ) {
536
+ if ( value [ identifier ] )
537
+ addConnectionGroupPermission ( identifier , PermissionSet . ObjectPermissionType [ key ] ) ;
538
+ else
539
+ removeConnectionGroupPermission ( identifier , PermissionSet . ObjectPermissionType [ key ] ) ;
520
540
521
- // Add/remove permission depending on flag state
522
- if ( granted )
523
- addConnectionGroupPermission ( identifier ) ;
524
- else
525
- removeConnectionGroupPermission ( identifier ) ;
541
+ }
526
542
527
543
} ,
528
544
@@ -537,14 +553,14 @@ angular.module('manage').directive('connectionPermissionEditor', ['$injector',
537
553
*/
538
554
sharingProfilePermissionChanged : function sharingProfilePermissionChanged ( identifier ) {
539
555
540
- // Determine current permission setting
541
- var granted = $scope . permissionFlags . sharingProfilePermissions . READ [ identifier ] ;
556
+ // Loop through permissions and add or remove them as required.
557
+ for ( const [ key , value ] of Object . entries ( $scope . permissionFlags . sharingProfilePermissions ) ) {
558
+ if ( value [ identifier ] )
559
+ addSharingProfilePermission ( identifier , PermissionSet . ObjectPermissionType [ key ] ) ;
560
+ else
561
+ removeSharingProfilePermission ( identifier , PermissionSet . ObjectPermissionType [ key ] ) ;
542
562
543
- // Add/remove permission depending on flag state
544
- if ( granted )
545
- addSharingProfilePermission ( identifier ) ;
546
- else
547
- removeSharingProfilePermission ( identifier ) ;
563
+ }
548
564
549
565
}
550
566
0 commit comments