Skip to content

Commit 94b691b

Browse files
committed
GUACAMOLE-1957: Support granular permissions management.
1 parent 9a8a5f3 commit 94b691b

File tree

6 files changed

+271
-66
lines changed

6 files changed

+271
-66
lines changed

guacamole/src/main/frontend/src/app/manage/directives/connectionPermissionEditor.js

Lines changed: 70 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ angular.module('manage').directive('connectionPermissionEditor', ['$injector',
3434
var connectionGroupService = $injector.get('connectionGroupService');
3535
var dataSourceService = $injector.get('dataSourceService');
3636
var requestService = $injector.get('requestService');
37+
var $log = $injector.get('$log');
3738

3839
var directive = {
3940

@@ -355,17 +356,20 @@ angular.module('manage').directive('connectionPermissionEditor', ['$injector',
355356
* to reflect the addition of the given connection permission.
356357
*
357358
* @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.
359363
*/
360-
var addConnectionPermission = function addConnectionPermission(identifier) {
364+
var addConnectionPermission = function addConnectionPermission(identifier, permission) {
361365

362366
// 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);
365369

366370
// Otherwise, explicitly add the permission
367371
else
368-
PermissionSet.addConnectionPermission($scope.permissionsAdded, PermissionSet.ObjectPermissionType.READ, identifier);
372+
PermissionSet.addConnectionPermission($scope.permissionsAdded, permission, identifier);
369373

370374
};
371375

@@ -374,17 +378,20 @@ angular.module('manage').directive('connectionPermissionEditor', ['$injector',
374378
* to reflect the removal of the given connection permission.
375379
*
376380
* @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.
378385
*/
379-
var removeConnectionPermission = function removeConnectionPermission(identifier) {
386+
var removeConnectionPermission = function removeConnectionPermission(identifier, permission) {
380387

381388
// 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);
384391

385392
// Otherwise, explicitly remove the permission
386393
else
387-
PermissionSet.addConnectionPermission($scope.permissionsRemoved, PermissionSet.ObjectPermissionType.READ, identifier);
394+
PermissionSet.addConnectionPermission($scope.permissionsRemoved, permission, identifier);
388395

389396
};
390397

@@ -393,18 +400,20 @@ angular.module('manage').directive('connectionPermissionEditor', ['$injector',
393400
* to reflect the addition of the given connection group permission.
394401
*
395402
* @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.
398407
*/
399-
var addConnectionGroupPermission = function addConnectionGroupPermission(identifier) {
408+
var addConnectionGroupPermission = function addConnectionGroupPermission(identifier, permission) {
400409

401410
// 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);
404413

405414
// Otherwise, explicitly add the permission
406415
else
407-
PermissionSet.addConnectionGroupPermission($scope.permissionsAdded, PermissionSet.ObjectPermissionType.READ, identifier);
416+
PermissionSet.addConnectionGroupPermission($scope.permissionsAdded, permission, identifier);
408417

409418
};
410419

@@ -413,18 +422,20 @@ angular.module('manage').directive('connectionPermissionEditor', ['$injector',
413422
* to reflect the removal of the given connection group permission.
414423
*
415424
* @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.
418429
*/
419-
var removeConnectionGroupPermission = function removeConnectionGroupPermission(identifier) {
430+
var removeConnectionGroupPermission = function removeConnectionGroupPermission(identifier, permission) {
420431

421432
// 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);
424435

425436
// Otherwise, explicitly remove the permission
426437
else
427-
PermissionSet.addConnectionGroupPermission($scope.permissionsRemoved, PermissionSet.ObjectPermissionType.READ, identifier);
438+
PermissionSet.addConnectionGroupPermission($scope.permissionsRemoved, permission, identifier);
428439

429440
};
430441

@@ -433,17 +444,20 @@ angular.module('manage').directive('connectionPermissionEditor', ['$injector',
433444
* to reflect the addition of the given sharing profile permission.
434445
*
435446
* @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.
437451
*/
438-
var addSharingProfilePermission = function addSharingProfilePermission(identifier) {
452+
var addSharingProfilePermission = function addSharingProfilePermission(identifier, permission) {
439453

440454
// 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);
443457

444458
// Otherwise, explicitly add the permission
445459
else
446-
PermissionSet.addSharingProfilePermission($scope.permissionsAdded, PermissionSet.ObjectPermissionType.READ, identifier);
460+
PermissionSet.addSharingProfilePermission($scope.permissionsAdded, permission, identifier);
447461

448462
};
449463

@@ -452,18 +466,20 @@ angular.module('manage').directive('connectionPermissionEditor', ['$injector',
452466
* to reflect the removal of the given sharing profile permission.
453467
*
454468
* @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.
457473
*/
458-
var removeSharingProfilePermission = function removeSharingProfilePermission(identifier) {
474+
var removeSharingProfilePermission = function removeSharingProfilePermission(identifier, permission) {
459475

460476
// 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);
463479

464480
// Otherwise, explicitly remove the permission
465481
else
466-
PermissionSet.addSharingProfilePermission($scope.permissionsRemoved, PermissionSet.ObjectPermissionType.READ, identifier);
482+
PermissionSet.addSharingProfilePermission($scope.permissionsRemoved, permission, identifier);
467483

468484
};
469485

@@ -493,14 +509,14 @@ angular.module('manage').directive('connectionPermissionEditor', ['$injector',
493509
*/
494510
connectionPermissionChanged : function connectionPermissionChanged(identifier) {
495511

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]);
498518

499-
// Add/remove permission depending on flag state
500-
if (granted)
501-
addConnectionPermission(identifier);
502-
else
503-
removeConnectionPermission(identifier);
519+
}
504520

505521
},
506522

@@ -515,14 +531,14 @@ angular.module('manage').directive('connectionPermissionEditor', ['$injector',
515531
*/
516532
connectionGroupPermissionChanged : function connectionGroupPermissionChanged(identifier) {
517533

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]);
520540

521-
// Add/remove permission depending on flag state
522-
if (granted)
523-
addConnectionGroupPermission(identifier);
524-
else
525-
removeConnectionGroupPermission(identifier);
541+
}
526542

527543
},
528544

@@ -537,14 +553,14 @@ angular.module('manage').directive('connectionPermissionEditor', ['$injector',
537553
*/
538554
sharingProfilePermissionChanged : function sharingProfilePermissionChanged(identifier) {
539555

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]);
542562

543-
// Add/remove permission depending on flag state
544-
if (granted)
545-
addSharingProfilePermission(identifier);
546-
else
547-
removeSharingProfilePermission(identifier);
563+
}
548564

549565
}
550566

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
/* Draw the box for the toggle button. */
21+
label.permission-toggle {
22+
position: relative;
23+
display: inline-grid;
24+
width: fit-content;
25+
border: 1px solid rgba(0, 0, 0, .125);
26+
font-weight: 300;
27+
cursor: pointer;
28+
}
29+
30+
/* Padding around the label. */
31+
label.permission-toggle div {
32+
padding: 6px;
33+
text-align: center;
34+
z-index: 1;
35+
}
36+
37+
/* Hide the actual checkbox */
38+
input.permission-toggle {
39+
display: none;
40+
}
41+
42+
/* Style of the checked toggle. */
43+
input.permission-toggle:checked + label.permission-toggle div:first-child {
44+
color: #ffffff;
45+
transition: color 0.3s;
46+
background: #5a5a5a;
47+
font-size: 0.90em;
48+
font-weight: 700;
49+
}
50+
51+
/* Style of the unchecked toggle. */
52+
input.permission-toggle + label.permission-toggle div:first-child {
53+
color: rgba(0, 0, 0, .125);
54+
transition: color 0.3s;
55+
font-size: 0.90em;
56+
font-weight: 700;
57+
}
58+
59+
.permission-container {
60+
display: inline-block;
61+
}

guacamole/src/main/frontend/src/app/manage/templates/connectionGroupPermission.html

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,50 @@
33
<!-- Connection group icon -->
44
<div class="icon type"></div>
55

6-
<!-- Permission checkbox -->
7-
<input type="checkbox" ng-model="context.getPermissionFlags().connectionGroupPermissions.READ[item.identifier]"
8-
ng-change="context.connectionGroupPermissionChanged(item.identifier)">
9-
106
<!-- Connection group name -->
117
<span class="name">{{item.name}}</span>
8+
9+
<div class="permission-container">
10+
11+
<!-- Connection Group Read (Connect) Permission -->
12+
<input type="checkbox"
13+
id="readConnectionGroup-{{item.identifier}}"
14+
class="permission-toggle"
15+
ng-model="context.getPermissionFlags().connectionGroupPermissions.READ[item.identifier]"
16+
ng-change="context.connectionGroupPermissionChanged(item.identifier)">
17+
<label for="readConnectionGroup-{{item.identifier}}" class="permission-toggle label">
18+
<div>{{'PERMISSIONS.TOGGLE_PERMISSION_CONNECT' | translate}}</div>
19+
</label>
20+
21+
<!-- Connection Group Update Permission -->
22+
<input type="checkbox"
23+
id="updateConnectionGroup-{{item.identifier}}"
24+
class="permission-toggle"
25+
ng-model="context.getPermissionFlags().connectionGroupPermissions.UPDATE[item.identifier]"
26+
ng-change="context.connectionGroupPermissionChanged(item.identifier)">
27+
<label for="updateConnectionGroup-{{item.identifier}}" class="permission-toggle label">
28+
<div>{{'PERMISSIONS.TOGGLE_PERMISSION_UPDATE' | translate}}</div>
29+
</label>
30+
31+
<!-- Connection Group Delete Permission -->
32+
<input type="checkbox"
33+
id="deleteConnectionGroup-{{item.identifier}}"
34+
class="permission-toggle"
35+
ng-model="context.getPermissionFlags().connectionGroupPermissions.DELETE[item.identifier]"
36+
ng-change="context.connectionGroupPermissionChanged(item.identifier)">
37+
<label for="deleteConnectionGroup-{{item.identifier}}" class="permission-toggle label">
38+
<div>{{'PERMISSIONS.TOGGLE_PERMISSION_DELETE' | translate}}</div>
39+
</label>
1240

41+
<!-- Connection Group Administer Permission -->
42+
<input type="checkbox"
43+
id="adminConnectionGroup-{{item.identifier}}"
44+
class="permission-toggle"
45+
ng-model="context.getPermissionFlags().connectionGroupPermissions.ADMINISTER[item.identifier]"
46+
ng-change="context.connectionGroupPermissionChanged(item.identifier)">
47+
<label for="adminConnectionGroup-{{item.identifier}}" class="permission-toggle label">
48+
<div>{{'PERMISSIONS.TOGGLE_PERMISSION_ADMINISTER' | translate}}</div>
49+
</label>
50+
51+
</div>
1352
</div>

0 commit comments

Comments
 (0)