mirror of
https://github.com/portainer/portainer.git
synced 2025-08-08 23:35:31 +02:00
fix(rbac): clean leftovers (#4265)
This commit is contained in:
parent
45cada05d5
commit
b4f97efb85
5 changed files with 14 additions and 55 deletions
|
@ -23,7 +23,7 @@ angular.module('portainer.app').controller('StacksDatatableController', [
|
|||
return false;
|
||||
}
|
||||
|
||||
return !(item.External && !this.isAdmin && !this.isEndpointAdmin);
|
||||
return !(item.External && !this.isAdmin);
|
||||
};
|
||||
|
||||
this.applyFilters = applyFilters.bind(this);
|
||||
|
@ -41,7 +41,6 @@ angular.module('portainer.app').controller('StacksDatatableController', [
|
|||
|
||||
this.$onInit = function () {
|
||||
this.isAdmin = Authentication.isAdmin();
|
||||
this.isEndpointAdmin = Authentication.hasAuthorizations(['EndpointResourcesAccess']);
|
||||
this.setDefaults();
|
||||
this.prepareTableFromDataset();
|
||||
|
||||
|
|
|
@ -2,8 +2,6 @@ export function UserViewModel(data) {
|
|||
this.Id = data.Id;
|
||||
this.Username = data.Username;
|
||||
this.Role = data.Role;
|
||||
this.EndpointAuthorizations = data.EndpointAuthorizations;
|
||||
this.PortainerAuthorizations = data.PortainerAuthorizations;
|
||||
if (data.Role === 1) {
|
||||
this.RoleName = 'administrator';
|
||||
} else {
|
||||
|
|
|
@ -7,8 +7,7 @@ angular.module('portainer.app').factory('Authentication', [
|
|||
'LocalStorage',
|
||||
'StateManager',
|
||||
'EndpointProvider',
|
||||
'UserService',
|
||||
function AuthenticationFactory($async, $state, Auth, OAuth, jwtHelper, LocalStorage, StateManager, EndpointProvider, UserService) {
|
||||
function AuthenticationFactory($async, $state, Auth, OAuth, jwtHelper, LocalStorage, StateManager, EndpointProvider) {
|
||||
'use strict';
|
||||
|
||||
var service = {};
|
||||
|
@ -21,7 +20,6 @@ angular.module('portainer.app').factory('Authentication', [
|
|||
service.isAuthenticated = isAuthenticated;
|
||||
service.getUserDetails = getUserDetails;
|
||||
service.isAdmin = isAdmin;
|
||||
service.hasAuthorizations = hasAuthorizations;
|
||||
|
||||
async function initAsync() {
|
||||
try {
|
||||
|
@ -81,19 +79,12 @@ angular.module('portainer.app').factory('Authentication', [
|
|||
return user;
|
||||
}
|
||||
|
||||
async function retrievePermissions() {
|
||||
const data = await UserService.user(user.ID);
|
||||
user.endpointAuthorizations = data.EndpointAuthorizations;
|
||||
user.portainerAuthorizations = data.PortainerAuthorizations;
|
||||
}
|
||||
|
||||
async function setUser(jwt) {
|
||||
LocalStorage.storeJWT(jwt);
|
||||
var tokenPayload = jwtHelper.decodeToken(jwt);
|
||||
user.username = tokenPayload.username;
|
||||
user.ID = tokenPayload.id;
|
||||
user.role = tokenPayload.role;
|
||||
await retrievePermissions();
|
||||
}
|
||||
|
||||
function isAdmin() {
|
||||
|
@ -103,23 +94,6 @@ angular.module('portainer.app').factory('Authentication', [
|
|||
return false;
|
||||
}
|
||||
|
||||
function hasAuthorizations(authorizations) {
|
||||
const endpointId = EndpointProvider.endpointID();
|
||||
if (isAdmin()) {
|
||||
return true;
|
||||
}
|
||||
if (!user.endpointAuthorizations || (user.endpointAuthorizations && !user.endpointAuthorizations[endpointId])) {
|
||||
return false;
|
||||
}
|
||||
for (var i = 0; i < authorizations.length; i++) {
|
||||
var authorization = authorizations[i];
|
||||
if (user.endpointAuthorizations[endpointId][authorization]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return service;
|
||||
},
|
||||
]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue