Skip to content

Commit

Permalink
[STCOR-835] refactor getUserTenantsPermissions to leverage roles inst…
Browse files Browse the repository at this point in the history
…ead of permissions (#1543)

* Conditionally use /users-keycloak/_self endpoint when roles interface is present

* Update CHANGELOG

* Update URLs

* CHANGELOG and lint fix

* Match old API respsonse

* Clarify URL code
  • Loading branch information
ryandberger authored Oct 16, 2024
1 parent cc8ef65 commit 49bf361
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
* useUserTenantPermissions hook - provide `isFetched` property. Refs STCOR-890.
* Reword error message "Error: server is forbidden, unreachable or down. VPN issue?". Refs STCOR-893.
* Move session timeout banner to the bottom of the page. Refs STCOR-883.
* Conditionally use `/users-keycloak/_self` endpoint when `users-keycloak` interface is present. Refs STCOR-835.
* Wait longer before declaring a rotation request to be stale. Refs STCOR-895.


## [10.1.1](https://github.com/folio-org/stripes-core/tree/v10.1.1) (2024-03-25)
[Full Changelog](https://github.com/folio-org/stripes-core/compare/v10.1.0...v10.1.1)

Expand Down
8 changes: 5 additions & 3 deletions src/queries/getUserTenantsPermissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@
*/
const getUserTenantsPermissions = async (stripes, tenants = []) => {
const {
user: { user: { id } },
okapi: {
url,
token,
}
} = stripes;
const userTenantIds = tenants.map(tenant => tenant.id || tenant);

const permPath = stripes.hasInterface('users-keycloak') ? 'users-keycloak' : 'bl-users';
const permUrl = `${url}/${permPath}/_self?expandPermissions=true`;

const promises = userTenantIds.map(async (tenantId) => {
const result = await fetch(`${url}/perms/users/${id}/permissions?full=true&indexField=userId`, {
const result = await fetch(permUrl, {
headers: {
'X-Okapi-Tenant': tenantId,
'Content-Type': 'application/json',
Expand All @@ -28,7 +30,7 @@ const getUserTenantsPermissions = async (stripes, tenants = []) => {

const json = await result.json();

return { tenantId, ...json };
return { tenantId, permissionNames: json?.permissions?.permissions, ...json };
});

const userTenantsPermissions = await Promise.allSettled(promises);
Expand Down
3 changes: 3 additions & 0 deletions src/queries/getUserTenantsPermissions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('getUserTenantsPermissions', () => {
url: 'http://okapiUrl',
token: 'elevensies',
},
hasInterface: jest.fn(),
};
mockFetch.mockResolvedValueOnce('non-okapi-success');

Expand All @@ -38,6 +39,7 @@ describe('getUserTenantsPermissions', () => {
okapi: {
url: 'http://okapiUrl',
},
hasInterface: jest.fn(),
};
mockFetch.mockResolvedValueOnce('non-okapi-success');

Expand All @@ -54,6 +56,7 @@ describe('getUserTenantsPermissions', () => {
okapi: {
url: 'http://okapiUrl',
},
hasInterface: jest.fn(),
};

const t1 = { p: ['t1-p1', 't1-p2'] };
Expand Down

0 comments on commit 49bf361

Please sign in to comment.