Skip to content

Commit

Permalink
Update permissions, global permissions, and fix clientconfig race con…
Browse files Browse the repository at this point in the history
…dition (#252)

* Update permissions, global permissions, and fix clientconfig race condition

* Remove unused var for linting
  • Loading branch information
Ryan Lane authored Jan 10, 2020
1 parent 8086538 commit 2ef3621
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 30 deletions.
17 changes: 11 additions & 6 deletions confidant/public/modules/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,19 @@
'$scope', '$http', 'common.userinfo', 'common.clientconfig', '$log', '$transitions',
function ConfidantMainCtrl($scope, $http, userinfo, clientconfig, $log, $transitions) {

$transitions.onSuccess({}, function(transition) {
$scope.viewLocation = transition.to().data.viewLocation;
// Load the clientconfig prior to transitioning to any module, as most modules require
// the clientconfig to load, and will fail otherwise.
$transitions.onBefore({}, function() {
$scope.user = userinfo.get();
return clientconfig.get().$promise.then(function(clientConfig) {
$scope.clientconfig = clientConfig;
$http.defaults.xsrfCookieName = clientConfig.generated.xsrf_cookie_name;
});
});

$scope.user = userinfo.get();
clientconfig.get().$promise.then(function(clientConfig) {
$scope.clientconfig = clientConfig;
$http.defaults.xsrfCookieName = clientConfig.generated.xsrf_cookie_name;
// Update the view location after a successful move between modules
$transitions.onSuccess({}, function(transition) {
$scope.viewLocation = transition.to().data.viewLocation;
});

}])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,12 @@
$scope.resourceArchive = ResourceArchiveService.getResourceArchive();
}
});
// TODO: There's a race condition here, for some reason. We need to figure out how to
// wait until the clientconfig is loaded before calling this. For now we're using a gross
// timeout hack. client_config endpoint is fast, so it's very likely it'll be loaded within
// the time period
if (angular.isUndefined($scope.clientconfig)) {
$timeout(function() {
ResourceArchiveService.setLimit($scope.clientconfig.generated.history_page_limit);
ResourceArchiveService.initResourceArchive('credentials');
ResourceArchiveService.initResourceArchive('blind_credentials');
ResourceArchiveService.initResourceArchive('services');
}, 1000);
} else {
// When moving between resources and history, the client config already exists, so we
// can avoid the timeout.
ResourceArchiveService.setLimit($scope.clientconfig.generated.history_page_limit);
ResourceArchiveService.initResourceArchive('credentials');
ResourceArchiveService.initResourceArchive('blind_credentials');
ResourceArchiveService.initResourceArchive('services');
}
// When moving between resources and history, the client config already exists, so we
// can avoid the timeout.
ResourceArchiveService.setLimit($scope.clientconfig.generated.history_page_limit);
ResourceArchiveService.initResourceArchive('credentials');
ResourceArchiveService.initResourceArchive('blind_credentials');
ResourceArchiveService.initResourceArchive('services');

}])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
$scope.getError = '';
$scope.credentialPairConflicts = null;
$scope.hasMetadata = false;
$scope.permissions = $scope.clientconfig.generated.permissions;

if ($stateParams.credentialId) {
CredentialServices.get({'id': $stateParams.credentialId}).$promise.then(function(credentialServices) {
Expand Down Expand Up @@ -94,8 +95,6 @@
};
credentialCopy = angular.copy($scope.credential);
$scope.shown = true;
// TODO: need a hasCreate here, which we'd get determine
// based on config endpoint.
}

$scope.showValue = function(credentialPair) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
$scope.$log = $log;
$scope.typeFilter = 'credentials';
$scope.showDisabled = false;
$scope.globalPermissions = $scope.clientconfig.generated.permissions;

$scope.getCredentialList = CredentialListService.getCredentialList;
$scope.$watch('getCredentialList()', function(newCredentialList, oldCredentialList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
$scope.newService = false;
$scope.credentialPairConflicts = null;
$scope.aws_account_options = $scope.clientconfig.generated.aws_accounts;
$scope.permissions = $scope.clientconfig.generated.permissions;

Roles.get().$promise.then(function(roles) {
$scope.roles = roles.roles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
</ul>
</div>
</div>
<div class="form-group" ng-show="credential.permissions.get">
<div class="form-group" ng-show="credential.permissions.get || globalPermissions.credentials.create">
<label for="credentialPairInputs">Credential Pairs <span class="glyphicon glyphicon-lock"></span></label>
<div class="well well-sm" id="credentialPairInputs">
<div class="row has-margin-bottom-lg">
Expand Down
4 changes: 2 additions & 2 deletions confidant/public/modules/resources/views/resources.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<div class="btn-group dropdown col-md-3">
<button type="button" class="btn dropdown-toggle call-to-action" data-toggle="dropdown" aria-expanded="false">Create <span class="glyphicon glyphicon-chevron-down glyphicon-xs"></span></small></span></button>
<ul class="dropdown-menu" role="menu">
<li><a href="#/resources/new/credential">Create credential</a></li>
<li><a href="#/resources/new/service">Create service</a></li>
<li ng-show="globalPermissions.credentials.create"><a href="#/resources/new/credential">Create credential</a></li>
<li ng-show="globalPermissions.services.create"><a href="#/resources/new/service">Create service</a></li>
</ul>
</div>
</div>
Expand Down

0 comments on commit 2ef3621

Please sign in to comment.