-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Guard and cache fetchPermission chrome API. #975
Guard and cache fetchPermission chrome API. #975
Conversation
Codecov Report
@@ Coverage Diff @@
## master #975 +/- ##
==========================================
+ Coverage 52.59% 52.88% +0.28%
==========================================
Files 57 57
Lines 1061 1076 +15
Branches 206 209 +3
==========================================
+ Hits 558 569 +11
- Misses 398 402 +4
Partials 105 105
|
src/js/rbac/fetchPermissions.js
Outdated
|
||
export const createFetchPermissionsWatcher = (getUser, libjwt) => { | ||
let currentCall = undefined; | ||
const cache = new CacheAdapter( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't create new cache, I'd rather share chrome cache from all over places, meaning passing it to createFetchPermissionsWatcher
const createFetchPermissionsWatcher = (cache) => {
let currentCall = undefined;
return async (userToken, app = '') => {
if (insights.chrome.getBundle() === 'openshift') {
return Promise.resolve([]);
}
const permissions = await cache.getItem('permissions');
if (permissions) {
return permissions;
}
if (typeof currentCall === 'undefined') {
currentCall = getUser().then(() => fetchPermissions(userToken, app).then((data) => {
currentCall = undefined;
cache.setItem('permissions', data);
return data;
}));
}
return currentCall;
};
}
src/js/entry.js
Outdated
libjwt.jwt.logoutAllTabs(); | ||
}); | ||
}; | ||
const fetchPermissions = createFetchPermissionsWatcher(getUser, libjwt); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd change this to consume only cahce
const fetchPermissions = getUser().then(() => createFetchPermissionsWatcher(cache));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to make it work correctly you'd have to moce let chromeCache
on line 56 move above chrome bootstrap.
d2b61c9
to
53409b2
Compare
451832b
to
77dd0b2
Compare
75fd24e
to
a8446ab
Compare
@karelhala I have forgotten to update the tests. |
@karelhala also using the global cache does not work 😢 The endpoint is called before the cache is created... Let's use the local cache for now and I will come up with a solution to make the chrome cache global in a different PR.
|
ada2556
to
52c3f12
Compare
jira: https://issues.redhat.com/browse/RHCLOUD-9200
Changes
fetchPermission
chrome API callfetchPermission
configfetchPermission
call