add operators UI

This commit is contained in:
Girish Ramakrishnan
2021-09-21 15:26:05 -07:00
parent ee62e9c2e7
commit aecba53de5
5 changed files with 126 additions and 68 deletions

View File

@@ -11,8 +11,6 @@
/* global SECRET_PLACEHOLDER */
angular.module('Application').controller('AppController', ['$scope', '$location', '$timeout', '$interval', '$route', '$routeParams', 'Client', function ($scope, $location, $timeout, $interval, $route, $routeParams, Client) {
Client.onReady(function () { if (!Client.getUserInfo().isAtLeastAdmin) $location.path('/'); });
// List is from http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
$scope.s3Regions = [
{ name: 'Asia Pacific (Mumbai)', value: 'ap-south-1' },
@@ -452,6 +450,8 @@ angular.module('Application').controller('AppController', ['$scope', '$location'
accessRestrictionOption: 'any',
accessRestriction: { users: [], groups: [] },
operators: { users: [], groups: [] },
isAccessRestrictionValid: function () {
var tmp = $scope.access.accessRestriction;
return !!(tmp.users.length || tmp.groups.length);
@@ -466,15 +466,29 @@ angular.module('Application').controller('AppController', ['$scope', '$location'
$scope.access.accessRestrictionOption = app.accessRestriction ? 'groups' : 'any';
$scope.access.accessRestriction = { users: [], groups: [] };
$scope.access.operators = { users: [], groups: [] };
var userSet, groupSet;
if (app.accessRestriction) {
var userSet = { };
userSet = {};
app.accessRestriction.users.forEach(function (uid) { userSet[uid] = true; });
$scope.users.forEach(function (u) { if (userSet[u.id] === true) $scope.access.accessRestriction.users.push(u); });
var groupSet = { };
app.accessRestriction.groups.forEach(function (gid) { groupSet[gid] = true; });
groupSet = {};
if (app.accessRestriction.groups) app.accessRestriction.groups.forEach(function (gid) { groupSet[gid] = true; });
$scope.groups.forEach(function (g) { if (groupSet[g.id] === true) $scope.access.accessRestriction.groups.push(g); });
}
if (app.operators) {
userSet = {};
app.operators.users.forEach(function (uid) { userSet[uid] = true; });
$scope.users.forEach(function (u) { if (userSet[u.id] === true) $scope.access.operators.users.push(u); });
groupSet = {};
if (app.operators.groups) app.operators.groups.forEach(function (gid) { groupSet[gid] = true; });
$scope.groups.forEach(function (g) { if (groupSet[g.id] === true) $scope.access.operators.groups.push(g); });
}
},
submit: function () {
@@ -488,13 +502,24 @@ angular.module('Application').controller('AppController', ['$scope', '$location'
accessRestriction.groups = $scope.access.accessRestriction.groups.map(function (g) { return g.id; });
}
var operators = null;
if ($scope.access.operators.users.length || $scope.access.operators.groups.length) {
operators = { users: [], groups: [] };
operators.users = $scope.access.operators.users.map(function (u) { return u.id; });
operators.groups = $scope.access.operators.groups.map(function (g) { return g.id; });
}
Client.configureApp($scope.app.id, 'access_restriction', { accessRestriction: accessRestriction }, function (error) {
if (error) return Client.error(error);
$timeout(function () {
$scope.access.success = true;
$scope.access.busy = false;
}, 1000);
Client.configureApp($scope.app.id, 'operators', { operators: operators }, function (error) {
if (error) return Client.error(error);
$timeout(function () {
$scope.access.success = true;
$scope.access.busy = false;
}, 1000);
});
});
}
};
@@ -1681,8 +1706,6 @@ angular.module('Application').controller('AppController', ['$scope', '$location'
return;
}
console.log(backupConfig)
$scope.$apply(function () {
// we assume property names match here, this does not yet work for gcs keys
Object.keys(backupConfig).forEach(function (k) {
@@ -1699,6 +1722,8 @@ angular.module('Application').controller('AppController', ['$scope', '$location'
refreshApp(appId, function (error) {
if (error) return Client.error(error);
if ($scope.app.accessLevel !== 'admin' && $scope.app.accessLevel !== 'operator') return $location.path('/');
// skipViewShow because we don't have all the values like domains/users to init the view yet
if ($routeParams.view) { // explicit route in url bar
$scope.setView($routeParams.view, true /* skipViewShow */);
@@ -1706,6 +1731,17 @@ angular.module('Application').controller('AppController', ['$scope', '$location'
$scope.setView($scope.app.error ? 'repair' : 'display', true /* skipViewShow */);
}
function done() {
$scope[$scope.view].show(); // initialize now that we have all the values
var refreshTimer = $interval(function () { refreshApp($scope.app.id); }, 5000); // call with inline function to avoid iteration argument passed see $interval docs
$scope.$on('$destroy', function () {
$interval.cancel(refreshTimer);
});
}
if ($scope.app.accessLevel !== 'admin') return done();
async.series([
fetchUsers,
fetchGroups,
@@ -1715,12 +1751,7 @@ angular.module('Application').controller('AppController', ['$scope', '$location'
], function (error) {
if (error) return Client.error(error);
$scope[$scope.view].show(); // initialize now that we have all the values
var refreshTimer = $interval(function () { refreshApp($scope.app.id); }, 5000); // call with inline function to avoid iteration argument passed see $interval docs
$scope.$on('$destroy', function () {
$interval.cancel(refreshTimer);
});
done();
});
});
});