Refactoring manage users to it's own directive.
This commit is contained in:
parent
7f9e01a1fe
commit
c8e5809cc7
4 changed files with 491 additions and 447 deletions
230
static/js/directives/ui/manage-user-tab.js
Normal file
230
static/js/directives/ui/manage-user-tab.js
Normal file
|
@ -0,0 +1,230 @@
|
|||
/**
|
||||
* An element which displays a panel for managing users.
|
||||
*/
|
||||
angular.module('quay').directive('manageUserTab', function () {
|
||||
var directiveDefinitionObject = {
|
||||
priority: 0,
|
||||
templateUrl: '/static/directives/manage-users-tab.html',
|
||||
replace: false,
|
||||
transclude: true,
|
||||
restrict: 'C',
|
||||
scope: {
|
||||
'isEnabled': '=isEnabled'
|
||||
},
|
||||
controller: function ($scope, $timeout, $location, $element, ApiService, UserService) {
|
||||
|
||||
$scope.newUser = {};
|
||||
$scope.createdUser = null;
|
||||
$scope.takeOwnershipInfo = null;
|
||||
|
||||
|
||||
$scope.showCreateUser = function () {
|
||||
$scope.createdUser = null;
|
||||
$('#createUserModal').modal('show');
|
||||
};
|
||||
|
||||
var loadUsersInternal = function () {
|
||||
ApiService.listAllUsers().then(function (resp) {
|
||||
$scope.users = resp['users'];
|
||||
$scope.showInterface = true;
|
||||
}, function (resp) {
|
||||
$scope.users = [];
|
||||
$scope.usersError = ApiService.getErrorMessage(resp);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.createUser = function () {
|
||||
$scope.creatingUser = true;
|
||||
$scope.createdUser = null;
|
||||
|
||||
var errorHandler = ApiService.errorDisplay('Cannot create user', function () {
|
||||
$scope.creatingUser = false;
|
||||
$('#createUserModal').modal('hide');
|
||||
});
|
||||
|
||||
ApiService.createInstallUser($scope.newUser, null).then(function (resp) {
|
||||
$scope.creatingUser = false;
|
||||
$scope.newUser = {};
|
||||
$scope.createdUser = resp;
|
||||
loadUsersInternal();
|
||||
}, errorHandler)
|
||||
};
|
||||
|
||||
|
||||
$scope.setSuperuser = function (user, status) {
|
||||
var setSuperuser = function () {
|
||||
var params = {
|
||||
'username': user.username
|
||||
};
|
||||
|
||||
var data = {
|
||||
'superuser': status
|
||||
};
|
||||
|
||||
ApiService.changeInstallUser(data, params).then(function (resp) {
|
||||
$scope.requiresRestart = true;
|
||||
}, ApiService.errorDisplay('Could not change user'));
|
||||
};
|
||||
|
||||
var msg = 'Note: This change, once applied, will require your installation ' +
|
||||
'to be restarted to take effect';
|
||||
|
||||
bootbox.confirm(msg, function (status) {
|
||||
if (status) {
|
||||
setSuperuser();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$scope.showChangeEmail = function (user) {
|
||||
$scope.userToChange = user;
|
||||
$('#changeEmailModal').modal({});
|
||||
};
|
||||
|
||||
$scope.changeUserEmail = function (user) {
|
||||
$('#changeEmailModal').modal('hide');
|
||||
|
||||
var params = {
|
||||
'username': user.username
|
||||
};
|
||||
|
||||
var data = {
|
||||
'email': user.newemail
|
||||
};
|
||||
|
||||
ApiService.changeInstallUser(data, params).then(function (resp) {
|
||||
loadUsersInternal();
|
||||
user.email = user.newemail;
|
||||
delete user.newemail;
|
||||
}, ApiService.errorDisplay('Could not change user'));
|
||||
};
|
||||
|
||||
$scope.showChangePassword = function (user) {
|
||||
$scope.userToChange = user;
|
||||
$('#changePasswordModal').modal({});
|
||||
};
|
||||
|
||||
$scope.changeUserPassword = function (user) {
|
||||
$('#changePasswordModal').modal('hide');
|
||||
|
||||
var params = {
|
||||
'username': user.username
|
||||
};
|
||||
|
||||
var data = {
|
||||
'password': user.password
|
||||
};
|
||||
|
||||
ApiService.changeInstallUser(data, params).then(function (resp) {
|
||||
loadUsersInternal();
|
||||
}, ApiService.errorDisplay('Could not change user'));
|
||||
};
|
||||
|
||||
$scope.sendRecoveryEmail = function (user) {
|
||||
var params = {
|
||||
'username': user.username
|
||||
};
|
||||
|
||||
ApiService.sendInstallUserRecoveryEmail(null, params).then(function (resp) {
|
||||
bootbox.dialog({
|
||||
"message": "A recovery email has been sent to " + resp['email'],
|
||||
"title": "Recovery email sent",
|
||||
"buttons": {
|
||||
"close": {
|
||||
"label": "Close",
|
||||
"className": "btn-primary"
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}, ApiService.errorDisplay('Cannot send recovery email'))
|
||||
};
|
||||
|
||||
$scope.showDeleteUser = function (user) {
|
||||
if (user.username == UserService.currentUser().username) {
|
||||
bootbox.dialog({
|
||||
"message": 'Cannot delete yourself!',
|
||||
"title": "Cannot delete user",
|
||||
"buttons": {
|
||||
"close": {
|
||||
"label": "Close",
|
||||
"className": "btn-primary"
|
||||
}
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
$scope.userToDelete = user;
|
||||
$('#confirmDeleteUserModal').modal({});
|
||||
};
|
||||
|
||||
$scope.deleteUser = function (user) {
|
||||
$('#confirmDeleteUserModal').modal('hide');
|
||||
|
||||
var params = {
|
||||
'username': user.username
|
||||
};
|
||||
|
||||
ApiService.deleteInstallUser(null, params).then(function (resp) {
|
||||
loadUsersInternal();
|
||||
}, ApiService.errorDisplay('Cannot delete user'));
|
||||
};
|
||||
|
||||
$scope.askDisableUser = function (user) {
|
||||
var message = 'Are you sure you want to disable this user? ' +
|
||||
'They will be unable to login, pull or push.';
|
||||
|
||||
if (!user.enabled) {
|
||||
message = 'Are you sure you want to reenable this user? ' +
|
||||
'They will be able to login, pull or push.'
|
||||
}
|
||||
|
||||
bootbox.confirm(message, function (resp) {
|
||||
if (resp) {
|
||||
var params = {
|
||||
'username': user.username
|
||||
};
|
||||
|
||||
var data = {
|
||||
'enabled': !user.enabled
|
||||
};
|
||||
|
||||
ApiService.changeInstallUser(data, params).then(function (resp) {
|
||||
loadUsersInternal();
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$scope.askTakeOwnership = function (entity, is_org) {
|
||||
$scope.takeOwnershipInfo = {
|
||||
'entity': entity,
|
||||
'is_org': is_org
|
||||
};
|
||||
};
|
||||
|
||||
$scope.takeOwnership = function (info, callback) {
|
||||
var errorDisplay = ApiService.errorDisplay('Could not take ownership of namespace', callback);
|
||||
var params = {
|
||||
'namespace': info.entity.username || info.entity.name
|
||||
};
|
||||
|
||||
ApiService.takeOwnership(null, params).then(function () {
|
||||
callback(true);
|
||||
$location.path('/organization/' + params.namespace);
|
||||
}, errorDisplay)
|
||||
};
|
||||
|
||||
$scope.$watch('isEnabled', function (value) {
|
||||
if (value) {
|
||||
if ($scope.users) {
|
||||
return;
|
||||
}
|
||||
loadUsersInternal();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
return directiveDefinitionObject;
|
||||
});
|
|
@ -10,7 +10,7 @@
|
|||
})
|
||||
}]);
|
||||
|
||||
function SuperuserCtrl($scope, $timeout, $location, ApiService, Features, UserService, ContainerService, AngularPollChannel, CoreDialog) {
|
||||
function SuperuserCtrl($scope, ApiService, Features, UserService, ContainerService, AngularPollChannel, CoreDialog) {
|
||||
if (!Features.SUPER_USERS) {
|
||||
return;
|
||||
}
|
||||
|
@ -21,8 +21,6 @@
|
|||
$scope.configStatus = null;
|
||||
$scope.requiresRestart = null;
|
||||
$scope.logsCounter = 0;
|
||||
$scope.newUser = {};
|
||||
$scope.createdUser = null;
|
||||
$scope.changeLog = null;
|
||||
$scope.debugServices = null;
|
||||
$scope.debugLogs = null;
|
||||
|
@ -32,7 +30,7 @@
|
|||
$scope.currentConfig = null;
|
||||
$scope.serviceKeysActive = false;
|
||||
$scope.globalMessagesActive = false;
|
||||
$scope.takeOwnershipInfo = null;
|
||||
$scope.manageUsersActive = false;
|
||||
|
||||
$scope.loadMessageOfTheDay = function () {
|
||||
$scope.globalMessagesActive = true;
|
||||
|
@ -42,11 +40,6 @@
|
|||
$scope.requiresRestart = true;
|
||||
};
|
||||
|
||||
$scope.showCreateUser = function() {
|
||||
$scope.createdUser = null;
|
||||
$('#createUserModal').modal('show');
|
||||
};
|
||||
|
||||
$scope.loadServiceKeys = function() {
|
||||
$scope.serviceKeysActive = true;
|
||||
};
|
||||
|
@ -121,110 +114,7 @@
|
|||
};
|
||||
|
||||
$scope.loadUsers = function() {
|
||||
if ($scope.users) {
|
||||
return;
|
||||
}
|
||||
|
||||
$scope.loadUsersInternal();
|
||||
};
|
||||
|
||||
$scope.loadUsersInternal = function() {
|
||||
ApiService.listAllUsers().then(function(resp) {
|
||||
$scope.users = resp['users'];
|
||||
$scope.showInterface = true;
|
||||
}, function(resp) {
|
||||
$scope.users = [];
|
||||
$scope.usersError = ApiService.getErrorMessage(resp);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.showChangePassword = function(user) {
|
||||
$scope.userToChange = user;
|
||||
$('#changePasswordModal').modal({});
|
||||
};
|
||||
|
||||
$scope.showChangeEmail = function(user) {
|
||||
$scope.userToChange = user;
|
||||
$('#changeEmailModal').modal({});
|
||||
};
|
||||
|
||||
$scope.createUser = function() {
|
||||
$scope.creatingUser = true;
|
||||
$scope.createdUser = null;
|
||||
|
||||
var errorHandler = ApiService.errorDisplay('Cannot create user', function() {
|
||||
$scope.creatingUser = false;
|
||||
$('#createUserModal').modal('hide');
|
||||
});
|
||||
|
||||
ApiService.createInstallUser($scope.newUser, null).then(function(resp) {
|
||||
$scope.creatingUser = false;
|
||||
$scope.newUser = {};
|
||||
$scope.createdUser = resp;
|
||||
$scope.loadUsersInternal();
|
||||
}, errorHandler)
|
||||
};
|
||||
|
||||
$scope.setSuperuser = function(user, status) {
|
||||
var setSuperuser = function() {
|
||||
var params = {
|
||||
'username': user.username
|
||||
};
|
||||
|
||||
var data = {
|
||||
'superuser': status
|
||||
};
|
||||
|
||||
ApiService.changeInstallUser(data, params).then(function(resp) {
|
||||
$scope.requiresRestart = true;
|
||||
}, ApiService.errorDisplay('Could not change user'));
|
||||
};
|
||||
|
||||
var msg = 'Note: This change, once applied, will require your installation ' +
|
||||
'to be restarted to take effect';
|
||||
|
||||
bootbox.confirm(msg, function(status) {
|
||||
if (status) {
|
||||
setSuperuser();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$scope.showDeleteUser = function(user) {
|
||||
if (user.username == UserService.currentUser().username) {
|
||||
bootbox.dialog({
|
||||
"message": 'Cannot delete yourself!',
|
||||
"title": "Cannot delete user",
|
||||
"buttons": {
|
||||
"close": {
|
||||
"label": "Close",
|
||||
"className": "btn-primary"
|
||||
}
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
$scope.userToDelete = user;
|
||||
$('#confirmDeleteUserModal').modal({});
|
||||
};
|
||||
|
||||
$scope.changeUserEmail = function(user) {
|
||||
$('#changeEmailModal').modal('hide');
|
||||
|
||||
var params = {
|
||||
'username': user.username
|
||||
};
|
||||
|
||||
var data = {
|
||||
'email': user.newemail
|
||||
};
|
||||
|
||||
ApiService.changeInstallUser(data, params).then(function(resp) {
|
||||
$scope.loadUsersInternal();
|
||||
user.email = user.newemail;
|
||||
delete user.newemail;
|
||||
}, ApiService.errorDisplay('Could not change user'));
|
||||
$scope.manageUsersActive = true;
|
||||
};
|
||||
|
||||
$scope.askDeleteOrganization = function(org) {
|
||||
|
@ -261,99 +151,6 @@
|
|||
});
|
||||
};
|
||||
|
||||
$scope.askTakeOwnership = function(entity, is_org) {
|
||||
$scope.takeOwnershipInfo = {
|
||||
'entity': entity,
|
||||
'is_org': is_org
|
||||
};
|
||||
};
|
||||
|
||||
$scope.takeOwnership = function(info, callback) {
|
||||
var errorDisplay = ApiService.errorDisplay('Could not take ownership of namespace', callback);
|
||||
var params = {
|
||||
'namespace': info.entity.username || info.entity.name
|
||||
};
|
||||
|
||||
ApiService.takeOwnership(null, params).then(function() {
|
||||
callback(true);
|
||||
$location.path('/organization/' + params.namespace);
|
||||
}, errorDisplay)
|
||||
};
|
||||
|
||||
$scope.askDisableUser = function(user) {
|
||||
var message = 'Are you sure you want to disable this user? ' +
|
||||
'They will be unable to login, pull or push.'
|
||||
|
||||
if (!user.enabled) {
|
||||
message = 'Are you sure you want to reenable this user? ' +
|
||||
'They will be able to login, pull or push.'
|
||||
}
|
||||
|
||||
bootbox.confirm(message, function(resp) {
|
||||
if (resp) {
|
||||
var params = {
|
||||
'username': user.username
|
||||
};
|
||||
|
||||
var data = {
|
||||
'enabled': !user.enabled
|
||||
};
|
||||
|
||||
ApiService.changeInstallUser(data, params).then(function(resp) {
|
||||
$scope.loadUsersInternal();
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$scope.changeUserPassword = function(user) {
|
||||
$('#changePasswordModal').modal('hide');
|
||||
|
||||
var params = {
|
||||
'username': user.username
|
||||
};
|
||||
|
||||
var data = {
|
||||
'password': user.password
|
||||
};
|
||||
|
||||
ApiService.changeInstallUser(data, params).then(function(resp) {
|
||||
$scope.loadUsersInternal();
|
||||
}, ApiService.errorDisplay('Could not change user'));
|
||||
};
|
||||
|
||||
$scope.deleteUser = function(user) {
|
||||
$('#confirmDeleteUserModal').modal('hide');
|
||||
|
||||
var params = {
|
||||
'username': user.username
|
||||
};
|
||||
|
||||
ApiService.deleteInstallUser(null, params).then(function(resp) {
|
||||
$scope.loadUsersInternal();
|
||||
}, ApiService.errorDisplay('Cannot delete user'));
|
||||
};
|
||||
|
||||
$scope.sendRecoveryEmail = function(user) {
|
||||
var params = {
|
||||
'username': user.username
|
||||
};
|
||||
|
||||
ApiService.sendInstallUserRecoveryEmail(null, params).then(function(resp) {
|
||||
bootbox.dialog({
|
||||
"message": "A recovery email has been sent to " + resp['email'],
|
||||
"title": "Recovery email sent",
|
||||
"buttons": {
|
||||
"close": {
|
||||
"label": "Close",
|
||||
"className": "btn-primary"
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}, ApiService.errorDisplay('Cannot send recovery email'))
|
||||
};
|
||||
|
||||
$scope.restartContainer = function() {
|
||||
$('#restartingContainerModal').modal({
|
||||
keyboard: false,
|
||||
|
@ -378,7 +175,7 @@
|
|||
var message = "Installation of this product has not yet been completed." +
|
||||
"<br><br>Please read the " +
|
||||
"<a href='https://coreos.com/docs/enterprise-registry/initial-setup/'>" +
|
||||
"Setup Guide</a>"
|
||||
"Setup Guide</a>";
|
||||
|
||||
var title = "Installation Incomplete";
|
||||
CoreDialog.fatal(title, message);
|
||||
|
|
Reference in a new issue