Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update permissions, global permissions, and fix clientconfig race condition #252

Merged
merged 2 commits into from
Jan 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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