wait until $rootScope.current_user is available, resolves #2126 (#2246)

This commit is contained in:
Leigh
2016-06-09 09:57:25 -04:00
parent 3e8aaa4b5e
commit f9a5955cc0

View File

@@ -178,32 +178,39 @@ export function CredentialsAdd($scope, $rootScope, $compile, $location, $log,
$scope.canShareCredential = false; $scope.canShareCredential = false;
if ($rootScope.current_user.is_superuser) { $rootScope.$watch('current_user', function(){
$scope.canShareCredential = true; try {
} else { if ($rootScope.current_user.is_superuser) {
Rest.setUrl(`/api/v1/users/${$rootScope.current_user.id}/admin_of_organizations`); $scope.canShareCredential = true;
Rest.get() } else {
.success(function(data) { Rest.setUrl(`/api/v1/users/${$rootScope.current_user.id}/admin_of_organizations`);
$scope.canShareCredential = (data.count) ? true : false; Rest.get()
}).error(function (data, status) { .success(function(data) {
ProcessErrors($scope, data, status, null, { hdr: 'Error!', msg: 'Failed to find if users is admin of org' + status }); $scope.canShareCredential = (data.count) ? true : false;
}).error(function (data, status) {
ProcessErrors($scope, data, status, null, { hdr: 'Error!', msg: 'Failed to find if users is admin of org' + status });
});
}
var orgUrl = ($rootScope.current_user.is_superuser) ?
GetBasePath("organizations") :
$rootScope.current_user.url + "admin_of_organizations?";
// Create LookUpInit for organizations
LookUpInit({
scope: $scope,
url: orgUrl,
form: form,
list: OrganizationList,
field: 'organization',
input_type: 'radio',
autopopulateLookup: false
}); });
} }
catch(err){
// $rootScope.current_user isn't available because a call to the config endpoint hasn't finished resolving yet
var orgUrl = ($rootScope.current_user.is_superuser) ? }
GetBasePath("organizations") :
$rootScope.current_user.url + "admin_of_organizations?";
// Create LookUpInit for organizations
LookUpInit({
scope: $scope,
url: orgUrl,
form: form,
list: OrganizationList,
field: 'organization',
input_type: 'radio',
autopopulateLookup: false
}); });
if (!Empty($stateParams.user_id)) { if (!Empty($stateParams.user_id)) {