Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/app/groups/group-edit-dialog.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module.controller('groups.GroupEditDialogController', [
'$scope',
'$uibModalInstance',
'GroupService',
'Alert',
'parentScope',
function ($scope, $modalInstance, GroupService, $alert, parentScope) {
$scope.group = {};
// true if group is being saved.
$scope.isLoading = false;

/**
* Close dialog
*/
$scope.close = function () {
$modalInstance.close();
};

/**
* Create or updates the user SSO profile.
*/
$scope.save = function () {
$scope.isLoading = true;
GroupService
.create($scope.group)
.then(function (data) {
parentScope.fetch();
$scope.close();
})
.catch(function (error) {
$alert.error(error.error, $scope);
})
. finally(function () {
$scope.isLoading = false;
});
}
}
]);
33 changes: 33 additions & 0 deletions src/app/groups/group-edit-dialog.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<div class="inmodal">
<div class="modal-header">
<button type="button" class="close" aria-label="Close" ng-click="close()"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="reg-dialog-label">Add Group</h4>
</div>
<div class="modal-body">
<div class="row">
<form role="form" name="groupForm">
<div class="col-md-12" ng-include src="'components/alert/alert.html'"></div>
<div class="form-group" ng-class="{'has-error': groupForm.name.$touched && groupForm.name.$invalid}">
<label>Name</label>
<input ng-model="group.name" name="name" type="text" class="form-control" required>
</div>
<div class="form-group">
<label>Description</label>
<textarea ng-model="group.description" class="form-control"></textarea>
</div>
</form>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-white" ng-click="close()" ng-disabed="isLoading">
Close
</button>
<button type="button" class="btn btn-primary" ng-click="save()" ng-disabled="groupForm.$invalid || isLoading">
Save
</button>
</div>
<div style="text-align:center;position:absolute;top:65px;left:0;width:100%;height:100%;zIndex:1;"
ng-show="isLoading">
<img src="assets/images/loading.gif"/>
</div>
</div>
15 changes: 13 additions & 2 deletions src/app/groups/groups.list.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
var module = angular.module('supportAdminApp');

module.controller('permissionmanagement.GroupsListController', [
'$scope', '$rootScope', 'GroupService', 'UserService', 'IdResolverService', 'Alert', '$timeout',
function ($scope, $rootScope, GroupService, UserService, IdResolverService, $alert, $timeout) {
'$scope', '$rootScope', 'GroupService', 'UserService', 'IdResolverService', 'Alert', '$timeout', '$uibModal',
function ($scope, $rootScope, GroupService, UserService, IdResolverService, $alert, $timeout, $modal) {

// true data is loading
$scope.isLoading = false;
Expand Down Expand Up @@ -51,5 +51,16 @@ module.controller('permissionmanagement.GroupsListController', [

// load the groups on controller init
$scope.fetch();

$scope.openGroupEditDialog = function(index) {
var modalInstance = $modal.open({
size: 'sm',
templateUrl: 'app/groups/group-edit-dialog.html',
controller: 'groups.GroupEditDialogController',
resolve: {
parentScope: function(){ return $scope; }
}
});
};
}
]);
3 changes: 3 additions & 0 deletions src/app/groups/groups.list.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
<div class="text-center" ng-show="isLoading">
<img src="assets/images/loading.gif" />
</div>
<button type="submit" class="btn btn-sm btn-info" ng-click="openGroupEditDialog()">
<strong><i class="fa fa-plus"></i> New Group</strong>
</button>
<div ng-show="!isLoading" class="table-responsive">
<table class="footable table table-stripped toggle-arrow-tiny" ng-show="groups.length" data-page-size="50">
<thead>
Expand Down
59 changes: 59 additions & 0 deletions src/app/groups/groups.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,65 @@ angular.module('supportAdminApp')
}).catch(GroupService.handleError);
};

/**
* Creates a group
* @param {Object} group The group.
*/
GroupService.create = function(group) {
var request = $http({
method: 'POST',
url: GroupService.getBasePath() + '/groups',
headers: {
"Content-Type":"application/json"
},
data: JSON.stringify({ param: group })
});

return request.then(
function(response) {
if (response && response.data && response.data.result) {
var newGroup = response.data.result.content;
var securityGroup = {id: newGroup.id, name: newGroup.name};
return GroupService.createSecurityGroup(securityGroup)
.then(function(response){}, GroupService.handleError);
} else {
return $q.reject({
error : 'Cannot find data in response'
})
}
},
GroupService.handleError
);
};

/**
* Creates a security group
* @param {Object} group The security group.
*/
GroupService.createSecurityGroup = function(group) {
var request = $http({
method: 'POST',
url: GroupService.getBasePath() + '/groups/securityGroups',
headers: {
"Content-Type":"application/json"
},
data: JSON.stringify({ param: group })
});

return request.then(
function(response) {
if (response && response.data && response.data.result) {
return response.data.result.content;
} else {
return $q.reject({
error : 'Cannot find data in response'
})
}
},
GroupService.handleError
);
};

/**
* Handle API response error
*
Expand Down
87 changes: 87 additions & 0 deletions src/app/users/sso-user-edit-dialog.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
module.controller('users.SsoUserEditDialogController', [
'$scope',
'$uibModalInstance',
'UserService',
'Alert',
'user',
'$q',
function ($scope, $modalInstance, UserService, $alert, user, $q) {

// currently selected user object
$scope.user = user;

// These are the provider types accepted in the API.
$scope.providerTypes = [
'ad',
'adfs',
'auth0',
'behance',
'bitbucket',
'dribbble',
'facebook',
'github',
'google-oauth2',
'linkedin',
'samlp',
'sfdc',
'stackoverflow',
'twitter'
];

// true if details are being loaded/saved
$scope.isLoading = false;

/**
* Close dialog
*/
$scope.close = function () {
$modalInstance.close();
};

/**
* Load user profile.
*/
$scope.loadData = function () {
$scope.isLoading = true;
UserService
.findById($scope.user.id)
.then(function (data) {
$scope.user.profile = {};
if (data.profile) {
// we can't have all properties form profile as saving will fail.
$scope.user.profile = {
userId: data.profile.userId,
providerType: data.profile.providerType,
provider: data.profile.provider
}
}
})
.catch(function (error) {
$alert.error(error.error, $scope);
})
. finally(function () {
$scope.isLoading = false;
});
}

/**
* Create or updates the user SSO profile.
*/
$scope.save = function () {
$scope.isLoading = true;
UserService
.createOrUpdateSSOUserLogin($scope.user.id, $scope.user.profile)
.then(function (data) {
$scope.close();
})
.catch(function (error) {
$alert.error(error.error, $scope);
})
. finally(function () {
$scope.isLoading = false;
});
}

$scope.loadData();
}
]);
38 changes: 38 additions & 0 deletions src/app/users/sso-user-edit-dialog.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<div class="inmodal">
<div class="modal-header">
<button type="button" class="close" aria-label="Close" ng-click="close()">
<span aria-hidden="true">&times;</span>
</button>
<h4 class="modal-title" id="reg-dialog-label">SSO User</h4>
</div>
<div class="modal-body">
<div class="row">
<form role="form" name="userForm">
<div class="col-md-12" ng-include src="'components/alert/alert.html'"></div>
<div class="form-group" ng-class="{'has-error': userForm.userId.$touched && userForm.userId.$invalid}">
<label>User Id</label>
<input ng-model="user.profile.userId" type="text" class="form-control" name="userId" required>
</div>
<div class="form-group">
<label>Provider type </label>
<select ng-options="provider for provider in providerTypes" class="form-control" ng-model="user.profile.providerType" disabled></select>
</div>
<div class="form-group" ng-class="{'has-error': userForm.provider.$touched && userForm.provider.$invalid}">
<label>Provider</label>
<input ng-model="user.profile.provider" type="text" class="form-control" name="provider" required>
</div>
</form>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-white" ng-click="close()" ng-disabed="isLoading">
Close
</button>
<button type="button" class="btn btn-primary" ng-click="save()" ng-disabled="userForm.$invalid || isLoading">
Save
</button>
</div>
<div style="text-align:center;position:absolute;top:65px;left:0;width:100%;height:100%;zIndex:1;" ng-show="isLoading">
<img src="assets/images/loading.gif" />
</div>
</div>
11 changes: 11 additions & 0 deletions src/app/users/users.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,17 @@ module.controller('users.UserSearchController', [
});
};

$scope.openSsoUserEditDialog = function(index) {
var modalInstance = $modal.open({
size: 'sm',
templateUrl: 'app/users/sso-user-edit-dialog.html',
controller: 'users.SsoUserEditDialogController',
resolve: {
user: function(){ return $scope.users[index]; }
}
});
};

}
]);

Expand Down
Loading