From c8e5809cc71999d2e9218451c9b10df598452889 Mon Sep 17 00:00:00 2001 From: Charlton Austin Date: Thu, 13 Oct 2016 09:04:59 -0400 Subject: [PATCH] Refactoring manage users to it's own directive. --- static/directives/manage-users-tab.html | 240 +++++++++++++++++++ static/js/directives/ui/manage-user-tab.js | 230 ++++++++++++++++++ static/js/pages/superuser.js | 211 +---------------- static/partials/super-user.html | 257 ++------------------- 4 files changed, 491 insertions(+), 447 deletions(-) create mode 100644 static/directives/manage-users-tab.html create mode 100644 static/js/directives/ui/manage-user-tab.js diff --git a/static/directives/manage-users-tab.html b/static/directives/manage-users-tab.html new file mode 100644 index 000000000..18d10ec84 --- /dev/null +++ b/static/directives/manage-users-tab.html @@ -0,0 +1,240 @@ +
+
+
+ {{ usersError }} +
+
+
+ + + Note: is configured to use external authentication, so users can only be created in that system + +
+ +
+ + + + + + + + + + + + + + + +
UsernameE-mail address
+ + + + You + Superuser + Disabled + + {{ current_user.username }} + + {{ current_user.email }} + + + + Ω + Make Superuser + + + ω + Remove Superuser + + + + Change E-mail Address + + + Change Password + + + Send Recovery E-mail + + + Delete User + + + Disable Enable User + + + Take Ownership + + +
+
+ + +
+ Are you sure you want to take ownership of + organization {{ takeOwnershipInfo.entity.name }}? + user namespace {{ takeOwnershipInfo .entity.username }}? + +
+ Note: This will convert the user namespace into an organization. The user will no longer be able to login + to + this account. +
+
+ + + + + + + + + + + + + +
diff --git a/static/js/directives/ui/manage-user-tab.js b/static/js/directives/ui/manage-user-tab.js new file mode 100644 index 000000000..6193925f9 --- /dev/null +++ b/static/js/directives/ui/manage-user-tab.js @@ -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; +}); diff --git a/static/js/pages/superuser.js b/static/js/pages/superuser.js index 50636337b..91bee789a 100644 --- a/static/js/pages/superuser.js +++ b/static/js/pages/superuser.js @@ -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." + "

Please read the " + "" + - "Setup Guide" + "Setup Guide"; var title = "Installation Incomplete"; CoreDialog.fatal(title, message); diff --git a/static/partials/super-user.html b/static/partials/super-user.html index 3b8892468..4e9eaa943 100644 --- a/static/partials/super-user.html +++ b/static/partials/super-user.html @@ -34,11 +34,12 @@ - +