mirror of
https://github.com/portainer/portainer.git
synced 2025-08-02 20:35:25 +02:00
feat(extensions): introduce RBAC extension (#2900)
This commit is contained in:
parent
27a0188949
commit
8057aa45c4
196 changed files with 3321 additions and 1316 deletions
33
app/extensions/rbac/directives/authorization.js
Normal file
33
app/extensions/rbac/directives/authorization.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
angular.module('portainer.extensions.rbac').directive('authorization', ['Authentication', 'ExtensionService',
|
||||
function(Authentication, ExtensionService) {
|
||||
return {
|
||||
restrict: 'A',
|
||||
link: async function(scope, elem, attrs) {
|
||||
elem.hide();
|
||||
try {
|
||||
const rbacEnabled = await ExtensionService.extensionEnabled(ExtensionService.EXTENSIONS.RBAC);
|
||||
if (!rbacEnabled) {
|
||||
elem.show();
|
||||
return;
|
||||
}
|
||||
} catch (err) {
|
||||
elem.show();
|
||||
return;
|
||||
}
|
||||
|
||||
var authorizations = attrs.authorization.split(",");
|
||||
for (var i = 0; i < authorizations.length; i++) {
|
||||
authorizations[i] = authorizations[i].trim();
|
||||
}
|
||||
|
||||
var hasAuthorizations = Authentication.hasAuthorizations(authorizations);
|
||||
|
||||
if (hasAuthorizations) {
|
||||
elem.show();
|
||||
} else if (!hasAuthorizations && elem[0].tagName === 'A') {
|
||||
elem.show();
|
||||
elem.addClass('portainer-disabled-link');
|
||||
}
|
||||
}
|
||||
}
|
||||
}]);
|
Loading…
Add table
Add a link
Reference in a new issue