mirror of
https://github.com/portainer/portainer.git
synced 2025-08-02 20:35:25 +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
|
@ -60,6 +60,13 @@
|
|||
<span ng-show="sortType == 'Mountpoint' && sortReverse" class="glyphicon glyphicon-chevron-up"></span>
|
||||
</a>
|
||||
</th>
|
||||
<th ng-if="applicationState.application.authentication">
|
||||
<a ui-sref="volumes" ng-click="order('Metadata.ResourceControl.OwnerId')">
|
||||
Ownership
|
||||
<span ng-show="sortType == 'Metadata.ResourceControl.OwnerId' && !sortReverse" class="glyphicon glyphicon-chevron-down"></span>
|
||||
<span ng-show="sortType == 'Metadata.ResourceControl.OwnerId' && sortReverse" class="glyphicon glyphicon-chevron-up"></span>
|
||||
</a>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
@ -68,12 +75,33 @@
|
|||
<td>{{ volume.Name|truncate:50 }}</td>
|
||||
<td>{{ volume.Driver }}</td>
|
||||
<td>{{ volume.Mountpoint }}</td>
|
||||
<td ng-if="applicationState.application.authentication">
|
||||
<span ng-if="user.role === 1 && volume.Metadata.ResourceControl">
|
||||
<i class="fa fa-eye-slash" aria-hidden="true"></i>
|
||||
<span ng-if="volume.Metadata.ResourceControl.OwnerId === user.ID">
|
||||
Private
|
||||
</span>
|
||||
<span ng-if="volume.Metadata.ResourceControl.OwnerId !== user.ID">
|
||||
Private <span ng-if="volume.Owner">(owner: {{ volume.Owner }})</span>
|
||||
</span>
|
||||
<a ng-click="switchOwnership(volume)" class="interactive"><i class="fa fa-eye" aria-hidden="true" style="margin-left: 7px;"></i> Switch to public</a>
|
||||
</span>
|
||||
<span ng-if="user.role !== 1 && volume.Metadata.ResourceControl.OwnerId === user.ID">
|
||||
<i class="fa fa-eye-slash" aria-hidden="true"></i>
|
||||
Private
|
||||
<a ng-click="switchOwnership(volume)" class="interactive"><i class="fa fa-eye" aria-hidden="true" style="margin-left: 7px;"></i> Switch to public</a>
|
||||
</span>
|
||||
<span ng-if="!volume.Metadata.ResourceControl">
|
||||
<i class="fa fa-eye" aria-hidden="true"></i>
|
||||
Public
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr ng-if="!volumes">
|
||||
<td colspan="4" class="text-center text-muted">Loading...</td>
|
||||
<td colspan="6" class="text-center text-muted">Loading...</td>
|
||||
</tr>
|
||||
<tr ng-if="volumes.length == 0">
|
||||
<td colspan="4" class="text-center text-muted">No volumes available.</td>
|
||||
<td colspan="6" class="text-center text-muted">No volumes available.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
angular.module('volumes', [])
|
||||
.controller('VolumesController', ['$scope', '$state', 'Volume', 'Messages', 'Pagination',
|
||||
function ($scope, $state, Volume, Messages, Pagination) {
|
||||
.controller('VolumesController', ['$scope', '$state', 'Volume', 'Messages', 'Pagination', 'ModalService', 'Authentication', 'ResourceControlService', 'UserService',
|
||||
function ($scope, $state, Volume, Messages, Pagination, ModalService, Authentication, ResourceControlService, UserService) {
|
||||
$scope.state = {};
|
||||
$scope.state.pagination_count = Pagination.getPaginationCount('volumes');
|
||||
$scope.state.selectedItemCount = 0;
|
||||
|
@ -10,6 +10,24 @@ function ($scope, $state, Volume, Messages, Pagination) {
|
|||
Name: ''
|
||||
};
|
||||
|
||||
function removeVolumeResourceControl(volume) {
|
||||
ResourceControlService.removeVolumeResourceControl(volume.Metadata.ResourceControl.OwnerId, volume.Name)
|
||||
.then(function success() {
|
||||
delete volume.Metadata.ResourceControl;
|
||||
Messages.send('Ownership changed to public', volume.Name);
|
||||
})
|
||||
.catch(function error(err) {
|
||||
Messages.error("Failure", err, "Unable to change volume ownership");
|
||||
});
|
||||
}
|
||||
|
||||
$scope.switchOwnership = function(volume) {
|
||||
ModalService.confirmVolumeOwnershipChange(function (confirmed) {
|
||||
if(!confirmed) { return; }
|
||||
removeVolumeResourceControl(volume);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.changePaginationCount = function() {
|
||||
Pagination.setPaginationCount('volumes', $scope.state.pagination_count);
|
||||
};
|
||||
|
@ -52,9 +70,21 @@ function ($scope, $state, Volume, Messages, Pagination) {
|
|||
if (d.message) {
|
||||
Messages.error("Unable to remove volume", {}, d.message);
|
||||
} else {
|
||||
Messages.send("Volume deleted", volume.Name);
|
||||
var index = $scope.volumes.indexOf(volume);
|
||||
$scope.volumes.splice(index, 1);
|
||||
if (volume.Metadata && volume.Metadata.ResourceControl) {
|
||||
ResourceControlService.removeVolumeResourceControl(volume.Metadata.ResourceControl.OwnerId, volume.Name)
|
||||
.then(function success() {
|
||||
Messages.send("Volume deleted", volume.Name);
|
||||
var index = $scope.volumes.indexOf(volume);
|
||||
$scope.volumes.splice(index, 1);
|
||||
})
|
||||
.catch(function error(err) {
|
||||
Messages.error("Failure", err, "Unable to remove volume ownership");
|
||||
});
|
||||
} else {
|
||||
Messages.send("Volume deleted", volume.Name);
|
||||
var index = $scope.volumes.indexOf(volume);
|
||||
$scope.volumes.splice(index, 1);
|
||||
}
|
||||
}
|
||||
complete();
|
||||
}, function (e) {
|
||||
|
@ -65,11 +95,45 @@ function ($scope, $state, Volume, Messages, Pagination) {
|
|||
});
|
||||
};
|
||||
|
||||
function mapUsersToVolumes(users) {
|
||||
angular.forEach($scope.volumes, function (volume) {
|
||||
if (volume.Metadata) {
|
||||
var volumeRC = volume.Metadata.ResourceControl;
|
||||
if (volumeRC && volumeRC.OwnerId != $scope.user.ID) {
|
||||
angular.forEach(users, function (user) {
|
||||
if (volumeRC.OwnerId === user.Id) {
|
||||
volume.Owner = user.Username;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function fetchVolumes() {
|
||||
$('#loadVolumesSpinner').show();
|
||||
var userDetails = Authentication.getUserDetails();
|
||||
$scope.user = userDetails;
|
||||
|
||||
Volume.query({}, function (d) {
|
||||
$scope.volumes = d.Volumes || [];
|
||||
$('#loadVolumesSpinner').hide();
|
||||
var volumes = d.Volumes || [];
|
||||
$scope.volumes = volumes.map(function (v) {
|
||||
return new VolumeViewModel(v);
|
||||
});
|
||||
if (userDetails.role === 1) {
|
||||
UserService.users()
|
||||
.then(function success(data) {
|
||||
mapUsersToVolumes(data);
|
||||
})
|
||||
.catch(function error(err) {
|
||||
Messages.error("Failure", err, "Unable to retrieve users");
|
||||
})
|
||||
.finally(function final() {
|
||||
$('#loadVolumesSpinner').hide();
|
||||
});
|
||||
} else {
|
||||
$('#loadVolumesSpinner').hide();
|
||||
}
|
||||
}, function (e) {
|
||||
$('#loadVolumesSpinner').hide();
|
||||
Messages.error("Failure", e, "Unable to retrieve volumes");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue