From 0d1aa47d4bff26307fea72eccc19a21957a79368 Mon Sep 17 00:00:00 2001 From: Ryan Berger Date: Wed, 16 Oct 2024 15:51:15 -0400 Subject: [PATCH] [STCOR-835] refactor getUserTenantsPermissions to leverage roles instead 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 49bf361990fbc3209727fb608ef70a70328a3d61) --- CHANGELOG.md | 8 ++++++-- src/queries/getUserTenantsPermissions.js | 8 +++++--- src/queries/getUserTenantsPermissions.test.js | 3 +++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2495aaecd..665cdc4b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/src/queries/getUserTenantsPermissions.js b/src/queries/getUserTenantsPermissions.js index 6afe466a9..0fbaf201c 100644 --- a/src/queries/getUserTenantsPermissions.js +++ b/src/queries/getUserTenantsPermissions.js @@ -8,7 +8,6 @@ */ const getUserTenantsPermissions = async (stripes, tenants = []) => { const { - user: { user: { id } }, okapi: { url, token, @@ -16,8 +15,11 @@ const getUserTenantsPermissions = async (stripes, tenants = []) => { } = 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', @@ -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); diff --git a/src/queries/getUserTenantsPermissions.test.js b/src/queries/getUserTenantsPermissions.test.js index d9ae848be..bd53ee4ea 100644 --- a/src/queries/getUserTenantsPermissions.test.js +++ b/src/queries/getUserTenantsPermissions.test.js @@ -18,6 +18,7 @@ describe('getUserTenantsPermissions', () => { url: 'http://okapiUrl', token: 'elevensies', }, + hasInterface: jest.fn(), }; mockFetch.mockResolvedValueOnce('non-okapi-success'); @@ -38,6 +39,7 @@ describe('getUserTenantsPermissions', () => { okapi: { url: 'http://okapiUrl', }, + hasInterface: jest.fn(), }; mockFetch.mockResolvedValueOnce('non-okapi-success'); @@ -54,6 +56,7 @@ describe('getUserTenantsPermissions', () => { okapi: { url: 'http://okapiUrl', }, + hasInterface: jest.fn(), }; const t1 = { p: ['t1-p1', 't1-p2'] };