From a76da24142a0d57b763a616da4a5f585158eb1cf Mon Sep 17 00:00:00 2001 From: Ryan Berger Date: Thu, 10 Oct 2024 16:50:45 -0400 Subject: [PATCH 1/2] Conditionally use /users-keycloak/_self endpoint when roles interface is present --- src/queries/getUserTenantsPermissions.js | 6 +++++- src/queries/getUserTenantsPermissions.test.js | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/queries/getUserTenantsPermissions.js b/src/queries/getUserTenantsPermissions.js index 6afe466a9..7e2ac2f23 100644 --- a/src/queries/getUserTenantsPermissions.js +++ b/src/queries/getUserTenantsPermissions.js @@ -16,8 +16,12 @@ const getUserTenantsPermissions = async (stripes, tenants = []) => { } = stripes; const userTenantIds = tenants.map(tenant => tenant.id || tenant); + const permUrl = stripes.hasInterface('roles') ? + `${url}/users-keycloak/_self?expandPermissions=true&fullPermissions=true` : + `${url}/perms/users/${id}/permissions?full=true&indexField=userId`; + 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', 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'] }; From 6e25cc4528198530f6b5e6380c9c2bd7dbea1b15 Mon Sep 17 00:00:00 2001 From: Ryan Berger Date: Thu, 10 Oct 2024 16:57:22 -0400 Subject: [PATCH 2/2] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21b65b78c..5c99ce43f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ * 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 `roles` interface is present. Refs STCOR-835. ## [10.1.1](https://github.com/folio-org/stripes-core/tree/v10.1.1) (2024-03-25)