2016-10-13 13:04:59 +00:00
|
|
|
/**
|
|
|
|
* 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: {
|
2016-12-20 18:54:31 +00:00
|
|
|
'isEnabled': '=isEnabled'
|
2016-10-13 13:04:59 +00:00
|
|
|
},
|
2016-12-20 18:54:31 +00:00
|
|
|
controller: function ($scope, $timeout, $location, $element, ApiService, UserService, TableService) {
|
|
|
|
$scope.user = UserService.currentUser();
|
|
|
|
$scope.users = null;
|
|
|
|
$scope.orderedUsers = [];
|
|
|
|
$scope.usersPerPage = 10;
|
2016-10-13 13:04:59 +00:00
|
|
|
|
|
|
|
$scope.newUser = {};
|
|
|
|
$scope.createdUser = null;
|
|
|
|
$scope.takeOwnershipInfo = null;
|
2016-12-20 18:54:31 +00:00
|
|
|
$scope.options = {
|
|
|
|
'predicate': 'username',
|
|
|
|
'reverse': false,
|
|
|
|
'filter': null,
|
|
|
|
'page': 0
|
|
|
|
};
|
2016-10-13 13:04:59 +00:00
|
|
|
|
|
|
|
$scope.showCreateUser = function () {
|
|
|
|
$scope.createdUser = null;
|
|
|
|
$('#createUserModal').modal('show');
|
|
|
|
};
|
|
|
|
|
2016-12-20 18:54:31 +00:00
|
|
|
var sortUsers = function() {
|
|
|
|
if (!$scope.users) {return;}
|
|
|
|
$scope.orderedUsers = TableService.buildOrderedItems($scope.users, $scope.options,
|
|
|
|
['username', 'email'], []);
|
|
|
|
};
|
|
|
|
|
2016-10-13 13:04:59 +00:00
|
|
|
var loadUsersInternal = function () {
|
|
|
|
ApiService.listAllUsers().then(function (resp) {
|
|
|
|
$scope.users = resp['users'];
|
2016-12-20 18:54:31 +00:00
|
|
|
sortUsers();
|
2016-10-13 13:04:59 +00:00
|
|
|
$scope.showInterface = true;
|
|
|
|
}, function (resp) {
|
|
|
|
$scope.users = [];
|
|
|
|
$scope.usersError = ApiService.getErrorMessage(resp);
|
|
|
|
});
|
|
|
|
};
|
2016-12-20 18:54:31 +00:00
|
|
|
$scope.tablePredicateClass = function(name, predicate, reverse) {
|
|
|
|
if (name != predicate) {
|
|
|
|
return '';
|
|
|
|
}
|
2016-10-13 13:04:59 +00:00
|
|
|
|
2016-12-20 18:54:31 +00:00
|
|
|
return 'current ' + (reverse ? 'reversed' : '');
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.orderBy = function(predicate) {
|
|
|
|
if (predicate == $scope.options.predicate) {
|
|
|
|
$scope.options.reverse = !$scope.options.reverse;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$scope.options.reverse = false;
|
|
|
|
$scope.options.predicate = predicate;
|
|
|
|
};
|
2016-10-13 13:04:59 +00:00
|
|
|
$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();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-03-22 16:25:20 +00:00
|
|
|
$scope.askTakeOwnership = function (entity) {
|
2016-10-13 13:04:59 +00:00
|
|
|
$scope.takeOwnershipInfo = {
|
2017-03-22 16:25:20 +00:00
|
|
|
'entity': entity
|
2016-10-13 13:04:59 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
$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();
|
|
|
|
}
|
|
|
|
});
|
2016-12-20 18:54:31 +00:00
|
|
|
|
|
|
|
$scope.$watch('options.predicate', sortUsers);
|
|
|
|
$scope.$watch('options.reverse', sortUsers);
|
|
|
|
$scope.$watch('options.filter', sortUsers);
|
2016-10-13 13:04:59 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
return directiveDefinitionObject;
|
|
|
|
});
|