mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 05:31:22 +00:00
GUACAMOLE-220: Move data source tabs to separate directive.
This commit is contained in:
@@ -26,7 +26,6 @@ angular.module('manage').controller('manageUserController', ['$scope', '$injecto
|
|||||||
// Required types
|
// Required types
|
||||||
var Error = $injector.get('Error');
|
var Error = $injector.get('Error');
|
||||||
var ManagementPermissions = $injector.get('ManagementPermissions');
|
var ManagementPermissions = $injector.get('ManagementPermissions');
|
||||||
var PageDefinition = $injector.get('PageDefinition');
|
|
||||||
var PermissionFlagSet = $injector.get('PermissionFlagSet');
|
var PermissionFlagSet = $injector.get('PermissionFlagSet');
|
||||||
var PermissionSet = $injector.get('PermissionSet');
|
var PermissionSet = $injector.get('PermissionSet');
|
||||||
var User = $injector.get('User');
|
var User = $injector.get('User');
|
||||||
@@ -40,7 +39,6 @@ angular.module('manage').controller('manageUserController', ['$scope', '$injecto
|
|||||||
var permissionService = $injector.get('permissionService');
|
var permissionService = $injector.get('permissionService');
|
||||||
var requestService = $injector.get('requestService');
|
var requestService = $injector.get('requestService');
|
||||||
var schemaService = $injector.get('schemaService');
|
var schemaService = $injector.get('schemaService');
|
||||||
var translationStringService = $injector.get('translationStringService');
|
|
||||||
var userService = $injector.get('userService');
|
var userService = $injector.get('userService');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -136,11 +134,14 @@ angular.module('manage').controller('manageUserController', ['$scope', '$injecto
|
|||||||
$scope.permissionsRemoved = new PermissionSet();
|
$scope.permissionsRemoved = new PermissionSet();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The management-related actions that the current user may perform on the
|
* For each applicable data source, the management-related actions that the
|
||||||
* user currently being created/modified, or null if the current user's
|
* current user may perform on the user account currently being created
|
||||||
* permissions have not yet been loaded.
|
* or modified, as a map of data source identifier to the
|
||||||
|
* {@link ManagementPermissions} object describing the actions available
|
||||||
|
* within that data source, or null if the current user's permissions have
|
||||||
|
* not yet been loaded.
|
||||||
*
|
*
|
||||||
* @type ManagementPermissions
|
* @type Object.<String, ManagementPermissions>
|
||||||
*/
|
*/
|
||||||
$scope.managementPermissions = null;
|
$scope.managementPermissions = null;
|
||||||
|
|
||||||
@@ -153,14 +154,6 @@ angular.module('manage').controller('manageUserController', ['$scope', '$injecto
|
|||||||
*/
|
*/
|
||||||
$scope.attributes = null;
|
$scope.attributes = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* The pages associated with each user account having the given username.
|
|
||||||
* Each user account will be associated with a particular data source.
|
|
||||||
*
|
|
||||||
* @type PageDefinition[]
|
|
||||||
*/
|
|
||||||
$scope.accountPages = [];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether critical data has completed being loaded.
|
* Returns whether critical data has completed being loaded.
|
||||||
*
|
*
|
||||||
@@ -349,53 +342,42 @@ angular.module('manage').controller('manageUserController', ['$scope', '$injecto
|
|||||||
})
|
})
|
||||||
.then(function dataReceived(values) {
|
.then(function dataReceived(values) {
|
||||||
|
|
||||||
var managementPermissions = {};
|
|
||||||
|
|
||||||
$scope.attributes = values.attributes;
|
$scope.attributes = values.attributes;
|
||||||
|
|
||||||
// Generate pages for each applicable data source
|
$scope.managementPermissions = {};
|
||||||
$scope.accountPages = [];
|
|
||||||
angular.forEach(dataSources, function addAccountPage(dataSource) {
|
angular.forEach(dataSources, function addAccountPage(dataSource) {
|
||||||
|
|
||||||
// Determine whether data source contains this user
|
// Determine whether data source contains this user
|
||||||
var exists = (dataSource in $scope.users);
|
var exists = (dataSource in $scope.users);
|
||||||
|
|
||||||
// Calculate management actions available for this specific account
|
// Calculate management actions available for this specific account
|
||||||
managementPermissions[dataSource] = ManagementPermissions.fromPermissionSet(
|
$scope.managementPermissions[dataSource] = ManagementPermissions.fromPermissionSet(
|
||||||
values.permissions[dataSource],
|
values.permissions[dataSource],
|
||||||
PermissionSet.SystemPermissionType.CREATE_USER,
|
PermissionSet.SystemPermissionType.CREATE_USER,
|
||||||
PermissionSet.hasUserPermission,
|
PermissionSet.hasUserPermission,
|
||||||
exists ? username : null);
|
exists ? username : null);
|
||||||
|
|
||||||
// Account is not relevant if it does not exist and cannot be
|
|
||||||
// created
|
|
||||||
var readOnly = !managementPermissions[dataSource].canSaveObject;
|
|
||||||
if (!exists && readOnly)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Only the selected data source is relevant when cloning
|
|
||||||
if (cloneSourceUsername && dataSource !== $scope.dataSource)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Determine class name based on read-only / linked status
|
|
||||||
var className;
|
|
||||||
if (readOnly) className = 'read-only';
|
|
||||||
else if (exists) className = 'linked';
|
|
||||||
else className = 'unlinked';
|
|
||||||
|
|
||||||
// Add page entry
|
|
||||||
$scope.accountPages.push(new PageDefinition({
|
|
||||||
name : translationStringService.canonicalize('DATA_SOURCE_' + dataSource) + '.NAME',
|
|
||||||
url : '/manage/' + encodeURIComponent(dataSource) + '/users/' + encodeURIComponent(username || ''),
|
|
||||||
className : className
|
|
||||||
}));
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$scope.managementPermissions = managementPermissions[$scope.dataSource];
|
|
||||||
|
|
||||||
}, requestService.WARN);
|
}, requestService.WARN);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the URL for the page which manages the user account currently
|
||||||
|
* being edited under the given data source. The given data source need not
|
||||||
|
* be the same as the data source currently selected.
|
||||||
|
*
|
||||||
|
* @param {String} dataSource
|
||||||
|
* The unique identifier of the data source that the URL is being
|
||||||
|
* generated for.
|
||||||
|
*
|
||||||
|
* @returns {String}
|
||||||
|
* The URL for the page which manages the user account currently being
|
||||||
|
* edited under the given data source.
|
||||||
|
*/
|
||||||
|
$scope.getUserURL = function getUserURL(dataSource) {
|
||||||
|
return '/manage/' + encodeURIComponent(dataSource) + '/users/' + encodeURIComponent(username || '');
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancels all pending edits, returning to the main list of users.
|
* Cancels all pending edits, returning to the main list of users.
|
||||||
*/
|
*/
|
||||||
|
@@ -0,0 +1,111 @@
|
|||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Directive which displays a set of tabs pointing to the same object within
|
||||||
|
* different data sources, such as user accounts which span multiple data
|
||||||
|
* sources.
|
||||||
|
*/
|
||||||
|
angular.module('manage').directive('dataSourceTabs', ['$injector',
|
||||||
|
function dataSourceTabs($injector) {
|
||||||
|
|
||||||
|
// Required types
|
||||||
|
var PageDefinition = $injector.get('PageDefinition');
|
||||||
|
|
||||||
|
// Required services
|
||||||
|
var translationStringService = $injector.get('translationStringService');
|
||||||
|
|
||||||
|
var directive = {
|
||||||
|
|
||||||
|
restrict : 'E',
|
||||||
|
replace : true,
|
||||||
|
templateUrl : 'app/manage/templates/dataSourceTabs.html',
|
||||||
|
|
||||||
|
scope : {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The permissions which dictate the management actions available
|
||||||
|
* to the current user.
|
||||||
|
*
|
||||||
|
* @type Object.<String, ManagementPermissions>
|
||||||
|
*/
|
||||||
|
permissions : '=',
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A function which returns the URL of the object within a given
|
||||||
|
* data source. The relevant data source will be made available to
|
||||||
|
* the Angular expression defining this function as the
|
||||||
|
* "dataSource" variable. No other values will be made available,
|
||||||
|
* including values from the scope.
|
||||||
|
*
|
||||||
|
* @type Function
|
||||||
|
*/
|
||||||
|
url : '&'
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
directive.controller = ['$scope', function dataSourceTabsController($scope) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The set of pages which each manage the same object within different
|
||||||
|
* data sources.
|
||||||
|
*
|
||||||
|
* @type PageDefinition[]
|
||||||
|
*/
|
||||||
|
$scope.pages = null;
|
||||||
|
|
||||||
|
// Keep pages synchronized with permissions
|
||||||
|
$scope.$watch('permissions', function permissionsChanged(permissions) {
|
||||||
|
|
||||||
|
$scope.pages = [];
|
||||||
|
angular.forEach(permissions, function addDataSourcePage(managementPermissions, dataSource) {
|
||||||
|
|
||||||
|
// Determine whether data source contains this object
|
||||||
|
var exists = !!managementPermissions.identifier;
|
||||||
|
|
||||||
|
// Data source is not relevant if the associated object does not
|
||||||
|
// exist and cannot be created
|
||||||
|
var readOnly = !managementPermissions.canSaveObject;
|
||||||
|
if (!exists && readOnly)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Determine class name based on read-only / linked status
|
||||||
|
var className;
|
||||||
|
if (readOnly) className = 'read-only';
|
||||||
|
else if (exists) className = 'linked';
|
||||||
|
else className = 'unlinked';
|
||||||
|
|
||||||
|
// Add page entry
|
||||||
|
$scope.pages.push(new PageDefinition({
|
||||||
|
name : translationStringService.canonicalize('DATA_SOURCE_' + dataSource) + '.NAME',
|
||||||
|
url : $scope.url({ dataSource : dataSource }),
|
||||||
|
className : className
|
||||||
|
}));
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}];
|
||||||
|
|
||||||
|
return directive;
|
||||||
|
|
||||||
|
}]);
|
@@ -0,0 +1,3 @@
|
|||||||
|
<div class="page-tabs">
|
||||||
|
<guac-page-list pages="pages"></guac-page-list>
|
||||||
|
</div>
|
@@ -6,17 +6,18 @@
|
|||||||
<h2>{{'MANAGE_USER.SECTION_HEADER_EDIT_USER' | translate}}</h2>
|
<h2>{{'MANAGE_USER.SECTION_HEADER_EDIT_USER' | translate}}</h2>
|
||||||
<guac-user-menu></guac-user-menu>
|
<guac-user-menu></guac-user-menu>
|
||||||
</div>
|
</div>
|
||||||
<div class="page-tabs">
|
<data-data-source-tabs ng-hide="cloneSourceUsername"
|
||||||
<guac-page-list pages="accountPages"></guac-page-list>
|
permissions="managementPermissions"
|
||||||
</div>
|
url="getUserURL(dataSource)">
|
||||||
|
</data-data-source-tabs>
|
||||||
|
|
||||||
<!-- Warn if user is read-only -->
|
<!-- Warn if user is read-only -->
|
||||||
<div class="section" ng-hide="managementPermissions.canSaveObject">
|
<div class="section" ng-hide="managementPermissions[dataSource].canSaveObject">
|
||||||
<p class="notice read-only">{{'MANAGE_USER.INFO_READ_ONLY' | translate}}</p>
|
<p class="notice read-only">{{'MANAGE_USER.INFO_READ_ONLY' | translate}}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Sections applicable to non-read-only users -->
|
<!-- Sections applicable to non-read-only users -->
|
||||||
<div ng-show="managementPermissions.canSaveObject">
|
<div ng-show="managementPermissions[dataSource].canSaveObject">
|
||||||
|
|
||||||
<!-- User password section -->
|
<!-- User password section -->
|
||||||
<div class="section">
|
<div class="section">
|
||||||
@@ -40,13 +41,14 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- User attributes section -->
|
<!-- User attributes section -->
|
||||||
<div class="attributes" ng-show="managementPermissions.canChangeAttributes">
|
<div class="attributes" ng-show="managementPermissions[dataSource].canChangeAttributes">
|
||||||
<guac-form namespace="'USER_ATTRIBUTES'" content="attributes"
|
<guac-form namespace="'USER_ATTRIBUTES'" content="attributes"
|
||||||
model="user.attributes" model-only="!managementPermissions.canChangeAllAttributes"></guac-form>
|
model="user.attributes"
|
||||||
|
model-only="!managementPermissions[dataSource].canChangeAllAttributes"></guac-form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- System permissions section -->
|
<!-- System permissions section -->
|
||||||
<system-permission-editor ng-show="managementPermissions.canChangePermissions"
|
<system-permission-editor ng-show="managementPermissions[dataSource].canChangePermissions"
|
||||||
username="selfUsername"
|
username="selfUsername"
|
||||||
data-data-source="dataSource"
|
data-data-source="dataSource"
|
||||||
permission-flags="permissionFlags"
|
permission-flags="permissionFlags"
|
||||||
@@ -55,7 +57,7 @@
|
|||||||
</system-permission-editor>
|
</system-permission-editor>
|
||||||
|
|
||||||
<!-- Connection permissions section -->
|
<!-- Connection permissions section -->
|
||||||
<connection-permission-editor ng-show="managementPermissions.canChangePermissions"
|
<connection-permission-editor ng-show="managementPermissions[dataSource].canChangePermissions"
|
||||||
data-data-source="dataSource"
|
data-data-source="dataSource"
|
||||||
permission-flags="permissionFlags"
|
permission-flags="permissionFlags"
|
||||||
permissions-added="permissionsAdded"
|
permissions-added="permissionsAdded"
|
||||||
@@ -64,7 +66,7 @@
|
|||||||
|
|
||||||
<!-- Form action buttons -->
|
<!-- Form action buttons -->
|
||||||
<management-buttons namespace="'MANAGE_USER'"
|
<management-buttons namespace="'MANAGE_USER'"
|
||||||
permissions="managementPermissions"
|
permissions="managementPermissions[dataSource]"
|
||||||
save="saveUser()"
|
save="saveUser()"
|
||||||
delete="deleteUser()"
|
delete="deleteUser()"
|
||||||
clone="cloneUser()"
|
clone="cloneUser()"
|
||||||
|
Reference in New Issue
Block a user