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

(cherry picked from commit 49bf361)
  • Loading branch information
ryandberger authored and zburke committed Oct 31, 2024
1 parent 25bb290 commit 0d1aa47
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Change history for stripes-core

## [10.2.0](https://github.com/folio-org/stripes-core/tree/v10.2.0) (2024-10-11)
[Full Changelog](https://github.com/folio-org/stripes-core/compare/v10.1.1...v10.2.0)
## 10.2.2 IN PROGRESS

* Conditionally use `/users-keycloak/_self` endpoint when `users-keycloak` interface is present. Refs STCOR-835.

## [10.2.1](https://github.com/folio-org/stripes-core/tree/v10.2.1) (2024-10-30)
[Full Changelog](https://github.com/folio-org/stripes-core/compare/v10.2.0...v10.2.1)

* Wait longer before declaring a rotation request to be stale. Refs STCOR-895.

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 0d1aa47

Please sign in to comment.