2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2017 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.status == 200){
174 confirmBoxService.showInformation('Sync operation completed successfully!').then(isConfirmed => {
175 $scope.getRolesForSelectedCentralizedApp(appId);
178 confirmBoxService.showInformation('Sync operation failed for '+app).then(isConfirmed => {});
184 $scope.getRolesForSelectedCentralizedApp = function(val) {
185 $scope.showSpinner = true;
186 applicationsService.getSingleAppInfoById(val).then(function(res) {
187 if(res.centralAuth == true){
188 $scope.syncRolesApplied = true;
191 RoleService.getRoles(val).then(function(data){
193 $scope.data = JSON.parse(j.data);
194 $scope.availableRoles =$scope.data.availableRoles;
195 $scope.showSpinner = false;
198 $scope.showSpinner = false;
199 confirmBoxService.showInformation('Failed to get roles. Please try again!').then(isConfirmed => {});
200 $scope.availableRoles = [];
201 $log.debug('failed');
205 $scope.fnManageRoleFunctions = function(){
206 RoleService.setManageRoleDetails($scope.centralizedApps, $scope.apps.selectedCentralizedApp);
211 selectedCentralizedApp:''
213 $scope.getCentralizedApps(sessionStorage.userId);
219 $scope.editRoleModalPopup = function(appId, availableRole) {
220 $scope.editRole = availableRole;
221 if(appId != undefined && availableRole.id != undefined){
222 RoleService.getRole(appId, availableRole.id).then(function(data){
223 var response = JSON.parse(data.data);
224 var role = JSON.parse(response.role);
225 var availableRoles = JSON.parse(response.availableRoles);
226 var availableRoleFunctions = JSON.parse(response.availableRoleFunctions);
227 $scope.availableRoleFunctions = response.roleFunctions;
228 var modalInstance = $modal.open({
229 templateUrl: 'app/views/role/popup_createedit_role.html',
230 controller: 'roleCreateEditController',
231 sizeClass: 'modal-large',
232 windowClass: "modal-docked",
234 message: function () {
236 availableRoles: availableRoles,
237 availableRoleFunctions: availableRoleFunctions,
238 appId: $scope.apps.selectedCentralizedApp,
245 modalInstance.result.then(function (confirmed) {
246 if(confirmed == 'confirmed'){
247 $scope.getRolesForSelectedCentralizedApp(appId);
251 $log.debug('Failed to editRole');
258 $scope.addRoleModalPopup = function(appId) {
261 RoleService.getRole(appId, roleId).then(function(data){
262 var response = JSON.parse(data.data);
263 var role = JSON.parse(response.role);
264 var availableRoles = JSON.parse(response.availableRoles);
265 var availableRoleFunctions = JSON.parse(response.availableRoleFunctions);
266 $scope.availableRoleFunctions = response.roleFunctions;
267 var modalInstance = $modal.open({
268 templateUrl: 'app/views/role/popup_createedit_role.html',
269 controller: 'roleCreateEditController',
270 sizeClass: 'modal-large',
271 windowClass: "modal-docked",
273 message: function () {
276 appId: $scope.apps.selectedCentralizedApp
282 modalInstance.result.then(function (confirmed) {
283 if(confirmed == 'confirmed'){
284 $scope.getRolesForSelectedCentralizedApp(appId);
288 $log.debug('Failed to AddRole');