mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 07:49:41 +02:00
* fix(app): wrapper for UI refresh trigger with async/await * fix(async): $async wrapper now accepts functions with params * fix(async): $async should return a promise to be chained with ES5 .then() style * fix(async): $async with multiple params was not working * refactor(app): wrap all async functions with $async * docs(async): add link to async wrapper documentation
37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
angular.module('portainer.extensions.rbac').directive('authorization', ['Authentication', 'ExtensionService', '$async',
|
|
function(Authentication, ExtensionService, $async) {
|
|
|
|
async function linkAsync(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');
|
|
}
|
|
}
|
|
|
|
return {
|
|
restrict: 'A',
|
|
link: function(scope, elem, attrs) {
|
|
return $async(linkAsync, scope, elem, attrs);
|
|
}
|
|
}
|
|
}]);
|