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});
47 $scope.toggleRole = function(appId, selected, availableRole) {
48 var toggleType = null;
50 toggleType = "activate";
52 toggleType = "inactivate";
54 if((availableRole.id == "1") || (availableRole.id =="999"))
56 confirmBoxService.showInformation(availableRole.name+" role cannot be disabled");
57 availableRole.active=!availableRole.active
60 else if((appId != '1') && (availableRole.name.indexOf('global_')!=-1))
62 confirmBoxService.showInformation("Global role cannot be disabled");
63 availableRole.active=!availableRole.active
66 confirmBoxService.confirm("You are about to "+toggleType+" the role "+availableRole.name+". Do you want to continue?").then(
69 var uuu = conf.api.toggleRole + '/' + appId + '/' + availableRole.id;
74 $http.post(uuu, postData).then(function(response) {
75 var data = response.data;
76 if (typeof data === 'object' & data.restcallStatus=='Success') {
77 $scope.availableRoles = data.availableRoles;
78 $log.debug('role::availableRoles:'+$scope.availableRoles);
80 confirmBoxService.showInformation("Error while saving." + data.restCallStatus);
81 availableRole.active=!availableRole.active;
84 }, function(response) {
85 debug.log('response:'+response);
86 availableRole.active=!availableRole.active;
87 confirmBoxService.showInformation("Error while saving." + data.restCallStatus);
92 }) .catch(function(err) {
93 $log.error('roleListController::confirmBoxService.confirm error:', err);
94 availableRole.active=!availableRole.active;
98 $scope.removeRole = function(appId, availableRole) {
99 if ((appId != '1') && (availableRole.name.indexOf('global_')!=-1)){
100 confirmBoxService.showInformation("Global role cannot be deleted");
103 confirmBoxService.confirm("You are about to delete the role "+availableRole.name+". Do you want to continue?").then(
105 var uuu = conf.api.removeRole + '/' + appId + '/' + availableRole.id;
108 availableRoleId: availableRole.id
110 $http.post(uuu, postData).then(function(response) {
111 var data = response.data;
112 if (typeof data === 'object' & data.restCallStatus == 'Success') {
113 $scope.availableRoles = data.availableRoles;
115 confirmBoxService.showInformation('Failed to remove role '+ data.error )
118 }, function(response) {
119 confirmBoxService.showInformation("Error while deleting: "+ data.error);
127 $scope.getCentralizedApps = function(userId) {
128 RoleService.getCentralizedApps(userId).then(res=> {
130 $scope.centralizedApps = res;
131 for(var i = 0; i<res.length; i++){
132 if(res[i].appId == 1){
133 $scope.getRolesForSelectedCentralizedApp(res[i].appId);
134 $scope.apps.selectedCentralizedApp = res[i].appId;
137 $scope.getRolesForSelectedCentralizedApp(res[0].appId);
138 $scope.apps.selectedCentralizedApp = res[0].appId;
142 $log.error('RoleListCtrl::centralizedApps retrieval error: ', err);
144 // this.isLoadingTable = false;
149 $scope.syncRolesFromExternalAuthSystem = function(appId){
150 applicationsService.syncRolesEcompFromExtAuthSystem(appId).then(function(res){
151 if(res.status == 200){
152 confirmBoxService.showInformation('Sync operation completed successfully!').then(isConfirmed => {
153 $scope.getRolesForSelectedCentralizedApp(appId);
156 confirmBoxService.showInformation('Sync operation failed for '+app).then(isConfirmed => {});
162 $scope.getRolesForSelectedCentralizedApp = function(val) {
163 $scope.showSpinner = true;
164 applicationsService.getSingleAppInfoById(val).then(function(res) {
165 if(res.centralAuth == true){
166 $scope.syncRolesApplied = true;
169 RoleService.getRoles(val).then(function(data){
171 $scope.data = JSON.parse(j.data);
172 $scope.availableRoles =$scope.data.availableRoles;
173 $scope.showSpinner = false;
176 $scope.showSpinner = false;
177 confirmBoxService.showInformation('Failed to get roles. Please try again!').then(isConfirmed => {});
178 $scope.availableRoles = [];
179 $log.debug('failed');
183 $scope.fnManageRoleFunctions = function(){
184 RoleService.setManageRoleDetails($scope.centralizedApps, $scope.apps.selectedCentralizedApp);
189 selectedCentralizedApp:''
191 $scope.getCentralizedApps(sessionStorage.userId);
197 $scope.editRoleModalPopup = function(appId, availableRole) {
198 $scope.editRole = availableRole;
199 if(appId != undefined && availableRole.id != undefined){
200 RoleService.getRole(appId, availableRole.id).then(function(data){
201 var response = JSON.parse(data.data);
202 var role = JSON.parse(response.role);
203 var availableRoles = JSON.parse(response.availableRoles);
204 var availableRoleFunctions = JSON.parse(response.availableRoleFunctions);
205 $scope.availableRoleFunctions = response.roleFunctions;
206 var modalInstance = $modal.open({
207 templateUrl: 'app/views/role/popup_createedit_role.html',
208 controller: 'roleCreateEditController',
209 sizeClass: 'modal-large',
210 windowClass: "modal-docked",
212 message: function () {
214 availableRoles: availableRoles,
215 availableRoleFunctions: availableRoleFunctions,
216 appId: $scope.apps.selectedCentralizedApp,
223 modalInstance.result.then(function (confirmed) {
224 if(confirmed == 'confirmed'){
225 $scope.getRolesForSelectedCentralizedApp(appId);
229 $log.debug('Failed to editRole');
236 $scope.addRoleModalPopup = function(appId) {
239 RoleService.getRole(appId, roleId).then(function(data){
240 var response = JSON.parse(data.data);
241 var role = JSON.parse(response.role);
242 var availableRoles = JSON.parse(response.availableRoles);
243 var availableRoleFunctions = JSON.parse(response.availableRoleFunctions);
244 $scope.availableRoleFunctions = response.roleFunctions;
245 var modalInstance = $modal.open({
246 templateUrl: 'app/views/role/popup_createedit_role.html',
247 controller: 'roleCreateEditController',
248 sizeClass: 'modal-large',
249 windowClass: "modal-docked",
251 message: function () {
254 appId: $scope.apps.selectedCentralizedApp
260 modalInstance.result.then(function (confirmed) {
261 if(confirmed == 'confirmed'){
262 $scope.getRolesForSelectedCentralizedApp(appId);
266 $log.debug('Failed to AddRole');