mirror of
https://github.com/portainer/portainer.git
synced 2025-08-05 05:45:22 +02:00
feat(global): introduce user teams and new UAC system (#868)
This commit is contained in:
parent
a380fd9adc
commit
5523fc9023
160 changed files with 7112 additions and 3166 deletions
|
@ -49,8 +49,8 @@
|
|||
</div>
|
||||
</div>
|
||||
<!-- !confirm-password-input -->
|
||||
<!-- role-checkbox -->
|
||||
<div class="form-group">
|
||||
<!-- admin-checkbox -->
|
||||
<div class="form-group" ng-if="isAdmin">
|
||||
<div class="col-sm-12">
|
||||
<label for="permissions" class="control-label text-left">
|
||||
Administrator
|
||||
|
@ -61,10 +61,36 @@
|
|||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<!-- !role-checkbox -->
|
||||
<div class="form-group">
|
||||
<!-- !admin-checkbox -->
|
||||
<!-- teams -->
|
||||
<div class="form-group" ng-if="!formValues.Administrator">
|
||||
<div class="col-sm-12">
|
||||
<span class="small text-muted">Note: non-administrator users do not have access to any endpoint by default. Head over the <a ui-sref="endpoints">endpoints view</a> to manage their accesses.</span>
|
||||
<label class="control-label text-left">
|
||||
Add to team(s)
|
||||
</label>
|
||||
<span class="small text-muted" style="margin-left: 20px;" ng-if="teams.length === 0">
|
||||
You have not yet created any team. Head over the <a ui-sref="teams">teams view</a> to manage user teams.</span>
|
||||
</span>
|
||||
<span isteven-multi-select
|
||||
ng-if="teams.length > 0"
|
||||
input-model="teams"
|
||||
output-model="formValues.Teams"
|
||||
button-label="Name"
|
||||
item-label="Name"
|
||||
tick-property="ticked"
|
||||
helper-elements="filter"
|
||||
search-property="Name"
|
||||
translation="{nothingSelected: 'Select one or more teams', search: 'Search...'}"
|
||||
style="margin-left: 20px;"
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<!-- !teams -->
|
||||
<div class="form-group" ng-if="isAdmin && !formValues.Administrator && formValues.Teams.length === 0">
|
||||
<div class="col-sm-12">
|
||||
<span class="small text-muted">
|
||||
Note: non-administrator users with no team do not have access to any endpoint by default. Head over the <a ui-sref="endpoints">endpoints view</a> to manage their accesses.
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
|
@ -98,7 +124,7 @@
|
|||
</div>
|
||||
</rd-widget-header>
|
||||
<rd-widget-taskbar classes="col-lg-12">
|
||||
<div class="pull-left">
|
||||
<div class="pull-left" ng-if="isAdmin">
|
||||
<button type="button" class="btn btn-danger" ng-click="removeAction()" ng-disabled="!state.selectedItemCount"><i class="fa fa-trash space-right" aria-hidden="true"></i>Remove</button>
|
||||
</div>
|
||||
<div class="pull-right">
|
||||
|
@ -110,7 +136,7 @@
|
|||
<table class="table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
<th ng-if="isAdmin">
|
||||
<input type="checkbox" ng-model="allSelected" ng-change="selectItems(allSelected)" />
|
||||
</th>
|
||||
<th>
|
||||
|
@ -127,18 +153,20 @@
|
|||
<span ng-show="sortType == 'RoleName' && sortReverse" class="glyphicon glyphicon-chevron-up"></span>
|
||||
</a>
|
||||
</th>
|
||||
<th></th>
|
||||
<th ng-if="isAdmin"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr dir-paginate="user in (state.filteredUsers = (users | filter:state.filter | orderBy:sortType:sortReverse | itemsPerPage: state.pagination_count))">
|
||||
<td><input type="checkbox" ng-model="user.Checked" ng-change="selectItem(user)" /></td>
|
||||
<td ng-if="isAdmin"><input type="checkbox" ng-model="user.Checked" ng-change="selectItem(user)" /></td>
|
||||
<td>{{ user.Username }}</td>
|
||||
<td>
|
||||
<i ng-if="user.Role === 1" class="fa fa-user-circle-o" aria-hidden="true" style="margin-right: 2px;"></i>
|
||||
<i ng-if="user.Role !== 1 && !user.isTeamLeader" class="fa fa-user" aria-hidden="true" style="margin-right: 2px;"></i>
|
||||
<i ng-if="user.isTeamLeader" class="fa fa-user-plus" aria-hidden="true" style="margin-right: 2px;"></i>
|
||||
{{ user.RoleName }}
|
||||
<i class="fa" ng-class="user.RoleId === 1 ? 'fa-user-circle-o' : 'fa-user'" aria-hidden="true" style="margin-left: 2px;"></i>
|
||||
</td>
|
||||
<td>
|
||||
<td ng-if="isAdmin">
|
||||
<a ui-sref="user({id: user.Id})"><i class="fa fa-pencil-square-o" aria-hidden="true"></i> Edit</a>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
angular.module('users', [])
|
||||
.controller('UsersController', ['$scope', '$state', 'UserService', 'ModalService', 'Notifications', 'Pagination',
|
||||
function ($scope, $state, UserService, ModalService, Notifications, Pagination) {
|
||||
.controller('UsersController', ['$q', '$scope', '$state', 'UserService', 'TeamService', 'TeamMembershipService', 'ModalService', 'Notifications', 'Pagination', 'Authentication',
|
||||
function ($q, $scope, $state, UserService, TeamService, TeamMembershipService, ModalService, Notifications, Pagination, Authentication) {
|
||||
$scope.state = {
|
||||
userCreationError: '',
|
||||
selectedItemCount: 0,
|
||||
|
@ -15,6 +15,7 @@ function ($scope, $state, UserService, ModalService, Notifications, Pagination)
|
|||
Password: '',
|
||||
ConfirmPassword: '',
|
||||
Administrator: false,
|
||||
Teams: []
|
||||
};
|
||||
|
||||
$scope.order = function(sortType) {
|
||||
|
@ -56,20 +57,25 @@ function ($scope, $state, UserService, ModalService, Notifications, Pagination)
|
|||
};
|
||||
|
||||
$scope.addUser = function() {
|
||||
$('#createUserSpinner').show();
|
||||
$scope.state.userCreationError = '';
|
||||
var username = $scope.formValues.Username;
|
||||
var password = $scope.formValues.Password;
|
||||
var role = $scope.formValues.Administrator ? 1 : 2;
|
||||
UserService.createUser(username, password, role)
|
||||
var teamIds = [];
|
||||
angular.forEach($scope.formValues.Teams, function(team) {
|
||||
teamIds.push(team.Id);
|
||||
});
|
||||
UserService.createUser(username, password, role, teamIds)
|
||||
.then(function success(data) {
|
||||
Notifications.success("User created", username);
|
||||
Notifications.success('User successfully created', username);
|
||||
$state.reload();
|
||||
})
|
||||
.catch(function error(err) {
|
||||
$scope.state.userCreationError = err.msg;
|
||||
Notifications.error('Failure', err, 'Unable to create user');
|
||||
})
|
||||
.finally(function final() {
|
||||
|
||||
$('#createUserSpinner').hide();
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -92,7 +98,7 @@ function ($scope, $state, UserService, ModalService, Notifications, Pagination)
|
|||
Notifications.success('User successfully deleted', user.Username);
|
||||
})
|
||||
.catch(function error(err) {
|
||||
Notifications.error("Failure", err, 'Unable to remove user');
|
||||
Notifications.error('Failure', err, 'Unable to remove user');
|
||||
})
|
||||
.finally(function final() {
|
||||
complete();
|
||||
|
@ -111,22 +117,46 @@ function ($scope, $state, UserService, ModalService, Notifications, Pagination)
|
|||
);
|
||||
};
|
||||
|
||||
function fetchUsers() {
|
||||
function assignTeamLeaders(users, memberships) {
|
||||
for (var i = 0; i < users.length; i++) {
|
||||
var user = users[i];
|
||||
user.isTeamLeader = false;
|
||||
for (var j = 0; j < memberships.length; j++) {
|
||||
var membership = memberships[j];
|
||||
if (user.Id === membership.UserId && membership.Role === 1) {
|
||||
user.isTeamLeader = true;
|
||||
user.RoleName = 'team leader';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function initView() {
|
||||
$('#loadUsersSpinner').show();
|
||||
UserService.users()
|
||||
var userDetails = Authentication.getUserDetails();
|
||||
var isAdmin = userDetails.role === 1 ? true: false;
|
||||
$scope.isAdmin = isAdmin;
|
||||
$q.all({
|
||||
users: UserService.users(true),
|
||||
teams: isAdmin ? TeamService.teams() : UserService.userLeadingTeams(userDetails.ID),
|
||||
memberships: TeamMembershipService.memberships()
|
||||
})
|
||||
.then(function success(data) {
|
||||
$scope.users = data.map(function(user) {
|
||||
return new UserViewModel(user);
|
||||
});
|
||||
var users = data.users;
|
||||
assignTeamLeaders(users, data.memberships);
|
||||
$scope.users = users;
|
||||
$scope.teams = data.teams;
|
||||
})
|
||||
.catch(function error(err) {
|
||||
Notifications.error("Failure", err, "Unable to retrieve users");
|
||||
Notifications.error('Failure', err, 'Unable to retrieve users and teams');
|
||||
$scope.users = [];
|
||||
$scope.teams = [];
|
||||
})
|
||||
.finally(function final() {
|
||||
$('#loadUsersSpinner').hide();
|
||||
});
|
||||
}
|
||||
|
||||
fetchUsers();
|
||||
initView();
|
||||
}]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue