1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-01 20:05:23 +02:00

fix(app): wrapper for UI refresh trigger with async/await (#2945)

* 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
This commit is contained in:
xAt0mZ 2019-06-17 16:51:39 +02:00 committed by GitHub
parent 09cf55a7dc
commit 71b1da8d32
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 167 additions and 92 deletions

View file

@ -1,27 +1,32 @@
angular.module('portainer.extensions.rbac')
.directive('disableAuthorization', ['Authentication', 'ExtensionService', function(Authentication, ExtensionService) {
return {
restrict: 'A',
link: async function (scope, elem, attrs) {
try {
const rbacEnabled = await ExtensionService.extensionEnabled(ExtensionService.EXTENSIONS.RBAC);
if (!rbacEnabled) {
elem.show();
return;
}
} catch (err) {
.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) {
elem.show();
return;
}
} catch (err) {
elem.show();
return;
}
var authorizations = attrs.disableAuthorization.split(",");
for (var i = 0; i < authorizations.length; i++) {
authorizations[i] = authorizations[i].trim();
}
var authorizations = attrs.disableAuthorization.split(",");
for (var i = 0; i < authorizations.length; i++) {
authorizations[i] = authorizations[i].trim();
}
if (!Authentication.hasAuthorizations(authorizations)) {
elem.attr('disabled', true);
}
if (!Authentication.hasAuthorizations(authorizations)) {
elem.attr('disabled', true);
}
}
return {
restrict: 'A',
link: function (scope, elem, attrs) {
return $async(linkAsync, scope, elem, attrs);
}
}
}]);