Skip to content
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

[STCOR-835] refactor getUserTenantsPermissions to leverage roles instead of permissions #1543

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion src/queries/getUserTenantsPermissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
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
Loading