mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 13:41:21 +00:00
GUAC-932: Rename various *DAO to *Service. Rename legacy services to legacy*, pending removal/refactor.
This commit is contained in:
@@ -132,8 +132,8 @@ angular.module('home').controller('clientController', ['$scope', '$routeParams',
|
|||||||
remaining: 15
|
remaining: 15
|
||||||
};
|
};
|
||||||
|
|
||||||
// Get DAO for reading connections and groups
|
// Get services for reading connections and groups
|
||||||
var connectionGroupDAO = $injector.get('connectionGroupDAO');
|
var connectionGroupService = $injector.get('connectionGroupService');
|
||||||
var connectionService = $injector.get('connectionService');
|
var connectionService = $injector.get('connectionService');
|
||||||
var ClientProperties = $injector.get('ClientProperties');
|
var ClientProperties = $injector.get('ClientProperties');
|
||||||
|
|
||||||
@@ -176,7 +176,7 @@ angular.module('home').controller('clientController', ['$scope', '$routeParams',
|
|||||||
|
|
||||||
// Connection group
|
// Connection group
|
||||||
case 'g':
|
case 'g':
|
||||||
connectionGroupDAO.getConnectionGroup($routeParams.id).success(function (group) {
|
connectionGroupService.getConnectionGroup($routeParams.id).success(function (group) {
|
||||||
$scope.connectionName = $scope.page.title = group.name;
|
$scope.connectionName = $scope.page.title = group.name;
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
@@ -30,7 +30,7 @@ angular.module('home').controller('homeController', ['$scope', '$injector',
|
|||||||
var GUAC_HISTORY_STORAGE_KEY = "GUAC_HISTORY";
|
var GUAC_HISTORY_STORAGE_KEY = "GUAC_HISTORY";
|
||||||
|
|
||||||
// Get the dependencies commonJS style
|
// Get the dependencies commonJS style
|
||||||
var connectionGroupService = $injector.get("connectionGroupService");
|
var legacyConnectionGroupService = $injector.get("legacyConnectionGroupService");
|
||||||
var guacHistory = $injector.get("guacHistory");
|
var guacHistory = $injector.get("guacHistory");
|
||||||
|
|
||||||
// All the connections and connection groups in root
|
// All the connections and connection groups in root
|
||||||
@@ -45,7 +45,7 @@ angular.module('home').controller('homeController', ['$scope', '$injector',
|
|||||||
/* Fetch all connections and groups, then find which recent connections
|
/* Fetch all connections and groups, then find which recent connections
|
||||||
* still refer to valid connections and groups.
|
* still refer to valid connections and groups.
|
||||||
*/
|
*/
|
||||||
connectionGroupService.getAllGroupsAndConnections($scope.connectionsAndGroups)
|
legacyConnectionGroupService.getAllGroupsAndConnections($scope.connectionsAndGroups)
|
||||||
.then(function findRecentConnections() {
|
.then(function findRecentConnections() {
|
||||||
|
|
||||||
// TODONT: Munch the guacHistory recentConnections list into a legacy-style object
|
// TODONT: Munch the guacHistory recentConnections list into a legacy-style object
|
||||||
|
@@ -27,7 +27,7 @@ angular.module('index').controller('indexController', ['$scope', '$injector',
|
|||||||
function indexController($scope, $injector) {
|
function indexController($scope, $injector) {
|
||||||
|
|
||||||
// Get the dependencies commonJS style
|
// Get the dependencies commonJS style
|
||||||
var permissionDAO = $injector.get("permissionDAO"),
|
var permissionService = $injector.get("permissionService"),
|
||||||
permissionCheckService = $injector.get("permissionCheckService"),
|
permissionCheckService = $injector.get("permissionCheckService"),
|
||||||
authenticationService = $injector.get("authenticationService"),
|
authenticationService = $injector.get("authenticationService"),
|
||||||
$q = $injector.get("$q"),
|
$q = $injector.get("$q"),
|
||||||
@@ -166,7 +166,7 @@ angular.module('index').controller('indexController', ['$scope', '$injector',
|
|||||||
// Allow the permissions to be reloaded elsewhere if needed
|
// Allow the permissions to be reloaded elsewhere if needed
|
||||||
$scope.loadBasicPermissions = function loadBasicPermissions() {
|
$scope.loadBasicPermissions = function loadBasicPermissions() {
|
||||||
|
|
||||||
permissionDAO.getPermissions($scope.currentUserID).success(function fetchCurrentUserPermissions(permissions) {
|
permissionService.getPermissions($scope.currentUserID).success(function fetchCurrentUserPermissions(permissions) {
|
||||||
$scope.currentUserPermissions = permissions;
|
$scope.currentUserPermissions = permissions;
|
||||||
|
|
||||||
// Will be true if the user is an admin
|
// Will be true if the user is an admin
|
||||||
|
@@ -27,7 +27,7 @@ angular.module('manage').controller('connectionGroupEditModalController', ['$sco
|
|||||||
function connectionEditModalController($scope, $injector) {
|
function connectionEditModalController($scope, $injector) {
|
||||||
|
|
||||||
var connectionGroupEditModal = $injector.get('connectionGroupEditModal');
|
var connectionGroupEditModal = $injector.get('connectionGroupEditModal');
|
||||||
var connectionGroupDAO = $injector.get('connectionGroupDAO');
|
var connectionGroupService = $injector.get('connectionGroupService');
|
||||||
var displayObjectPreparationService = $injector.get('displayObjectPreparationService');
|
var displayObjectPreparationService = $injector.get('displayObjectPreparationService');
|
||||||
|
|
||||||
// Make a copy of the old connection group so that we can copy over the changes when done
|
// Make a copy of the old connection group so that we can copy over the changes when done
|
||||||
@@ -64,7 +64,7 @@ angular.module('manage').controller('connectionGroupEditModalController', ['$sco
|
|||||||
* Save the connection and close the modal.
|
* Save the connection and close the modal.
|
||||||
*/
|
*/
|
||||||
$scope.save = function save() {
|
$scope.save = function save() {
|
||||||
connectionGroupDAO.saveConnectionGroup($scope.connectionGroup).success(function successfullyUpdatedConnectionGroup() {
|
connectionGroupService.saveConnectionGroup($scope.connectionGroup).success(function successfullyUpdatedConnectionGroup() {
|
||||||
|
|
||||||
// Prepare this connection group for display
|
// Prepare this connection group for display
|
||||||
displayObjectPreparationService.prepareConnectionGroup($scope.connectionGroup);
|
displayObjectPreparationService.prepareConnectionGroup($scope.connectionGroup);
|
||||||
@@ -79,7 +79,7 @@ angular.module('manage').controller('connectionGroupEditModalController', ['$sco
|
|||||||
if(newConnectionGroup && newParentID === $scope.rootGroup.identifier) {
|
if(newConnectionGroup && newParentID === $scope.rootGroup.identifier) {
|
||||||
$scope.moveItem($scope.connectionGroup, oldParentID, newParentID);
|
$scope.moveItem($scope.connectionGroup, oldParentID, newParentID);
|
||||||
} else {
|
} else {
|
||||||
connectionGroupDAO.moveConnectionGroup($scope.connectionGroup).then(function moveConnectionGroup() {
|
connectionGroupService.moveConnectionGroup($scope.connectionGroup).then(function moveConnectionGroup() {
|
||||||
$scope.moveItem($scope.connectionGroup, oldParentID, newParentID);
|
$scope.moveItem($scope.connectionGroup, oldParentID, newParentID);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -99,7 +99,7 @@ angular.module('manage').controller('connectionGroupEditModalController', ['$sco
|
|||||||
// Close the modal
|
// Close the modal
|
||||||
connectionGroupEditModal.deactivate();
|
connectionGroupEditModal.deactivate();
|
||||||
|
|
||||||
connectionGroupDAO.deleteConnectionGroup($scope.connectionGroup).success(function successfullyDeletedConnectionGroup() {
|
connectionGroupService.deleteConnectionGroup($scope.connectionGroup).success(function successfullyDeletedConnectionGroup() {
|
||||||
var oldParentID = oldConnectionGroup.parentIdentifier;
|
var oldParentID = oldConnectionGroup.parentIdentifier;
|
||||||
|
|
||||||
// We have to remove this connection group from the heirarchy
|
// We have to remove this connection group from the heirarchy
|
||||||
|
@@ -27,13 +27,13 @@ angular.module('manage').controller('manageController', ['$scope', '$injector',
|
|||||||
function manageController($scope, $injector) {
|
function manageController($scope, $injector) {
|
||||||
|
|
||||||
// Get the dependencies commonJS style
|
// Get the dependencies commonJS style
|
||||||
var connectionGroupService = $injector.get('connectionGroupService');
|
var legacyConnectionGroupService = $injector.get('legacyConnectionGroupService');
|
||||||
var connectionEditModal = $injector.get('connectionEditModal');
|
var connectionEditModal = $injector.get('connectionEditModal');
|
||||||
var connectionGroupEditModal = $injector.get('connectionGroupEditModal');
|
var connectionGroupEditModal = $injector.get('connectionGroupEditModal');
|
||||||
var userEditModal = $injector.get('userEditModal');
|
var userEditModal = $injector.get('userEditModal');
|
||||||
var protocolDAO = $injector.get('protocolDAO');
|
var protocolService = $injector.get('protocolService');
|
||||||
var userDAO = $injector.get('userDAO');
|
|
||||||
var userService = $injector.get('userService');
|
var userService = $injector.get('userService');
|
||||||
|
var legacyUserService = $injector.get('legacyUserService');
|
||||||
|
|
||||||
// Set status to loading until we have all the connections, groups, and users have loaded
|
// Set status to loading until we have all the connections, groups, and users have loaded
|
||||||
$scope.loadingUsers = true;
|
$scope.loadingUsers = true;
|
||||||
@@ -46,13 +46,13 @@ angular.module('manage').controller('manageController', ['$scope', '$injector',
|
|||||||
$scope.users = [];
|
$scope.users = [];
|
||||||
|
|
||||||
$scope.basicPermissionsLoaded.then(function basicPermissionsHaveBeenLoaded() {
|
$scope.basicPermissionsLoaded.then(function basicPermissionsHaveBeenLoaded() {
|
||||||
connectionGroupService.getAllGroupsAndConnections([], undefined, true, true).then(function filterConnectionsAndGroups(rootGroupList) {
|
legacyConnectionGroupService.getAllGroupsAndConnections([], undefined, true, true).then(function filterConnectionsAndGroups(rootGroupList) {
|
||||||
$scope.rootGroup = rootGroupList[0];
|
$scope.rootGroup = rootGroupList[0];
|
||||||
$scope.connectionsAndGroups = $scope.rootGroup.children;
|
$scope.connectionsAndGroups = $scope.rootGroup.children;
|
||||||
|
|
||||||
// Filter the items to only include ones that we have UPDATE for
|
// Filter the items to only include ones that we have UPDATE for
|
||||||
if(!$scope.currentUserIsAdmin) {
|
if(!$scope.currentUserIsAdmin) {
|
||||||
connectionGroupService.filterConnectionsAndGroupByPermission(
|
legacyConnectionGroupService.filterConnectionsAndGroupByPermission(
|
||||||
$scope.connectionsAndGroups,
|
$scope.connectionsAndGroups,
|
||||||
$scope.currentUserPermissions,
|
$scope.currentUserPermissions,
|
||||||
{
|
{
|
||||||
@@ -65,12 +65,12 @@ angular.module('manage').controller('manageController', ['$scope', '$injector',
|
|||||||
$scope.loadingConnections = false;
|
$scope.loadingConnections = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
userDAO.getUsers().success(function filterEditableUsers(users) {
|
userService.getUsers().success(function filterEditableUsers(users) {
|
||||||
$scope.users = users;
|
$scope.users = users;
|
||||||
|
|
||||||
// Filter the users to only include ones that we have UPDATE for
|
// Filter the users to only include ones that we have UPDATE for
|
||||||
if(!$scope.currentUserIsAdmin) {
|
if(!$scope.currentUserIsAdmin) {
|
||||||
userService.filterUsersByPermission(
|
legacyUserService.filterUsersByPermission(
|
||||||
$scope.users,
|
$scope.users,
|
||||||
$scope.currentUserPermissions,
|
$scope.currentUserPermissions,
|
||||||
'UPDATE'
|
'UPDATE'
|
||||||
@@ -132,7 +132,7 @@ angular.module('manage').controller('manageController', ['$scope', '$injector',
|
|||||||
$scope.protocols = {};
|
$scope.protocols = {};
|
||||||
|
|
||||||
// Get the protocol information from the server and copy it into the scope
|
// Get the protocol information from the server and copy it into the scope
|
||||||
protocolDAO.getProtocols().success(function fetchProtocols(protocols) {
|
protocolService.getProtocols().success(function fetchProtocols(protocols) {
|
||||||
angular.extend($scope.protocols, protocols);
|
angular.extend($scope.protocols, protocols);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -236,7 +236,7 @@ angular.module('manage').controller('manageController', ['$scope', '$injector',
|
|||||||
username: $scope.newUsername
|
username: $scope.newUsername
|
||||||
};
|
};
|
||||||
|
|
||||||
userDAO.createUser(newUser).success(function addUserToList() {
|
userService.createUser(newUser).success(function addUserToList() {
|
||||||
$scope.users.push(newUser);
|
$scope.users.push(newUser);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -27,8 +27,8 @@ angular.module('manage').controller('userEditModalController', ['$scope', '$inje
|
|||||||
function userEditModalController($scope, $injector) {
|
function userEditModalController($scope, $injector) {
|
||||||
|
|
||||||
var userEditModal = $injector.get('userEditModal');
|
var userEditModal = $injector.get('userEditModal');
|
||||||
var userDAO = $injector.get('userDAO');
|
var userService = $injector.get('userService');
|
||||||
var permissionDAO = $injector.get('permissionDAO');
|
var permissionService = $injector.get('permissionService');
|
||||||
|
|
||||||
// Make a copy of the old user so that we can copy over the changes when done
|
// Make a copy of the old user so that we can copy over the changes when done
|
||||||
var oldUser = $scope.user;
|
var oldUser = $scope.user;
|
||||||
@@ -73,7 +73,7 @@ angular.module('manage').controller('userEditModalController', ['$scope', '$inje
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
userDAO.saveUser($scope.user).success(function successfullyUpdatedUser() {
|
userService.saveUser($scope.user).success(function successfullyUpdatedUser() {
|
||||||
|
|
||||||
//Figure out what permissions have changed
|
//Figure out what permissions have changed
|
||||||
var connectionPermissionsToCreate = [],
|
var connectionPermissionsToCreate = [],
|
||||||
@@ -182,7 +182,7 @@ angular.module('manage').controller('userEditModalController', ['$scope', '$inje
|
|||||||
|
|
||||||
if(permissionsToAdd.length || permissionsToRemove.length) {
|
if(permissionsToAdd.length || permissionsToRemove.length) {
|
||||||
// Make the call to update the permissions
|
// Make the call to update the permissions
|
||||||
permissionDAO.patchPermissions(
|
permissionService.patchPermissions(
|
||||||
$scope.user.username, permissionsToAdd, permissionsToRemove)
|
$scope.user.username, permissionsToAdd, permissionsToRemove)
|
||||||
.success(completeSaveProcess).error(handleFailure);
|
.success(completeSaveProcess).error(handleFailure);
|
||||||
} else {
|
} else {
|
||||||
@@ -205,7 +205,7 @@ angular.module('manage').controller('userEditModalController', ['$scope', '$inje
|
|||||||
originalSystemPermissions;
|
originalSystemPermissions;
|
||||||
|
|
||||||
// Get the permissions for the user we are editing
|
// Get the permissions for the user we are editing
|
||||||
permissionDAO.getPermissions($scope.user.username).success(function gotPermissions(permissions) {
|
permissionService.getPermissions($scope.user.username).success(function gotPermissions(permissions) {
|
||||||
$scope.permissions = permissions;
|
$scope.permissions = permissions;
|
||||||
|
|
||||||
// Figure out if the user has any system level permissions
|
// Figure out if the user has any system level permissions
|
||||||
@@ -239,7 +239,7 @@ angular.module('manage').controller('userEditModalController', ['$scope', '$inje
|
|||||||
* Delete the user and close the modal.
|
* Delete the user and close the modal.
|
||||||
*/
|
*/
|
||||||
$scope['delete'] = function deleteUser() {
|
$scope['delete'] = function deleteUser() {
|
||||||
userDAO.deleteUser($scope.user).success(function successfullyDeletedUser() {
|
userService.deleteUser($scope.user).success(function successfullyDeletedUser() {
|
||||||
|
|
||||||
// Remove the user from the list
|
// Remove the user from the list
|
||||||
$scope.removeUser($scope.user);
|
$scope.removeUser($scope.user);
|
||||||
|
@@ -1,130 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2014 Glyptodon LLC
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The DAO for connection group operations agains the REST API.
|
|
||||||
*/
|
|
||||||
angular.module('rest').factory('connectionGroupDAO', ['$http', 'authenticationService',
|
|
||||||
function connectionGrouDAO($http, authenticationService) {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The ID of the root connection group.
|
|
||||||
*/
|
|
||||||
var ROOT_CONNECTION_GROUP_ID = "ROOT";
|
|
||||||
|
|
||||||
var service = {};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Makes a request to the REST API to get the list of connection groups,
|
|
||||||
* returning a promise that can be used for processing the results of the call.
|
|
||||||
*
|
|
||||||
* @param {string} parentID The parent ID for the connection group.
|
|
||||||
* If not passed in, it will query a list of the
|
|
||||||
* connection groups in the root group.
|
|
||||||
*
|
|
||||||
* @returns {promise} A promise for the HTTP call.
|
|
||||||
*/
|
|
||||||
service.getConnectionGroups = function getConnectionGroups(parentID) {
|
|
||||||
|
|
||||||
var parentIDParam = "";
|
|
||||||
if(parentID !== undefined)
|
|
||||||
parentIDParam = "&parentID=" + parentID;
|
|
||||||
|
|
||||||
return $http.get("api/connectionGroup?token=" + authenticationService.getCurrentToken() + parentIDParam);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Makes a request to the REST API to get an individual connection group,
|
|
||||||
* returning a promise that can be used for processing the results of the call.
|
|
||||||
*
|
|
||||||
* @param {string} connectionGroupID The ID for the connection group.
|
|
||||||
* If not passed in, it will query the
|
|
||||||
* root connection group.
|
|
||||||
*
|
|
||||||
* @returns {promise} A promise for the HTTP call.
|
|
||||||
*/
|
|
||||||
service.getConnectionGroup = function getConnectionGroup(connectionGroupID) {
|
|
||||||
|
|
||||||
// Use the root connection group ID if no ID is passed in
|
|
||||||
connectionGroupID = connectionGroupID || ROOT_CONNECTION_GROUP_ID;
|
|
||||||
|
|
||||||
return $http.get("api/connectionGroup/" + connectionGroupID + "?token=" + authenticationService.getCurrentToken());
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Makes a request to the REST API to save a connection group,
|
|
||||||
* returning a promise that can be used for processing the results of the call.
|
|
||||||
*
|
|
||||||
* @param {object} connectionGroup The connection group to update
|
|
||||||
*
|
|
||||||
* @returns {promise} A promise for the HTTP call.
|
|
||||||
*/
|
|
||||||
service.saveConnectionGroup = function saveConnectionGroup(connectionGroup) {
|
|
||||||
// This is a new connection group
|
|
||||||
if(!connectionGroup.identifier) {
|
|
||||||
return $http.post("api/connectionGroup/?token=" + authenticationService.getCurrentToken(), connectionGroup).success(
|
|
||||||
function setConnectionGroupID(connectionGroupID){
|
|
||||||
// Set the identifier on the new connection
|
|
||||||
connectionGroup.identifier = connectionGroupID;
|
|
||||||
return connectionGroupID;
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return $http.post(
|
|
||||||
"api/connectionGroup/" + connectionGroup.identifier +
|
|
||||||
"?token=" + authenticationService.getCurrentToken(),
|
|
||||||
connectionGroup);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Makes a request to the REST API to move a connection group to a different group,
|
|
||||||
* returning a promise that can be used for processing the results of the call.
|
|
||||||
*
|
|
||||||
* @param {object} connectionGroup The connection group to move.
|
|
||||||
*
|
|
||||||
* @returns {promise} A promise for the HTTP call.
|
|
||||||
*/
|
|
||||||
service.moveConnectionGroup = function moveConnectionGroup(connectionGroup) {
|
|
||||||
|
|
||||||
return $http.put(
|
|
||||||
"api/connectionGroup/" + connectionGroup.identifier +
|
|
||||||
"?token=" + authenticationService.getCurrentToken() +
|
|
||||||
"&parentID=" + connectionGroup.parentIdentifier,
|
|
||||||
connectionGroup);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Makes a request to the REST API to delete a connection group,
|
|
||||||
* returning a promise that can be used for processing the results of the call.
|
|
||||||
*
|
|
||||||
* @param {object} connectionGroup The connection group to delete
|
|
||||||
*
|
|
||||||
* @returns {promise} A promise for the HTTP call.
|
|
||||||
*/
|
|
||||||
service.deleteConnectionGroup = function deleteConnectionGroup(connectionGroup) {
|
|
||||||
return $http['delete'](
|
|
||||||
"api/connectionGroup/" + connectionGroup.identifier +
|
|
||||||
"?token=" + authenticationService.getCurrentToken());
|
|
||||||
};
|
|
||||||
|
|
||||||
return service;
|
|
||||||
}]);
|
|
@@ -21,210 +21,109 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A service for performing useful connection group related functionaltiy.
|
* Service for operating on connection groups via the REST API.
|
||||||
*/
|
*/
|
||||||
angular.module('rest').factory('connectionGroupService', ['$injector', function connectionGroupService($injector) {
|
angular.module('rest').factory('connectionGroupService', ['$http', 'authenticationService',
|
||||||
|
function connectionGrouService($http, authenticationService) {
|
||||||
|
|
||||||
var connectionGroupDAO = $injector.get('connectionGroupDAO');
|
/**
|
||||||
var connectionService = $injector.get('connectionService');
|
* The ID of the root connection group.
|
||||||
var permissionCheckService = $injector.get('permissionCheckService');
|
*/
|
||||||
var $q = $injector.get('$q');
|
var ROOT_CONNECTION_GROUP_ID = "ROOT";
|
||||||
var displayObjectPreparationService = $injector.get('displayObjectPreparationService');
|
|
||||||
|
|
||||||
var service = {};
|
var service = {};
|
||||||
|
|
||||||
// Add all groups from this group to the parent group child list
|
|
||||||
function addToParent(connectionGroup, parentGroup, context, includeConnections) {
|
|
||||||
|
|
||||||
// Include connections by default
|
|
||||||
if(typeof includeConnections === 'undefined')
|
|
||||||
includeConnections = true;
|
|
||||||
|
|
||||||
parentGroup.children.push(connectionGroup);
|
|
||||||
|
|
||||||
// Prepare this group for display
|
|
||||||
displayObjectPreparationService.prepareConnectionGroup(connectionGroup);
|
|
||||||
|
|
||||||
if(includeConnections) {
|
|
||||||
// Get all connections in the group and add them under this connection group
|
|
||||||
context.openRequest();
|
|
||||||
connectionService.getConnections(connectionGroup.identifier).success(function fetchConnections(connections) {
|
|
||||||
for(var i = 0; i < connections.length; i++) {
|
|
||||||
connections[i].isConnection = true;
|
|
||||||
connectionGroup.children.push(connections[i]);
|
|
||||||
}
|
|
||||||
context.closeRequest();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get all connection groups in the group and repeat
|
|
||||||
context.openRequest();
|
|
||||||
connectionGroupDAO.getConnectionGroups(connectionGroup.identifier).success(function fetchConnectionGroups(connectionGroups) {
|
|
||||||
for(var i = 0; i < connectionGroups.length; i++) {
|
|
||||||
addToParent(connectionGroups[i], connectionGroup, context, includeConnections);
|
|
||||||
}
|
|
||||||
context.closeRequest();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Queries all connections and connection groups under the connection group
|
* Makes a request to the REST API to get the list of connection groups,
|
||||||
* with the provided parent ID, and returns them in a heirarchical structure
|
* returning a promise that can be used for processing the results of the call.
|
||||||
* with convinient display properties set on the objects.
|
|
||||||
*
|
|
||||||
* @param {array} items The root list of connections and groups. Should be an
|
|
||||||
* initally empty array that will get filled in as the
|
|
||||||
* connections and groups are loaded.
|
|
||||||
*
|
*
|
||||||
* @param {string} parentID The parent ID for the connection group.
|
* @param {string} parentID The parent ID for the connection group.
|
||||||
* If not passed in, it will begin with
|
* If not passed in, it will query a list of the
|
||||||
* the root connection group.
|
* connection groups in the root group.
|
||||||
*
|
*
|
||||||
* @param {boolean} includeConnections Whether or not to include connections
|
* @returns {promise} A promise for the HTTP call.
|
||||||
* in the structure. Defaults to true.
|
|
||||||
*
|
|
||||||
* @param {boolean} includeRoot Whether or not to include the root connection group
|
|
||||||
* in the structure. Defaults to false.
|
|
||||||
*
|
|
||||||
* @return {promise} A promise that will be fulfilled when all connections
|
|
||||||
* and groups have been loaded.
|
|
||||||
*/
|
*/
|
||||||
service.getAllGroupsAndConnections = function getAllGroupsAndConnections(items, parentID, includeConnections, includeRoot) {
|
service.getConnectionGroups = function getConnectionGroups(parentID) {
|
||||||
|
|
||||||
// Include connections by default
|
var parentIDParam = "";
|
||||||
if(typeof includeConnections === 'undefined')
|
if(parentID !== undefined)
|
||||||
includeConnections = true;
|
parentIDParam = "&parentID=" + parentID;
|
||||||
|
|
||||||
var context = {
|
return $http.get("api/connectionGroup?token=" + authenticationService.getCurrentToken() + parentIDParam);
|
||||||
// The number of requets to the server currently open
|
|
||||||
openRequests : 0,
|
|
||||||
|
|
||||||
// Create the promise
|
|
||||||
finishedFetching : $q.defer(),
|
|
||||||
|
|
||||||
// Notify the caller that the promise has been completed
|
|
||||||
complete : function complete() {
|
|
||||||
this.finishedFetching.resolve(items);
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Indicate that a request has been started.
|
|
||||||
*/
|
|
||||||
openRequest : function openRequest() {
|
|
||||||
this.openRequests++;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Indicate that a request has been completed. If this was the last
|
|
||||||
* open request, fulfill the promise.
|
|
||||||
*/
|
|
||||||
closeRequest : function closeRequest() {
|
|
||||||
if(--this.openRequests === 0)
|
|
||||||
this.complete();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Include the root only if it was asked for
|
/**
|
||||||
if(includeRoot) {
|
* Makes a request to the REST API to get an individual connection group,
|
||||||
context.openRequest();
|
* returning a promise that can be used for processing the results of the call.
|
||||||
connectionGroupDAO.getConnectionGroup(parentID).success(function setRootGroup (rootGroup) {
|
*
|
||||||
items.push(rootGroup);
|
* @param {string} connectionGroupID The ID for the connection group.
|
||||||
rootGroup.children = [];
|
* If not passed in, it will query the
|
||||||
getChildrenOfRootGroup(rootGroup.children);
|
* root connection group.
|
||||||
context.closeRequest();
|
*
|
||||||
|
* @returns {promise} A promise for the HTTP call.
|
||||||
|
*/
|
||||||
|
service.getConnectionGroup = function getConnectionGroup(connectionGroupID) {
|
||||||
|
|
||||||
|
// Use the root connection group ID if no ID is passed in
|
||||||
|
connectionGroupID = connectionGroupID || ROOT_CONNECTION_GROUP_ID;
|
||||||
|
|
||||||
|
return $http.get("api/connectionGroup/" + connectionGroupID + "?token=" + authenticationService.getCurrentToken());
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes a request to the REST API to save a connection group,
|
||||||
|
* returning a promise that can be used for processing the results of the call.
|
||||||
|
*
|
||||||
|
* @param {object} connectionGroup The connection group to update
|
||||||
|
*
|
||||||
|
* @returns {promise} A promise for the HTTP call.
|
||||||
|
*/
|
||||||
|
service.saveConnectionGroup = function saveConnectionGroup(connectionGroup) {
|
||||||
|
// This is a new connection group
|
||||||
|
if(!connectionGroup.identifier) {
|
||||||
|
return $http.post("api/connectionGroup/?token=" + authenticationService.getCurrentToken(), connectionGroup).success(
|
||||||
|
function setConnectionGroupID(connectionGroupID){
|
||||||
|
// Set the identifier on the new connection
|
||||||
|
connectionGroup.identifier = connectionGroupID;
|
||||||
|
return connectionGroupID;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
getChildrenOfRootGroup(items);
|
return $http.post(
|
||||||
|
"api/connectionGroup/" + connectionGroup.identifier +
|
||||||
|
"?token=" + authenticationService.getCurrentToken(),
|
||||||
|
connectionGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the children of the root group
|
|
||||||
function getChildrenOfRootGroup(children) {
|
|
||||||
context.openRequest();
|
|
||||||
connectionGroupDAO.getConnectionGroups(parentID).success(function fetchRootConnectionGroups(connectionGroups) {
|
|
||||||
for(var i = 0; i < connectionGroups.length; i++) {
|
|
||||||
addToParent(connectionGroups[i], {children: children}, context, includeConnections);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(includeConnections) {
|
|
||||||
// Get all connections in the root group and add them under this connection group
|
|
||||||
context.openRequest();
|
|
||||||
connectionService.getConnections().success(function fetchRootConnections(connections) {
|
|
||||||
for(var i = 0; i < connections.length; i++) {
|
|
||||||
|
|
||||||
// Prepare this connection for display
|
|
||||||
displayObjectPreparationService.prepareConnection(connections[i]);
|
|
||||||
|
|
||||||
children.push(connections[i]);
|
|
||||||
}
|
|
||||||
context.closeRequest();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
context.closeRequest();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the promise
|
|
||||||
return context.finishedFetching.promise;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes a request to the REST API to move a connection group to a different group,
|
||||||
|
* returning a promise that can be used for processing the results of the call.
|
||||||
|
*
|
||||||
|
* @param {object} connectionGroup The connection group to move.
|
||||||
|
*
|
||||||
|
* @returns {promise} A promise for the HTTP call.
|
||||||
|
*/
|
||||||
|
service.moveConnectionGroup = function moveConnectionGroup(connectionGroup) {
|
||||||
|
|
||||||
|
return $http.put(
|
||||||
|
"api/connectionGroup/" + connectionGroup.identifier +
|
||||||
|
"?token=" + authenticationService.getCurrentToken() +
|
||||||
|
"&parentID=" + connectionGroup.parentIdentifier,
|
||||||
|
connectionGroup);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filters the list of connections and groups using the provided permissions.
|
* Makes a request to the REST API to delete a connection group,
|
||||||
|
* returning a promise that can be used for processing the results of the call.
|
||||||
*
|
*
|
||||||
* @param {array} items The heirarchical list of groups and connections.
|
* @param {object} connectionGroup The connection group to delete
|
||||||
*
|
*
|
||||||
* @param {object} permissionList The list of permissions to use
|
* @returns {promise} A promise for the HTTP call.
|
||||||
* when filtering.
|
|
||||||
*
|
|
||||||
* @param {object} permissionCriteria A map of object type to permission type(s)
|
|
||||||
* required for that object type.
|
|
||||||
*
|
|
||||||
* @return {array} The filtered list.
|
|
||||||
*/
|
*/
|
||||||
service.filterConnectionsAndGroupByPermission = function filterConnectionsAndGroupByPermission(items, permissionList, permissionCriteria) {
|
service.deleteConnectionGroup = function deleteConnectionGroup(connectionGroup) {
|
||||||
var requiredConnectionPermission = permissionCriteria.CONNECTION;
|
return $http['delete'](
|
||||||
var requiredConnectionGroupPermission = permissionCriteria.CONNECTION_GROUP;
|
"api/connectionGroup/" + connectionGroup.identifier +
|
||||||
|
"?token=" + authenticationService.getCurrentToken());
|
||||||
for(var i = 0; i < items.length; i++) {
|
|
||||||
var item = items[i];
|
|
||||||
|
|
||||||
if(item.isConnection && requiredConnectionPermission) {
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If item is a connection and a permission is required for this
|
|
||||||
* item, check now to see if the permission exists. If not,
|
|
||||||
* remove the item.
|
|
||||||
*/
|
|
||||||
if(!permissionCheckService.checkPermission(permissionList,
|
|
||||||
"CONNECTION", item.identifier, requiredConnectionPermission)) {
|
|
||||||
items.splice(i, 1);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If item is a group and a permission is required for this
|
|
||||||
* item, check now to see if the permission exists. If not,
|
|
||||||
* remove the item.
|
|
||||||
*/
|
|
||||||
if(requiredConnectionGroupPermission) {
|
|
||||||
if(!permissionCheckService.checkPermission(permissionList,
|
|
||||||
"CONNECTION_GROUP", item.identifier, requiredConnectionGroupPermission)) {
|
|
||||||
items.splice(i, 1);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Filter the children of this connection group as well
|
|
||||||
if(item.children && item.children.length)
|
|
||||||
service.filterConnectionsAndGroupByPermission(items.children);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return items;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return service;
|
return service;
|
||||||
|
@@ -0,0 +1,231 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Glyptodon LLC
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A service for performing useful connection group related functionaltiy.
|
||||||
|
*/
|
||||||
|
angular.module('rest').factory('legacyConnectionGroupService', ['$injector', function legacyConnectionGroupService($injector) {
|
||||||
|
|
||||||
|
var connectionGroupService = $injector.get('connectionGroupService');
|
||||||
|
var connectionService = $injector.get('connectionService');
|
||||||
|
var permissionCheckService = $injector.get('permissionCheckService');
|
||||||
|
var $q = $injector.get('$q');
|
||||||
|
var displayObjectPreparationService = $injector.get('displayObjectPreparationService');
|
||||||
|
|
||||||
|
var service = {};
|
||||||
|
|
||||||
|
// Add all groups from this group to the parent group child list
|
||||||
|
function addToParent(connectionGroup, parentGroup, context, includeConnections) {
|
||||||
|
|
||||||
|
// Include connections by default
|
||||||
|
if(typeof includeConnections === 'undefined')
|
||||||
|
includeConnections = true;
|
||||||
|
|
||||||
|
parentGroup.children.push(connectionGroup);
|
||||||
|
|
||||||
|
// Prepare this group for display
|
||||||
|
displayObjectPreparationService.prepareConnectionGroup(connectionGroup);
|
||||||
|
|
||||||
|
if(includeConnections) {
|
||||||
|
// Get all connections in the group and add them under this connection group
|
||||||
|
context.openRequest();
|
||||||
|
connectionService.getConnections(connectionGroup.identifier).success(function fetchConnections(connections) {
|
||||||
|
for(var i = 0; i < connections.length; i++) {
|
||||||
|
connections[i].isConnection = true;
|
||||||
|
connectionGroup.children.push(connections[i]);
|
||||||
|
}
|
||||||
|
context.closeRequest();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get all connection groups in the group and repeat
|
||||||
|
context.openRequest();
|
||||||
|
connectionGroupService.getConnectionGroups(connectionGroup.identifier).success(function fetchConnectionGroups(connectionGroups) {
|
||||||
|
for(var i = 0; i < connectionGroups.length; i++) {
|
||||||
|
addToParent(connectionGroups[i], connectionGroup, context, includeConnections);
|
||||||
|
}
|
||||||
|
context.closeRequest();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queries all connections and connection groups under the connection group
|
||||||
|
* with the provided parent ID, and returns them in a heirarchical structure
|
||||||
|
* with convinient display properties set on the objects.
|
||||||
|
*
|
||||||
|
* @param {array} items The root list of connections and groups. Should be an
|
||||||
|
* initally empty array that will get filled in as the
|
||||||
|
* connections and groups are loaded.
|
||||||
|
*
|
||||||
|
* @param {string} parentID The parent ID for the connection group.
|
||||||
|
* If not passed in, it will begin with
|
||||||
|
* the root connection group.
|
||||||
|
*
|
||||||
|
* @param {boolean} includeConnections Whether or not to include connections
|
||||||
|
* in the structure. Defaults to true.
|
||||||
|
*
|
||||||
|
* @param {boolean} includeRoot Whether or not to include the root connection group
|
||||||
|
* in the structure. Defaults to false.
|
||||||
|
*
|
||||||
|
* @return {promise} A promise that will be fulfilled when all connections
|
||||||
|
* and groups have been loaded.
|
||||||
|
*/
|
||||||
|
service.getAllGroupsAndConnections = function getAllGroupsAndConnections(items, parentID, includeConnections, includeRoot) {
|
||||||
|
|
||||||
|
// Include connections by default
|
||||||
|
if(typeof includeConnections === 'undefined')
|
||||||
|
includeConnections = true;
|
||||||
|
|
||||||
|
var context = {
|
||||||
|
// The number of requets to the server currently open
|
||||||
|
openRequests : 0,
|
||||||
|
|
||||||
|
// Create the promise
|
||||||
|
finishedFetching : $q.defer(),
|
||||||
|
|
||||||
|
// Notify the caller that the promise has been completed
|
||||||
|
complete : function complete() {
|
||||||
|
this.finishedFetching.resolve(items);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicate that a request has been started.
|
||||||
|
*/
|
||||||
|
openRequest : function openRequest() {
|
||||||
|
this.openRequests++;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicate that a request has been completed. If this was the last
|
||||||
|
* open request, fulfill the promise.
|
||||||
|
*/
|
||||||
|
closeRequest : function closeRequest() {
|
||||||
|
if(--this.openRequests === 0)
|
||||||
|
this.complete();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Include the root only if it was asked for
|
||||||
|
if(includeRoot) {
|
||||||
|
context.openRequest();
|
||||||
|
connectionGroupService.getConnectionGroup(parentID).success(function setRootGroup (rootGroup) {
|
||||||
|
items.push(rootGroup);
|
||||||
|
rootGroup.children = [];
|
||||||
|
getChildrenOfRootGroup(rootGroup.children);
|
||||||
|
context.closeRequest();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
getChildrenOfRootGroup(items);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the children of the root group
|
||||||
|
function getChildrenOfRootGroup(children) {
|
||||||
|
context.openRequest();
|
||||||
|
connectionGroupService.getConnectionGroups(parentID).success(function fetchRootConnectionGroups(connectionGroups) {
|
||||||
|
for(var i = 0; i < connectionGroups.length; i++) {
|
||||||
|
addToParent(connectionGroups[i], {children: children}, context, includeConnections);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(includeConnections) {
|
||||||
|
// Get all connections in the root group and add them under this connection group
|
||||||
|
context.openRequest();
|
||||||
|
connectionService.getConnections().success(function fetchRootConnections(connections) {
|
||||||
|
for(var i = 0; i < connections.length; i++) {
|
||||||
|
|
||||||
|
// Prepare this connection for display
|
||||||
|
displayObjectPreparationService.prepareConnection(connections[i]);
|
||||||
|
|
||||||
|
children.push(connections[i]);
|
||||||
|
}
|
||||||
|
context.closeRequest();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
context.closeRequest();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the promise
|
||||||
|
return context.finishedFetching.promise;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters the list of connections and groups using the provided permissions.
|
||||||
|
*
|
||||||
|
* @param {array} items The heirarchical list of groups and connections.
|
||||||
|
*
|
||||||
|
* @param {object} permissionList The list of permissions to use
|
||||||
|
* when filtering.
|
||||||
|
*
|
||||||
|
* @param {object} permissionCriteria A map of object type to permission type(s)
|
||||||
|
* required for that object type.
|
||||||
|
*
|
||||||
|
* @return {array} The filtered list.
|
||||||
|
*/
|
||||||
|
service.filterConnectionsAndGroupByPermission = function filterConnectionsAndGroupByPermission(items, permissionList, permissionCriteria) {
|
||||||
|
var requiredConnectionPermission = permissionCriteria.CONNECTION;
|
||||||
|
var requiredConnectionGroupPermission = permissionCriteria.CONNECTION_GROUP;
|
||||||
|
|
||||||
|
for(var i = 0; i < items.length; i++) {
|
||||||
|
var item = items[i];
|
||||||
|
|
||||||
|
if(item.isConnection && requiredConnectionPermission) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If item is a connection and a permission is required for this
|
||||||
|
* item, check now to see if the permission exists. If not,
|
||||||
|
* remove the item.
|
||||||
|
*/
|
||||||
|
if(!permissionCheckService.checkPermission(permissionList,
|
||||||
|
"CONNECTION", item.identifier, requiredConnectionPermission)) {
|
||||||
|
items.splice(i, 1);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If item is a group and a permission is required for this
|
||||||
|
* item, check now to see if the permission exists. If not,
|
||||||
|
* remove the item.
|
||||||
|
*/
|
||||||
|
if(requiredConnectionGroupPermission) {
|
||||||
|
if(!permissionCheckService.checkPermission(permissionList,
|
||||||
|
"CONNECTION_GROUP", item.identifier, requiredConnectionGroupPermission)) {
|
||||||
|
items.splice(i, 1);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter the children of this connection group as well
|
||||||
|
if(item.children && item.children.length)
|
||||||
|
service.filterConnectionsAndGroupByPermission(items.children);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return items;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
return service;
|
||||||
|
}]);
|
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Glyptodon LLC
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A service for performing useful user related functionaltiy.
|
||||||
|
*/
|
||||||
|
angular.module('rest').factory('legacyUserService', ['$injector', function legacyUserService($injector) {
|
||||||
|
|
||||||
|
var permissionCheckService = $injector.get('permissionCheckService');
|
||||||
|
|
||||||
|
var service = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters the list of users using the provided permissions.
|
||||||
|
*
|
||||||
|
* @param {array} users The user list.
|
||||||
|
*
|
||||||
|
* @param {object} permissionList The list of permissions to use
|
||||||
|
* when filtering.
|
||||||
|
*
|
||||||
|
* @param {object} permissionCriteria The required permission for each user.
|
||||||
|
*
|
||||||
|
* @return {array} The filtered list.
|
||||||
|
*/
|
||||||
|
service.filterUsersByPermission = function filterUsersByPermission(users, permissionList, permissionCriteria) {
|
||||||
|
for(var i = 0; i < users.length; i++) {
|
||||||
|
if(!permissionCheckService.checkPermission(permissionList,
|
||||||
|
"USER", user.username, permissionCriteria)) {
|
||||||
|
items.splice(i, 1);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return users;
|
||||||
|
};
|
||||||
|
|
||||||
|
return service;
|
||||||
|
}]);
|
@@ -21,10 +21,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The DAO for permission operations agains the REST API.
|
* Service for operating on user permissions via the REST API.
|
||||||
*/
|
*/
|
||||||
angular.module('rest').factory('permissionDAO', ['$http', 'authenticationService',
|
angular.module('rest').factory('permissionService', ['$http', 'authenticationService',
|
||||||
function permissionDAO($http, authenticationService) {
|
function permissionService($http, authenticationService) {
|
||||||
|
|
||||||
var service = {};
|
var service = {};
|
||||||
|
|
@@ -21,9 +21,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The DAO for protocol operations agains the REST API.
|
* Service for operating on protocol metadata via the REST API.
|
||||||
*/
|
*/
|
||||||
angular.module('rest').factory('protocolDAO', ['$http', function protocolDAO($http) {
|
angular.module('rest').factory('protocolService', ['$http', function protocolService($http) {
|
||||||
|
|
||||||
var service = {};
|
var service = {};
|
||||||
|
|
@@ -1,100 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2014 Glyptodon LLC
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The DAO for connection operations agains the REST API.
|
|
||||||
*/
|
|
||||||
angular.module('rest').factory('userDAO', ['$http', 'authenticationService',
|
|
||||||
function userDAO($http, authenticationService) {
|
|
||||||
|
|
||||||
var service = {};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Makes a request to the REST API to get the list of users,
|
|
||||||
* returning a promise that can be used for processing the results of the call.
|
|
||||||
*
|
|
||||||
* @returns {promise} A promise for the HTTP call.
|
|
||||||
*/
|
|
||||||
service.getUsers = function getUsers() {
|
|
||||||
return $http.get("api/user?token=" + authenticationService.getCurrentToken());
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Makes a request to the REST API to get the list of users,
|
|
||||||
* returning a promise that can be used for processing the results of the call.
|
|
||||||
*
|
|
||||||
* @param {string} userID The ID of the user to retrieve.
|
|
||||||
*
|
|
||||||
* @returns {promise} A promise for the HTTP call.
|
|
||||||
*/
|
|
||||||
service.getUser = function getUser(userID) {
|
|
||||||
return $http.get("api/user/" + userID + "/?token=" + authenticationService.getCurrentToken());
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Makes a request to the REST API to delete a user,
|
|
||||||
* returning a promise that can be used for processing the results of the call.
|
|
||||||
*
|
|
||||||
* @param {object} user The user to delete.
|
|
||||||
*
|
|
||||||
* @returns {promise} A promise for the HTTP call.
|
|
||||||
*/
|
|
||||||
service.deleteUser = function deleteUser(user) {
|
|
||||||
return $http['delete'](
|
|
||||||
"api/user/" + user.username +
|
|
||||||
"?token=" + authenticationService.getCurrentToken());
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Makes a request to the REST API to create a user,
|
|
||||||
* returning a promise that can be used for processing the results of the call.
|
|
||||||
*
|
|
||||||
* @param {object} user The user to create.
|
|
||||||
*
|
|
||||||
* @returns {promise} A promise for the HTTP call.
|
|
||||||
*/
|
|
||||||
service.createUser = function createUser(user) {
|
|
||||||
return $http.post(
|
|
||||||
"api/user/"
|
|
||||||
+ "?token=" + authenticationService.getCurrentToken(),
|
|
||||||
user
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Makes a request to the REST API to save a user,
|
|
||||||
* returning a promise that can be used for processing the results of the call.
|
|
||||||
*
|
|
||||||
* @param {object} user The user to update.
|
|
||||||
*
|
|
||||||
* @returns {promise} A promise for the HTTP call.
|
|
||||||
*/
|
|
||||||
service.saveUser = function saveUser(user) {
|
|
||||||
return $http.post(
|
|
||||||
"api/user/" + user.username +
|
|
||||||
"?token=" + authenticationService.getCurrentToken(),
|
|
||||||
user);
|
|
||||||
};
|
|
||||||
|
|
||||||
return service;
|
|
||||||
}]);
|
|
@@ -21,36 +21,79 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A service for performing useful user related functionaltiy.
|
* Service for operating on users via the REST API.
|
||||||
*/
|
*/
|
||||||
angular.module('rest').factory('userService', ['$injector', function userService($injector) {
|
angular.module('rest').factory('userService', ['$http', 'authenticationService',
|
||||||
|
function userService($http, authenticationService) {
|
||||||
var permissionCheckService = $injector.get('permissionCheckService');
|
|
||||||
|
|
||||||
var service = {};
|
var service = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filters the list of users using the provided permissions.
|
* Makes a request to the REST API to get the list of users,
|
||||||
|
* returning a promise that can be used for processing the results of the call.
|
||||||
*
|
*
|
||||||
* @param {array} users The user list.
|
* @returns {promise} A promise for the HTTP call.
|
||||||
*
|
|
||||||
* @param {object} permissionList The list of permissions to use
|
|
||||||
* when filtering.
|
|
||||||
*
|
|
||||||
* @param {object} permissionCriteria The required permission for each user.
|
|
||||||
*
|
|
||||||
* @return {array} The filtered list.
|
|
||||||
*/
|
*/
|
||||||
service.filterUsersByPermission = function filterUsersByPermission(users, permissionList, permissionCriteria) {
|
service.getUsers = function getUsers() {
|
||||||
for(var i = 0; i < users.length; i++) {
|
return $http.get("api/user?token=" + authenticationService.getCurrentToken());
|
||||||
if(!permissionCheckService.checkPermission(permissionList,
|
};
|
||||||
"USER", user.username, permissionCriteria)) {
|
|
||||||
items.splice(i, 1);
|
/**
|
||||||
continue;
|
* Makes a request to the REST API to get the list of users,
|
||||||
}
|
* returning a promise that can be used for processing the results of the call.
|
||||||
|
*
|
||||||
|
* @param {string} userID The ID of the user to retrieve.
|
||||||
|
*
|
||||||
|
* @returns {promise} A promise for the HTTP call.
|
||||||
|
*/
|
||||||
|
service.getUser = function getUser(userID) {
|
||||||
|
return $http.get("api/user/" + userID + "/?token=" + authenticationService.getCurrentToken());
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes a request to the REST API to delete a user,
|
||||||
|
* returning a promise that can be used for processing the results of the call.
|
||||||
|
*
|
||||||
|
* @param {object} user The user to delete.
|
||||||
|
*
|
||||||
|
* @returns {promise} A promise for the HTTP call.
|
||||||
|
*/
|
||||||
|
service.deleteUser = function deleteUser(user) {
|
||||||
|
return $http['delete'](
|
||||||
|
"api/user/" + user.username +
|
||||||
|
"?token=" + authenticationService.getCurrentToken());
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes a request to the REST API to create a user,
|
||||||
|
* returning a promise that can be used for processing the results of the call.
|
||||||
|
*
|
||||||
|
* @param {object} user The user to create.
|
||||||
|
*
|
||||||
|
* @returns {promise} A promise for the HTTP call.
|
||||||
|
*/
|
||||||
|
service.createUser = function createUser(user) {
|
||||||
|
return $http.post(
|
||||||
|
"api/user/"
|
||||||
|
+ "?token=" + authenticationService.getCurrentToken(),
|
||||||
|
user
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return users;
|
/**
|
||||||
|
* Makes a request to the REST API to save a user,
|
||||||
|
* returning a promise that can be used for processing the results of the call.
|
||||||
|
*
|
||||||
|
* @param {object} user The user to update.
|
||||||
|
*
|
||||||
|
* @returns {promise} A promise for the HTTP call.
|
||||||
|
*/
|
||||||
|
service.saveUser = function saveUser(user) {
|
||||||
|
return $http.post(
|
||||||
|
"api/user/" + user.username +
|
||||||
|
"?token=" + authenticationService.getCurrentToken(),
|
||||||
|
user);
|
||||||
};
|
};
|
||||||
|
|
||||||
return service;
|
return service;
|
||||||
|
Reference in New Issue
Block a user