update canAdd and move org admin scope var off of rootScope

This commit is contained in:
John Mitchell
2016-09-13 16:14:26 -04:00
parent 8cff8e4202
commit a7cbfdc242
17 changed files with 101 additions and 120 deletions
-5
View File
@@ -841,11 +841,6 @@ var tower = angular.module('Tower', [
$rootScope.user_is_superuser = Authorization.getUserInfo('is_superuser');
$rootScope.user_is_system_auditor = Authorization.getUserInfo('is_system_auditor');
Rest.setUrl($rootScope.current_user.related.admin_of_organizations);
Rest.get()
.success(function(data) {
$rootScope.current_user_admin_orgs = data.results.map(i => i.name);
});
// state the user refreshes we want to open the socket, except if the user is on the login page, which should happen after the user logs in (see the AuthService module for that call to OpenSocket)
if (!_.contains($location.$$url, '/login')) {
ConfigService.getConfig().then(function() {
@@ -17,16 +17,6 @@ export function CredentialsList($scope, $rootScope, $location, $log,
SelectionInit, GetChoices, Wait, $state, $filter) {
ClearScope();
$scope.canAdd = false;
Rest.setUrl(GetBasePath('credentials'));
Rest.options()
.success(function(data) {
if (data.actions.POST) {
$scope.canAdd = true;
}
});
Wait('start');
var list = CredentialList,
@@ -148,16 +138,6 @@ export function CredentialsAdd($scope, $rootScope, $compile, $location, $log,
ReturnToCaller, ClearScope, GenerateList, SearchInit, PaginateInit,
LookUpInit, OrganizationList, GetBasePath, GetChoices, Empty, KindChange,
OwnerChange, FormSave, $state, CreateSelect2) {
Rest.setUrl(GetBasePath('credentials'));
Rest.options()
.success(function(data) {
if (!data.actions.POST) {
$state.go("^");
Alert('Permission Error', 'You do not have permission to add a credential.', 'alert-info');
}
});
ClearScope();
// Inject dynamic view
+5 -8
View File
@@ -15,17 +15,14 @@ export function ProjectsList ($scope, $rootScope, $location, $log, $stateParams,
Rest, Alert, ProjectList, GenerateList, Prompt, SearchInit,
PaginateInit, ReturnToCaller, ClearScope, ProcessErrors, GetBasePath,
SelectionInit, ProjectUpdate, Refresh, Wait, GetChoices, Empty,
Find, GetProjectIcon, GetProjectToolTip, $filter, $state) {
Find, GetProjectIcon, GetProjectToolTip, $filter, $state, rbacUiControlService) {
ClearScope();
$scope.canAdd = false;
Rest.setUrl(GetBasePath('projects'));
Rest.options()
.success(function(data) {
if (data.actions.POST) {
$scope.canAdd = true;
}
rbacUiControlService.canAdd('projects')
.then(function(canAdd) {
$scope.canAdd = canAdd;
});
Wait('start');
@@ -378,7 +375,7 @@ ProjectsList.$inject = ['$scope', '$rootScope', '$location', '$log',
'SearchInit', 'PaginateInit', 'ReturnToCaller', 'ClearScope',
'ProcessErrors', 'GetBasePath', 'SelectionInit', 'ProjectUpdate',
'Refresh', 'Wait', 'GetChoices', 'Empty', 'Find',
'GetProjectIcon', 'GetProjectToolTip', '$filter', '$state'
'GetProjectIcon', 'GetProjectToolTip', '$filter', '$state', 'rbacUiControlService'
];
+5 -8
View File
@@ -14,17 +14,14 @@
export function TeamsList($scope, $rootScope, $location, $log, $stateParams,
Rest, Alert, TeamList, GenerateList, Prompt, SearchInit, PaginateInit,
ReturnToCaller, ClearScope, ProcessErrors, SetTeamListeners, GetBasePath,
SelectionInit, Wait, $state, Refresh, $filter) {
SelectionInit, Wait, $state, Refresh, $filter, rbacUiControlService) {
ClearScope();
$scope.canAdd = false;
Rest.setUrl(GetBasePath('teams'));
Rest.options()
.success(function(data) {
if (data.actions.POST) {
$scope.canAdd = true;
}
rbacUiControlService.canAdd('teams')
.then(function(canAdd) {
$scope.canAdd = canAdd;
});
var list = TeamList,
@@ -135,7 +132,7 @@ TeamsList.$inject = ['$scope', '$rootScope', '$location', '$log',
'$stateParams', 'Rest', 'Alert', 'TeamList', 'generateList', 'Prompt',
'SearchInit', 'PaginateInit', 'ReturnToCaller', 'ClearScope',
'ProcessErrors', 'SetTeamListeners', 'GetBasePath', 'SelectionInit', 'Wait',
'$state', 'Refresh', '$filter'
'$state', 'Refresh', '$filter', 'rbacUiControlService'
];
+5 -8
View File
@@ -34,17 +34,14 @@ function user_type_sync($scope) {
export function UsersList($scope, $rootScope, $location, $log, $stateParams,
Rest, Alert, UserList, GenerateList, Prompt, SearchInit, PaginateInit,
ReturnToCaller, ClearScope, ProcessErrors, GetBasePath, SelectionInit,
Wait, $state, Refresh, $filter) {
Wait, $state, Refresh, $filter, rbacUiControlService) {
ClearScope();
$scope.canAdd = false;
Rest.setUrl(GetBasePath('users'));
Rest.options()
.success(function(data) {
if (data.actions.POST) {
$scope.canAdd = true;
}
rbacUiControlService.canAdd('users')
.then(function(canAdd) {
$scope.canAdd = canAdd;
});
var list = UserList,
@@ -145,7 +142,7 @@ UsersList.$inject = ['$scope', '$rootScope', '$location', '$log',
'$stateParams', 'Rest', 'Alert', 'UserList', 'generateList', 'Prompt',
'SearchInit', 'PaginateInit', 'ReturnToCaller', 'ClearScope',
'ProcessErrors', 'GetBasePath', 'SelectionInit', 'Wait', '$state',
'Refresh', '$filter'
'Refresh', '$filter', 'rbacUiControlService'
];
@@ -14,16 +14,13 @@ function InventoriesList($scope, $rootScope, $location, $log,
$stateParams, $compile, $filter, sanitizeFilter, Rest, Alert, InventoryList,
generateList, Prompt, SearchInit, PaginateInit, ReturnToCaller,
ClearScope, ProcessErrors, GetBasePath, Wait,
Find, Empty, $state) {
Find, Empty, $state, rbacUiControlService) {
$scope.canAdd = false;
Rest.setUrl(GetBasePath('inventory'));
Rest.options()
.success(function(data) {
if (data.actions.POST) {
$scope.canAdd = true;
}
rbacUiControlService.canAdd('inventory')
.then(function(canAdd) {
$scope.canAdd = canAdd;
});
var list = InventoryList,
@@ -386,4 +383,4 @@ function InventoriesList($scope, $rootScope, $location, $log,
export default ['$scope', '$rootScope', '$location', '$log',
'$stateParams', '$compile', '$filter', 'sanitizeFilter', 'Rest', 'Alert', 'InventoryList',
'generateList', 'Prompt', 'SearchInit', 'PaginateInit', 'ReturnToCaller',
'ClearScope', 'ProcessErrors', 'GetBasePath', 'Wait', 'Find', 'Empty', '$state', InventoriesList];
'ClearScope', 'ProcessErrors', 'GetBasePath', 'Wait', 'Find', 'Empty', '$state', 'rbacUiControlService', InventoriesList];
@@ -5,9 +5,9 @@
*************************************************/
export default
['$scope', '$rootScope', '$state', '$stateParams', 'InventoryGroups', 'generateList', 'InventoryUpdate', 'GroupManageService', 'GroupsCancelUpdate', 'ViewUpdateStatus',
'InventoryManageService', 'groupsUrl', 'SearchInit', 'PaginateInit', 'GetSyncStatusMsg', 'GetHostsStatusMsg', 'Rest', 'GetBasePath',
'InventoryManageService', 'groupsUrl', 'SearchInit', 'PaginateInit', 'GetSyncStatusMsg', 'GetHostsStatusMsg', 'Rest', 'GetBasePath', 'rbacUiControlService',
function($scope, $rootScope, $state, $stateParams, InventoryGroups, generateList, InventoryUpdate, GroupManageService, GroupsCancelUpdate, ViewUpdateStatus,
InventoryManageService, groupsUrl, SearchInit, PaginateInit, GetSyncStatusMsg, GetHostsStatusMsg, Rest, GetBasePath){
InventoryManageService, groupsUrl, SearchInit, PaginateInit, GetSyncStatusMsg, GetHostsStatusMsg, Rest, GetBasePath, rbacUiControlService){
var list = InventoryGroups,
view = generateList,
pageSize = 20;
@@ -15,12 +15,9 @@
$scope.canAdd = false;
Rest.setUrl(GetBasePath('inventory') + $scope.inventory_id + "/groups");
Rest.options()
.success(function(data) {
if (data.actions.POST) {
$scope.canAdd = true;
}
rbacUiControlService.canAdd(GetBasePath('inventory') + $scope.inventory_id + "/groups")
.then(function(canAdd) {
$scope.canAdd = canAdd;
});
@@ -5,24 +5,21 @@
*************************************************/
export default
['$scope', '$rootScope', '$state', '$stateParams', 'InventoryHosts', 'generateList', 'InventoryManageService', 'HostManageService',
'hostsUrl', 'SearchInit', 'PaginateInit', 'SetStatus', 'Prompt', 'Wait', 'inventoryData', '$filter', 'Rest', 'GetBasePath',
'hostsUrl', 'SearchInit', 'PaginateInit', 'SetStatus', 'Prompt', 'Wait', 'inventoryData', '$filter', 'Rest', 'GetBasePath', 'rbacUiControlService',
function($scope, $rootScope, $state, $stateParams, InventoryHosts, generateList, InventoryManageService, HostManageService,
hostsUrl, SearchInit, PaginateInit, SetStatus, Prompt, Wait, inventoryData, $filter, Rest, GetBasePath){
hostsUrl, SearchInit, PaginateInit, SetStatus, Prompt, Wait, inventoryData, $filter, Rest, GetBasePath, rbacUiControlService){
var list = InventoryHosts,
view = generateList,
pageSize = 20;
$scope.canAdd = false;
$scope.inventory_id = $stateParams.inventory_id;
Rest.setUrl(GetBasePath('inventory') + $scope.inventory_id + "/hosts");
Rest.options()
.success(function(data) {
if (data.actions.POST) {
$scope.canAdd = true;
}
$scope.canAdd = false;
rbacUiControlService.canAdd(GetBasePath('inventory') + $scope.inventory_id + "/hosts")
.then(function(canAdd) {
$scope.canAdd = canAdd;
});
// The ncy breadcrumb directive will look at this attribute when attempting to bind to the correct scope.
@@ -7,11 +7,11 @@
export default
[ '$rootScope','Wait', 'generateList', 'inventoryScriptsListObject',
'GetBasePath' , 'SearchInit' , 'PaginateInit', 'Rest' , 'ProcessErrors',
'Prompt', '$state', '$filter',
'Prompt', '$state', '$filter', 'rbacUiControlService',
function(
$rootScope,Wait, GenerateList, inventoryScriptsListObject,
GetBasePath, SearchInit, PaginateInit,
Rest, ProcessErrors, Prompt, $state, $filter
Rest, ProcessErrors, Prompt, $state, $filter, rbacUiControlService
) {
var scope = $rootScope.$new(),
defaultUrl = GetBasePath('inventory_scripts'),
@@ -20,12 +20,9 @@ export default
scope.canAdd = false;
Rest.setUrl(GetBasePath('inventory_scripts'));
Rest.options()
.success(function(data) {
if (data.actions.POST) {
scope.canAdd = true;
}
rbacUiControlService.canAdd("inventory_scripts")
.then(function(canAdd) {
scope.canAdd = canAdd;
});
view.inject( list, {
@@ -10,25 +10,22 @@ export default
'Prompt', 'SearchInit', 'PaginateInit', 'ReturnToCaller', 'ClearScope',
'ProcessErrors', 'GetBasePath', 'JobTemplateForm', 'CredentialList',
'LookUpInit', 'InitiatePlaybookRun', 'Wait', '$compile',
'$state', '$filter',
'$state', '$filter', 'rbacUiControlService',
function(
$scope, $rootScope, $location, $log,
$stateParams, Rest, Alert, JobTemplateList, GenerateList, Prompt,
SearchInit, PaginateInit, ReturnToCaller, ClearScope, ProcessErrors,
GetBasePath, JobTemplateForm, CredentialList, LookUpInit, InitiatePlaybookRun,
Wait, $compile, $state, $filter
Wait, $compile, $state, $filter, rbacUiControlService
) {
ClearScope();
$scope.canAdd = false;
Rest.setUrl(GetBasePath('job_templates'));
Rest.options()
.success(function(data) {
if (data.actions.POST) {
$scope.canAdd = true;
}
rbacUiControlService.canAdd("job_templates")
.then(function(canAdd) {
$scope.canAdd = canAdd;
});
var list = JobTemplateList,
+1 -2
View File
@@ -58,8 +58,7 @@ export default
ngClick: 'addCredential()',
awToolTip: 'Create a new credential',
actionClass: 'btn List-buttonSubmit',
buttonContent: '+ ADD',
ngShow: 'canAdd'
buttonContent: '+ ADD'
}
},
@@ -8,12 +8,12 @@ export default
[ '$rootScope','Wait', 'generateList', 'NotificationTemplatesList',
'GetBasePath' , 'SearchInit' , 'PaginateInit', 'Rest' ,
'ProcessErrors', 'Prompt', '$state', 'GetChoices', 'Empty', 'Find',
'ngToast', '$compile', '$filter',
'ngToast', '$compile', '$filter', 'rbacUiControlService',
function(
$rootScope,Wait, GenerateList, NotificationTemplatesList,
GetBasePath, SearchInit, PaginateInit, Rest,
ProcessErrors, Prompt, $state, GetChoices, Empty, Find, ngToast,
$compile, $filter) {
$compile, $filter, rbacUiControlService) {
var scope = $rootScope.$new(),
defaultUrl = GetBasePath('notification_templates'),
list = NotificationTemplatesList,
@@ -26,12 +26,9 @@ export default
scope.canAdd = false;
Rest.setUrl(GetBasePath('notification_templates'));
Rest.options()
.success(function(data) {
if (data.actions.POST) {
scope.canAdd = true;
}
rbacUiControlService.canAdd("notification_templates")
.then(function(canAdd) {
scope.canAdd = canAdd;
});
scope.removePostRefresh = scope.$on('PostRefresh', function () {
@@ -15,13 +15,21 @@
*/
export default ['Wait', 'GetBasePath', 'ProcessErrors', 'Rest', 'GetChoices',
'$state',
function(Wait, GetBasePath, ProcessErrors, Rest, GetChoices, $state) {
'$state', '$rootScope',
function(Wait, GetBasePath, ProcessErrors, Rest, GetChoices, $state, $rootScope) {
return function(params) {
var scope = params.scope,
url = params.url,
id = params.id;
scope.current_user_admin_orgs = [];
Rest.setUrl($rootScope.current_user.related.admin_of_organizations);
Rest.get()
.success(function(data) {
scope.current_user_admin_orgs = data.results.map(i => i.name);
});
scope.addNotificationTemplate = function(){
$state.go('notifications.add');
};
@@ -8,23 +8,20 @@ export default ['$stateParams', '$scope', '$rootScope', '$location',
'$log', '$compile', 'Rest', 'PaginateInit',
'SearchInit', 'OrganizationList', 'Alert', 'Prompt', 'ClearScope',
'ProcessErrors', 'GetBasePath', 'Wait',
'$state', 'generateList', 'Refresh', '$filter',
'$state', 'generateList', 'Refresh', '$filter', 'rbacUiControlService',
function($stateParams, $scope, $rootScope, $location,
$log, $compile, Rest, PaginateInit,
SearchInit, OrganizationList, Alert, Prompt, ClearScope,
ProcessErrors, GetBasePath, Wait,
$state, generateList, Refresh, $filter) {
$state, generateList, Refresh, $filter, rbacUiControlService) {
ClearScope();
$scope.canAdd = false;
Rest.setUrl(GetBasePath('organizations'));
Rest.options()
.success(function(data) {
if (data.actions.POST) {
$scope.canAdd = true;
}
rbacUiControlService.canAdd("organizations")
.then(function(canAdd) {
$scope.canAdd = canAdd;
});
var defaultUrl = GetBasePath('organizations'),
@@ -14,11 +14,11 @@
export default [
'$scope', '$compile', '$location', '$stateParams', 'SchedulesList', 'Rest',
'ProcessErrors', 'ReturnToCaller', 'ClearScope', 'GetBasePath', 'Wait',
'Find', 'LoadSchedulesScope', 'GetChoices', '$q', '$state',
'Find', 'LoadSchedulesScope', 'GetChoices', '$q', '$state', 'rbacUiControlService',
function ($scope, $compile, $location, $stateParams,
SchedulesList, Rest, ProcessErrors, ReturnToCaller, ClearScope,
GetBasePath, Wait, Find, LoadSchedulesScope, GetChoices,
$q, $state) {
$q, $state, rbacUiControlService) {
var schedList = _.cloneDeep(SchedulesList);
ClearScope();
@@ -51,12 +51,9 @@ export default [
$scope.canAdd = false;
Rest.setUrl(url);
Rest.options()
.success(function(data) {
if (data.actions.POST) {
$scope.canAdd = true;
}
rbacUiControlService.canAdd(url)
.then(function(canAdd) {
$scope.canAdd = canAdd;
});
schedList.well = true;
+3 -1
View File
@@ -11,12 +11,14 @@ import lodashAsPromised from './lodash-as-promised';
import stringFilters from './string-filters/main';
import truncatedText from './truncated-text.directive';
import stateExtender from './stateExtender.provider';
import rbacUiControl from './rbacUiControl';
export default
angular.module('shared', [listGenerator.name,
pagination.name,
stringFilters.name,
'ui.router'
'ui.router',
rbacUiControl.name
])
.factory('lodashAsPromised', lodashAsPromised)
.directive('truncatedText', truncatedText)
+30
View File
@@ -0,0 +1,30 @@
/*************************************************
* Copyright (c) 2015 Ansible, Inc.
*
* All Rights Reserved
*************************************************/
export default
angular.module('rbacUiControl', [])
.service('rbacUiControlService', ['$q', 'GetBasePath', 'Rest', function($q, GetBasePath, Rest){
this.canAdd = function(apiPath) {
var canAddVal = $q.defer();
if (apiPath.indexOf("api/v1") > -1) {
Rest.setUrl(apiPath);
} else {
Rest.setUrl(GetBasePath(apiPath));
}
Rest.options()
.success(function(data) {
if (data.actions.POST) {
canAddVal.resolve(true);
} else {
canAddVal.reject(false);
}
});
return canAddVal.promise;
};
}]);