2019-05-24 06:04:58 +00:00
|
|
|
angular.module('portainer.extensions.rbac')
|
2019-06-17 14:51:39 +00:00
|
|
|
.directive('disableAuthorization', ['Authentication', 'ExtensionService', '$async', function(Authentication, ExtensionService, $async) {
|
|
|
|
|
|
|
|
async function linkAsync(scope, elem, attrs) {
|
|
|
|
try {
|
|
|
|
const rbacEnabled = await ExtensionService.extensionEnabled(ExtensionService.EXTENSIONS.RBAC);
|
|
|
|
if (!rbacEnabled) {
|
2019-05-24 06:04:58 +00:00
|
|
|
elem.show();
|
|
|
|
return;
|
|
|
|
}
|
2019-06-17 14:51:39 +00:00
|
|
|
} catch (err) {
|
|
|
|
elem.show();
|
|
|
|
return;
|
|
|
|
}
|
2019-05-24 06:04:58 +00:00
|
|
|
|
2019-06-17 14:51:39 +00:00
|
|
|
var authorizations = attrs.disableAuthorization.split(",");
|
|
|
|
for (var i = 0; i < authorizations.length; i++) {
|
|
|
|
authorizations[i] = authorizations[i].trim();
|
|
|
|
}
|
2019-05-24 06:04:58 +00:00
|
|
|
|
2019-06-17 14:51:39 +00:00
|
|
|
if (!Authentication.hasAuthorizations(authorizations)) {
|
|
|
|
elem.attr('disabled', true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
restrict: 'A',
|
|
|
|
link: function (scope, elem, attrs) {
|
|
|
|
return $async(linkAsync, scope, elem, attrs);
|
2019-05-24 06:04:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}]);
|