2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
38 app.controller('roleListController', function ($scope,RoleService, applicationsService, confirmBoxService,conf,$state,$http,$log, $modal){
39 $scope.showSpinner = true;
40 $scope.syncRolesApplied = false;
44 $scope.goToUrl = function(roleIdVal) {
45 $state.go("root.role", {"roleId":roleIdVal});
48 $scope.toggleRole = function(appId, selected, availableRole) {
49 var toggleType = null;
51 toggleType = "activate";
53 toggleType = "inactivate";
55 if((availableRole.id == "1") || (availableRole.id =="999"))
57 confirmBoxService.showInformation(availableRole.name+" role cannot be disabled");
58 availableRole.active=!availableRole.active
61 else if((appId != '1') && (availableRole.name.indexOf('global_')!=-1))
63 confirmBoxService.showInformation("Global role cannot be disabled");
64 availableRole.active=!availableRole.active
67 confirmBoxService.confirm("You are about to "+toggleType+" the role "+availableRole.name+". Do you want to continue?").then(
70 var uuu = conf.api.toggleRole + '/' + appId + '/' + availableRole.id;
75 $http.post(uuu, postData).then(function(response) {
76 var data = response.data;
77 if (typeof data === 'object' & data.restcallStatus=='Success') {
78 $scope.availableRoles = data.availableRoles;
79 $log.debug('role::availableRoles:'+$scope.availableRoles);
81 confirmBoxService.showInformation("Error while saving." + data.restCallStatus);
82 availableRole.active=!availableRole.active;
85 }, function(response) {
86 debug.log('response:'+response);
87 availableRole.active=!availableRole.active;
88 confirmBoxService.showInformation("Error while saving." + data.restCallStatus);
93 }) .catch(function(err) {
94 $log.error('roleListController::confirmBoxService.confirm error:', err);
95 availableRole.active=!availableRole.active;
99 $scope.removeRole = function(appId, availableRole) {
100 if ((appId != '1') && (availableRole.name.indexOf('global_')!=-1)){
101 confirmBoxService.showInformation("Global role cannot be deleted");
104 confirmBoxService.confirm("You are about to delete the role "+availableRole.name+". Do you want to continue?").then(
106 var uuu = conf.api.removeRole + '/' + appId + '/' + availableRole.id;
109 availableRoleId: availableRole.id
111 $http.post(uuu, postData).then(function(response) {
112 var data = response.data;
113 if (typeof data === 'object' & data.restCallStatus == 'Success') {
114 $scope.availableRoles = data.availableRoles;
116 confirmBoxService.showInformation('Failed to remove role '+ data.error )
119 }, function(response) {
120 confirmBoxService.showInformation("Error while deleting: "+ data.error);
127 $scope.openBulkUploadRolesAndFunctionsModal = function(appId) {
128 var modalInstance = $modal.open({
129 templateUrl: 'app/views/role/bulk-upload-dialogs/bulk-upload-role-functions-modal.html',
130 controller: 'BulkRoleAndFunctionsModalCtrl as bulkRoleAndFunctions',
131 sizeClass: 'modal-medium',
133 message: function () {
141 modalInstance.result.then(function (confirmed) {
142 if(confirmed == 'confirmed'){
143 // update role list table
149 $scope.getCentralizedApps = function(userId) {
150 RoleService.getCentralizedApps(userId).then(res=> {
152 $scope.centralizedApps = res;
153 for(var i = 0; i<res.length; i++){
154 if(res[i].appId == 1){
155 $scope.getRolesForSelectedCentralizedApp(res[i].appId);
156 $scope.apps.selectedCentralizedApp = res[i].appId;
159 $scope.getRolesForSelectedCentralizedApp(res[0].appId);
160 $scope.apps.selectedCentralizedApp = res[0].appId;
164 $log.error('RoleListCtrl::centralizedApps retrieval error: ', err);
166 // this.isLoadingTable = false;
171 $scope.syncRolesFromExternalAuthSystem = function(appId){
172 applicationsService.syncRolesEcompFromExtAuthSystem(appId).then(function(res){
173 if(res.data != null || res.data.status != null || res.data.status == 'OK'){
174 confirmBoxService.showInformation('Sync operation completed successfully!').then(isConfirmed => {
175 $scope.getRolesForSelectedCentralizedApp(appId);
178 confirmBoxService.showInformation('Sync operation failed for '+app + res.data.message).then(isConfirmed => {});
181 confirmBoxService.showInformation("Sync operation failed for: " + err);
186 $scope.getRolesForSelectedCentralizedApp = function(val) {
187 $scope.showSpinner = true;
188 applicationsService.getSingleAppInfoById(val).then(function(res) {
189 if(res.centralAuth == true){
190 $scope.syncRolesApplied = true;
193 RoleService.getRoles(val).then(function(data){
195 $scope.data = JSON.parse(j.data);
196 $scope.availableRoles =$scope.data.availableRoles;
197 $scope.showSpinner = false;
200 $scope.showSpinner = false;
201 confirmBoxService.showInformation('Failed to get roles. Please try again!').then(isConfirmed => {});
202 $scope.availableRoles = [];
203 $log.debug('failed');
207 $scope.fnManageRoleFunctions = function(){
208 RoleService.setManageRoleDetails($scope.centralizedApps, $scope.apps.selectedCentralizedApp);
213 selectedCentralizedApp:''
215 $scope.getCentralizedApps(sessionStorage.userId);
221 $scope.editRoleModalPopup = function(appId, availableRole) {
222 $scope.showSpinner = true;
223 if(!availableRole.active)
224 return confirmBoxService.showInformation('Edit is diabled! Please toggle the role to activate it.').then(isConfirmed => {});
225 $scope.editRole = availableRole;
226 if(appId != undefined && availableRole.id != undefined){
227 RoleService.getRole(appId, availableRole.id).then(function(data){
228 $scope.showSpinner = false;
229 var response = JSON.parse(data.data);
230 var role = JSON.parse(response.role);
231 var availableRoles = JSON.parse(response.availableRoles);
232 var availableRoleFunctions = JSON.parse(response.availableRoleFunctions);
233 $scope.availableRoleFunctions = response.roleFunctions;
234 var modalInstance = $modal.open({
235 templateUrl: 'app/views/role/popup_createedit_role.html',
236 controller: 'roleCreateEditController',
237 sizeClass: 'modal-large',
238 windowClass: "modal-docked",
240 message: function () {
242 availableRoles: availableRoles,
243 availableRoleFunctions: availableRoleFunctions,
244 appId: $scope.apps.selectedCentralizedApp,
251 modalInstance.result.then(function (confirmed) {
252 if(confirmed == 'confirmed'){
253 $scope.getRolesForSelectedCentralizedApp(appId);
257 $log.debug('Failed to editRole');
258 $scope.showSpinner = false;
265 $scope.addRoleModalPopup = function(appId) {
266 $scope.showSpinner = true;
269 RoleService.getRole(appId, roleId).then(function(data){
270 $scope.showSpinner = false;
271 var response = JSON.parse(data.data);
272 var role = JSON.parse(response.role);
273 var availableRoles = JSON.parse(response.availableRoles);
274 var availableRoleFunctions = JSON.parse(response.availableRoleFunctions);
275 $scope.availableRoleFunctions = response.roleFunctions;
276 var modalInstance = $modal.open({
277 templateUrl: 'app/views/role/popup_createedit_role.html',
278 controller: 'roleCreateEditController',
279 sizeClass: 'modal-large',
280 windowClass: "modal-docked",
282 message: function () {
285 appId: $scope.apps.selectedCentralizedApp
291 modalInstance.result.then(function (confirmed) {
292 if(confirmed == 'confirmed'){
293 $scope.getRolesForSelectedCentralizedApp(appId);
297 $log.debug('Failed to AddRole');