You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@guacamole.apache.org by jm...@apache.org on 2016/08/20 22:08:14 UTC
[4/5] incubator-guacamole-client git commit: GUACAMOLE-77: Retrieve
the current user's permissions via ".../self" rather than
".../users/{username}". The current user may not actually exist.
GUACAMOLE-77: Retrieve the current user's permissions via ".../self" rather than ".../users/{username}". The current user may not actually exist.
Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/20459ecb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/20459ecb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/20459ecb
Branch: refs/heads/master
Commit: 20459ecbd34fc4d215460523f59e0b2efa1936ed
Parents: 36dc375
Author: Michael Jumper <mj...@apache.org>
Authored: Sat Aug 20 14:23:43 2016 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Sat Aug 20 14:47:44 2016 -0700
----------------------------------------------------------------------
.../app/rest/services/permissionService.js | 43 +++++++++++++++++++-
1 file changed, 41 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/20459ecb/guacamole/src/main/webapp/app/rest/services/permissionService.js
----------------------------------------------------------------------
diff --git a/guacamole/src/main/webapp/app/rest/services/permissionService.js b/guacamole/src/main/webapp/app/rest/services/permissionService.js
index 67fceba..a803775 100644
--- a/guacamole/src/main/webapp/app/rest/services/permissionService.js
+++ b/guacamole/src/main/webapp/app/rest/services/permissionService.js
@@ -35,6 +35,45 @@ angular.module('rest').factory('permissionService', ['$injector',
var service = {};
/**
+ * Returns the URL for the REST resource most appropriate for accessing
+ * the permissions of the user having the given username.
+ *
+ * It is important to note that a particular data source can authenticate
+ * and provide permissions for a user, even if that user does not exist
+ * within that data source (and thus cannot be found beneath
+ * "api/session/data/{dataSource}/users")
+ *
+ * @param {String} dataSource
+ * The unique identifier of the data source containing the user whose
+ * permissions should be retrieved. This identifier corresponds to an
+ * AuthenticationProvider within the Guacamole web application.
+ *
+ * @param {String} username
+ * The username of the user for which the URL of the proper REST
+ * resource should be derived.
+ *
+ * @returns {String}
+ * The URL for the REST resource representing the user having the given
+ * username.
+ */
+ var getPermissionsResourceURL = function getPermissionsResourceURL(dataSource, username) {
+
+ // Create base URL for data source
+ var base = 'api/session/data/' + encodeURIComponent(dataSource);
+
+ // If the username is that of the current user, do not rely on the
+ // user actually existing (they may not). Access their permissions via
+ // "self" rather than the collection of defined users.
+ if (username === authenticationService.getCurrentUsername())
+ return base + '/self/permissions';
+
+ // Otherwise, the user must exist for their permissions to be
+ // accessible. Use the collection of defined users.
+ return base + '/users/' + encodeURIComponent(username) + '/permissions';
+
+ };
+
+ /**
* Makes a request to the REST API to get the list of permissions for a
* given user, returning a promise that provides an array of
* @link{Permission} objects if successful.
@@ -62,7 +101,7 @@ angular.module('rest').factory('permissionService', ['$injector',
return $http({
cache : cacheService.users,
method : 'GET',
- url : 'api/session/data/' + encodeURIComponent(dataSource) + '/users/' + encodeURIComponent(userID) + '/permissions',
+ url : getPermissionsResourceURL(dataSource, userID),
params : httpParameters
});
@@ -239,7 +278,7 @@ angular.module('rest').factory('permissionService', ['$injector',
// Patch user permissions
return $http({
method : 'PATCH',
- url : 'api/session/data/' + encodeURIComponent(dataSource) + '/users/' + encodeURIComponent(userID) + '/permissions',
+ url : getPermissionsResourceURL(dataSource, userID),
params : httpParameters,
data : permissionPatch
})