Skip to content

Commit f947520

Browse files
authored
Merge pull request #100 from topcoder-platform/dev
group and sso management features - part 1
2 parents 79440f2 + d4f9e71 commit f947520

11 files changed

+496
-231
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
module.controller('groups.GroupEditDialogController', [
2+
'$scope',
3+
'$uibModalInstance',
4+
'GroupService',
5+
'Alert',
6+
'parentScope',
7+
function ($scope, $modalInstance, GroupService, $alert, parentScope) {
8+
$scope.group = {};
9+
// true if group is being saved.
10+
$scope.isLoading = false;
11+
12+
/**
13+
* Close dialog
14+
*/
15+
$scope.close = function () {
16+
$modalInstance.close();
17+
};
18+
19+
/**
20+
* Create or updates the user SSO profile.
21+
*/
22+
$scope.save = function () {
23+
$scope.isLoading = true;
24+
GroupService
25+
.create($scope.group)
26+
.then(function (data) {
27+
parentScope.fetch();
28+
$scope.close();
29+
})
30+
.catch(function (error) {
31+
$alert.error(error.error, $scope);
32+
})
33+
. finally(function () {
34+
$scope.isLoading = false;
35+
});
36+
}
37+
}
38+
]);

src/app/groups/group-edit-dialog.html

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<div class="inmodal">
2+
<div class="modal-header">
3+
<button type="button" class="close" aria-label="Close" ng-click="close()"><span aria-hidden="true">&times;</span></button>
4+
<h4 class="modal-title" id="reg-dialog-label">Add Group</h4>
5+
</div>
6+
<div class="modal-body">
7+
<div class="row">
8+
<form role="form" name="groupForm">
9+
<div class="col-md-12" ng-include src="'components/alert/alert.html'"></div>
10+
<div class="form-group" ng-class="{'has-error': groupForm.name.$touched && groupForm.name.$invalid}">
11+
<label>Name</label>
12+
<input ng-model="group.name" name="name" type="text" class="form-control" required>
13+
</div>
14+
<div class="form-group">
15+
<label>Description</label>
16+
<textarea ng-model="group.description" class="form-control"></textarea>
17+
</div>
18+
</form>
19+
</div>
20+
</div>
21+
<div class="modal-footer">
22+
<button type="button" class="btn btn-white" ng-click="close()" ng-disabed="isLoading">
23+
Close
24+
</button>
25+
<button type="button" class="btn btn-primary" ng-click="save()" ng-disabled="groupForm.$invalid || isLoading">
26+
Save
27+
</button>
28+
</div>
29+
<div style="text-align:center;position:absolute;top:65px;left:0;width:100%;height:100%;zIndex:1;"
30+
ng-show="isLoading">
31+
<img src="assets/images/loading.gif"/>
32+
</div>
33+
</div>

src/app/groups/groups.list.controller.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
var module = angular.module('supportAdminApp');
44

55
module.controller('permissionmanagement.GroupsListController', [
6-
'$scope', '$rootScope', 'GroupService', 'UserService', 'IdResolverService', 'Alert', '$timeout',
7-
function ($scope, $rootScope, GroupService, UserService, IdResolverService, $alert, $timeout) {
6+
'$scope', '$rootScope', 'GroupService', 'UserService', 'IdResolverService', 'Alert', '$timeout', '$uibModal',
7+
function ($scope, $rootScope, GroupService, UserService, IdResolverService, $alert, $timeout, $modal) {
88

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

5252
// load the groups on controller init
5353
$scope.fetch();
54+
55+
$scope.openGroupEditDialog = function(index) {
56+
var modalInstance = $modal.open({
57+
size: 'sm',
58+
templateUrl: 'app/groups/group-edit-dialog.html',
59+
controller: 'groups.GroupEditDialogController',
60+
resolve: {
61+
parentScope: function(){ return $scope; }
62+
}
63+
});
64+
};
5465
}
5566
]);

src/app/groups/groups.list.html

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
<div class="text-center" ng-show="isLoading">
77
<img src="assets/images/loading.gif" />
88
</div>
9+
<button type="submit" class="btn btn-sm btn-info" ng-click="openGroupEditDialog()">
10+
<strong><i class="fa fa-plus"></i> New Group</strong>
11+
</button>
912
<div ng-show="!isLoading" class="table-responsive">
1013
<table class="footable table table-stripped toggle-arrow-tiny" ng-show="groups.length" data-page-size="50">
1114
<thead>

src/app/groups/groups.service.js

+59
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,65 @@ angular.module('supportAdminApp')
7979
}).catch(GroupService.handleError);
8080
};
8181

82+
/**
83+
* Creates a group
84+
* @param {Object} group The group.
85+
*/
86+
GroupService.create = function(group) {
87+
var request = $http({
88+
method: 'POST',
89+
url: GroupService.getBasePath() + '/groups',
90+
headers: {
91+
"Content-Type":"application/json"
92+
},
93+
data: JSON.stringify({ param: group })
94+
});
95+
96+
return request.then(
97+
function(response) {
98+
if (response && response.data && response.data.result) {
99+
var newGroup = response.data.result.content;
100+
var securityGroup = {id: newGroup.id, name: newGroup.name};
101+
return GroupService.createSecurityGroup(securityGroup)
102+
.then(function(response){}, GroupService.handleError);
103+
} else {
104+
return $q.reject({
105+
error : 'Cannot find data in response'
106+
})
107+
}
108+
},
109+
GroupService.handleError
110+
);
111+
};
112+
113+
/**
114+
* Creates a security group
115+
* @param {Object} group The security group.
116+
*/
117+
GroupService.createSecurityGroup = function(group) {
118+
var request = $http({
119+
method: 'POST',
120+
url: GroupService.getBasePath() + '/groups/securityGroups',
121+
headers: {
122+
"Content-Type":"application/json"
123+
},
124+
data: JSON.stringify({ param: group })
125+
});
126+
127+
return request.then(
128+
function(response) {
129+
if (response && response.data && response.data.result) {
130+
return response.data.result.content;
131+
} else {
132+
return $q.reject({
133+
error : 'Cannot find data in response'
134+
})
135+
}
136+
},
137+
GroupService.handleError
138+
);
139+
};
140+
82141
/**
83142
* Handle API response error
84143
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
module.controller('users.SsoUserEditDialogController', [
2+
'$scope',
3+
'$uibModalInstance',
4+
'UserService',
5+
'Alert',
6+
'user',
7+
'$q',
8+
function ($scope, $modalInstance, UserService, $alert, user, $q) {
9+
10+
// currently selected user object
11+
$scope.user = user;
12+
13+
// These are the provider types accepted in the API.
14+
$scope.providerTypes = [
15+
'ad',
16+
'adfs',
17+
'auth0',
18+
'behance',
19+
'bitbucket',
20+
'dribbble',
21+
'facebook',
22+
'github',
23+
'google-oauth2',
24+
'linkedin',
25+
'samlp',
26+
'sfdc',
27+
'stackoverflow',
28+
'twitter'
29+
];
30+
31+
// true if details are being loaded/saved
32+
$scope.isLoading = false;
33+
34+
/**
35+
* Close dialog
36+
*/
37+
$scope.close = function () {
38+
$modalInstance.close();
39+
};
40+
41+
/**
42+
* Load user profile.
43+
*/
44+
$scope.loadData = function () {
45+
$scope.isLoading = true;
46+
UserService
47+
.findById($scope.user.id)
48+
.then(function (data) {
49+
$scope.user.profile = {};
50+
if (data.profile) {
51+
// we can't have all properties form profile as saving will fail.
52+
$scope.user.profile = {
53+
userId: data.profile.userId,
54+
providerType: data.profile.providerType,
55+
provider: data.profile.provider
56+
}
57+
}
58+
})
59+
.catch(function (error) {
60+
$alert.error(error.error, $scope);
61+
})
62+
. finally(function () {
63+
$scope.isLoading = false;
64+
});
65+
}
66+
67+
/**
68+
* Create or updates the user SSO profile.
69+
*/
70+
$scope.save = function () {
71+
$scope.isLoading = true;
72+
UserService
73+
.createOrUpdateSSOUserLogin($scope.user.id, $scope.user.profile)
74+
.then(function (data) {
75+
$scope.close();
76+
})
77+
.catch(function (error) {
78+
$alert.error(error.error, $scope);
79+
})
80+
. finally(function () {
81+
$scope.isLoading = false;
82+
});
83+
}
84+
85+
$scope.loadData();
86+
}
87+
]);
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<div class="inmodal">
2+
<div class="modal-header">
3+
<button type="button" class="close" aria-label="Close" ng-click="close()">
4+
<span aria-hidden="true">&times;</span>
5+
</button>
6+
<h4 class="modal-title" id="reg-dialog-label">SSO User</h4>
7+
</div>
8+
<div class="modal-body">
9+
<div class="row">
10+
<form role="form" name="userForm">
11+
<div class="col-md-12" ng-include src="'components/alert/alert.html'"></div>
12+
<div class="form-group" ng-class="{'has-error': userForm.userId.$touched && userForm.userId.$invalid}">
13+
<label>User Id</label>
14+
<input ng-model="user.profile.userId" type="text" class="form-control" name="userId" required>
15+
</div>
16+
<div class="form-group">
17+
<label>Provider type </label>
18+
<select ng-options="provider for provider in providerTypes" class="form-control" ng-model="user.profile.providerType" disabled></select>
19+
</div>
20+
<div class="form-group" ng-class="{'has-error': userForm.provider.$touched && userForm.provider.$invalid}">
21+
<label>Provider</label>
22+
<input ng-model="user.profile.provider" type="text" class="form-control" name="provider" required>
23+
</div>
24+
</form>
25+
</div>
26+
</div>
27+
<div class="modal-footer">
28+
<button type="button" class="btn btn-white" ng-click="close()" ng-disabed="isLoading">
29+
Close
30+
</button>
31+
<button type="button" class="btn btn-primary" ng-click="save()" ng-disabled="userForm.$invalid || isLoading">
32+
Save
33+
</button>
34+
</div>
35+
<div style="text-align:center;position:absolute;top:65px;left:0;width:100%;height:100%;zIndex:1;" ng-show="isLoading">
36+
<img src="assets/images/loading.gif" />
37+
</div>
38+
</div>

src/app/users/users.controller.js

+11
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,17 @@ module.controller('users.UserSearchController', [
199199
});
200200
};
201201

202+
$scope.openSsoUserEditDialog = function(index) {
203+
var modalInstance = $modal.open({
204+
size: 'sm',
205+
templateUrl: 'app/users/sso-user-edit-dialog.html',
206+
controller: 'users.SsoUserEditDialogController',
207+
resolve: {
208+
user: function(){ return $scope.users[index]; }
209+
}
210+
});
211+
};
212+
202213
}
203214
]);
204215

0 commit comments

Comments
 (0)