mirror of
https://github.com/portainer/portainer.git
synced 2025-08-05 05:45:22 +02:00
feat(uac): add multi user management and UAC (#647)
This commit is contained in:
parent
f28f223624
commit
80d50378c5
91 changed files with 3973 additions and 866 deletions
88
app/components/user/user.html
Normal file
88
app/components/user/user.html
Normal file
|
@ -0,0 +1,88 @@
|
|||
<rd-header>
|
||||
<rd-header-title title="User details">
|
||||
<i id="loadingViewSpinner" class="fa fa-cog fa-spin"></i>
|
||||
</rd-header-title>
|
||||
<rd-header-content>
|
||||
<a ui-sref="users">Users</a> > <a ui-sref="user({id: user.Id})">{{ user.Username }}</a>
|
||||
</rd-header-content>
|
||||
</rd-header>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-12 col-md-12 col-xs-12">
|
||||
<rd-widget>
|
||||
<rd-widget-header icon="fa-user" title="User details"></rd-widget-header>
|
||||
<rd-widget-body classes="no-padding">
|
||||
<table class="table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>Name</td>
|
||||
<td>
|
||||
{{ user.Username }}
|
||||
<button class="btn btn-xs btn-danger" ng-click="deleteUser()"><i class="fa fa-trash space-right" aria-hidden="true"></i>Delete this user</button>
|
||||
</td>
|
||||
</tr>
|
||||
<td>Permissions</td>
|
||||
<td>
|
||||
<div class="btn-group btn-group-sm">
|
||||
<label class="btn btn-default" ng-model="user.RoleId" uib-btn-radio="2" ng-change="updatePermissions()">
|
||||
<i class="fa fa-user" aria-hidden="true"></i>
|
||||
User
|
||||
</label>
|
||||
<label class="btn btn-default" ng-model="user.RoleId" uib-btn-radio="1" ng-change="updatePermissions()">
|
||||
<i class="fa fa-user-circle-o" aria-hidden="true"></i>
|
||||
Administrator
|
||||
</label>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</rd-widget-body>
|
||||
</rd-widget>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-12 col-md-12 col-xs-12">
|
||||
<rd-widget>
|
||||
<rd-widget-header icon="fa-lock" title="Change user password"></rd-widget-header>
|
||||
<rd-widget-body>
|
||||
<form class="form-horizontal" style="margin-top: 15px;">
|
||||
<!-- new-password-input -->
|
||||
<div class="form-group">
|
||||
<label for="new_password" class="col-sm-2 control-label text-left">New password</label>
|
||||
<div class="col-sm-8">
|
||||
<div class="input-group">
|
||||
<span class="input-group-addon"><i class="fa fa-lock" aria-hidden="true"></i></span>
|
||||
<input type="password" class="form-control" ng-model="formValues.newPassword" id="new_password">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- !new-password-input -->
|
||||
<!-- confirm-password-input -->
|
||||
<div class="form-group">
|
||||
<label for="confirm_password" class="col-sm-2 control-label text-left">Confirm password</label>
|
||||
<div class="col-sm-8">
|
||||
<div class="input-group">
|
||||
<span class="input-group-addon"><i class="fa fa-lock" aria-hidden="true"></i></span>
|
||||
<input type="password" class="form-control" ng-model="formValues.confirmPassword" id="confirm_password">
|
||||
<span class="input-group-addon"><i ng-class="{true: 'fa fa-check green-icon', false: 'fa fa-times red-icon'}[formValues.newPassword !== '' && formValues.newPassword === formValues.confirmPassword]" aria-hidden="true"></i></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- !confirm-password-input -->
|
||||
<div class="form-group">
|
||||
<div class="col-sm-2">
|
||||
<button type="submit" class="btn btn-primary btn-sm" ng-disabled="formValues.newPassword === '' || formValues.newPassword !== formValues.confirmPassword" ng-click="updatePassword()">Update password</button>
|
||||
</div>
|
||||
<div class="col-sm-10">
|
||||
<p class="pull-left text-danger" ng-if="state.updatePasswordError" style="margin: 5px;">
|
||||
<i class="fa fa-exclamation-circle" aria-hidden="true"></i> {{ state.updatePasswordError }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</rd-widget-body>
|
||||
</rd-widget>
|
||||
</div>
|
||||
</div>
|
85
app/components/user/userController.js
Normal file
85
app/components/user/userController.js
Normal file
|
@ -0,0 +1,85 @@
|
|||
angular.module('user', [])
|
||||
.controller('UserController', ['$scope', '$state', '$stateParams', 'UserService', 'ModalService', 'Messages',
|
||||
function ($scope, $state, $stateParams, UserService, ModalService, Messages) {
|
||||
|
||||
$scope.state = {
|
||||
updatePasswordError: '',
|
||||
};
|
||||
|
||||
$scope.formValues = {
|
||||
newPassword: '',
|
||||
confirmPassword: ''
|
||||
};
|
||||
|
||||
$scope.deleteUser = function() {
|
||||
ModalService.confirmDeletion(
|
||||
'Do you want to delete this user? This user will not be able to login into Portainer anymore.',
|
||||
function onConfirm(confirmed) {
|
||||
if(!confirmed) { return; }
|
||||
deleteUser();
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
$scope.updatePermissions = function() {
|
||||
$('#loadingViewSpinner').show();
|
||||
UserService.updateUser($scope.user.Id, undefined, $scope.user.RoleId)
|
||||
.then(function success(data) {
|
||||
var newRole = $scope.user.RoleId === 1 ? 'administrator' : 'user';
|
||||
Messages.send('Permissions successfully updated', $scope.user.Username + ' is now ' + newRole);
|
||||
$state.reload();
|
||||
})
|
||||
.catch(function error(err) {
|
||||
Messages.error("Failure", err, 'Unable to update user permissions');
|
||||
})
|
||||
.finally(function final() {
|
||||
$('#loadingViewSpinner').hide();
|
||||
});
|
||||
};
|
||||
|
||||
$scope.updatePassword = function() {
|
||||
$('#loadingViewSpinner').show();
|
||||
UserService.updateUser($scope.user.Id, $scope.formValues.newPassword, undefined)
|
||||
.then(function success(data) {
|
||||
Messages.send('Password successfully updated');
|
||||
$state.reload();
|
||||
})
|
||||
.catch(function error(err) {
|
||||
$scope.state.updatePasswordError = 'Unable to update password';
|
||||
})
|
||||
.finally(function final() {
|
||||
$('#loadingViewSpinner').hide();
|
||||
});
|
||||
};
|
||||
|
||||
function deleteUser() {
|
||||
$('#loadingViewSpinner').show();
|
||||
UserService.deleteUser($scope.user.Id)
|
||||
.then(function success(data) {
|
||||
Messages.send('User successfully deleted', $scope.user.Username);
|
||||
$state.go('users');
|
||||
})
|
||||
.catch(function error(err) {
|
||||
Messages.error("Failure", err, 'Unable to remove user');
|
||||
})
|
||||
.finally(function final() {
|
||||
$('#loadingViewSpinner').hide();
|
||||
});
|
||||
}
|
||||
|
||||
function getUser() {
|
||||
$('#loadingViewSpinner').show();
|
||||
UserService.user($stateParams.id)
|
||||
.then(function success(data) {
|
||||
$scope.user = new UserViewModel(data);
|
||||
})
|
||||
.catch(function error(err) {
|
||||
Messages.error("Failure", err, 'Unable to retrieve user information');
|
||||
})
|
||||
.finally(function final() {
|
||||
$('#loadingViewSpinner').hide();
|
||||
});
|
||||
}
|
||||
|
||||
getUser();
|
||||
}]);
|
Loading…
Add table
Add a link
Reference in a new issue