Skip to content

Commit

Permalink
Merge pull request #997 from karelhala/fix-permissions-gate
Browse files Browse the repository at this point in the history
Fix permissions gate by changing it to object
  • Loading branch information
Hyperkid123 authored Oct 5, 2020
2 parents e35d634 + 402f05d commit 65eecb9
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/js/rbac/fetchPermissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,28 @@ const fetchPermissions = (userToken, app = '') => {
};

export const createFetchPermissionsWatcher = (chromeInstance) => {
let currentCall = undefined;
let currentCall = {};
return async (userToken, app = '', bypassCache = false) => {
if (insights.chrome.getBundle() === 'openshift') {
return Promise.resolve([]);
}
if (bypassCache) {
return fetchPermissions(userToken, app).then(data => {
chromeInstance.cache.setItem('permissions', undefined);
return data;
});
const data = await fetchPermissions(userToken, app);
chromeInstance.cache.setItem('permissions', undefined);
return data;
}
let permissions;
permissions = await chromeInstance.cache.getItem('permissions');
if (permissions) {
return permissions;
if (permissions?.[app]) {
return permissions?.[app];
}
if (typeof currentCall === 'undefined') {
currentCall = fetchPermissions(userToken, app).then((data) => {
currentCall = undefined;
chromeInstance.cache.setItem('permissions', data);
return data;
if (typeof currentCall?.[app] === 'undefined') {
currentCall[app] = await fetchPermissions(userToken, app);
chromeInstance.cache.setItem('permissions', {
...permissions || {},
[app]: currentCall[app]
});
}
return currentCall;
return currentCall?.[app];
};
};

0 comments on commit 65eecb9

Please sign in to comment.