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-905: based on 'users-keycloak' interface use bl-users or users-keycloak for _self endpoint in useUserTenantPermissions #1556

Merged
merged 12 commits into from
Nov 15, 2024
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 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.
* Send the stored central tenant name in the header on logout. Refs STCOR-900.
* Use the `users-keycloak/_self` endpoint conditionally when the `users-keycloak` interface is present; otherwise, use `bl-users/_self` within `useUserSelfTenantPermissions`. Refs STCOR-905.

## [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)
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export { useChunkedCQLFetch } from './src/queries';
export { getUserTenantsPermissions } from './src/queries';

/* Hooks */
export { useUserTenantPermissions } from './src/hooks';
export { useUserSelfTenantPermissions } from './src/hooks';

/* misc */
export { supportedLocales } from './src/loginServices';
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default as useUserTenantPermissions } from './useUserTenantPermissions'; // eslint-disable-line import/prefer-default-export
export { default as useUserSelfTenantPermissions } from './useUserSelfTenantPermissions';

Check failure on line 1 in src/hooks/index.js

View workflow job for this annotation

GitHub Actions / ui / Install and lint / Install and lint

Prefer default export
7 changes: 3 additions & 4 deletions src/hooks/useUserSelfTenantPermissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,22 @@ const useUserSelfTenantPermissions = (
});
const [namespace] = useNamespace({ key: 'user-self-permissions' });

const user = stripes.user.user;
const permPath = stripes.hasInterface('users-keycloak') ? 'users-keycloak' : 'bl-users';

const {
isFetching,
isFetched,
isLoading,
data,
} = useQuery(
[namespace, user?.id, tenantId],
[namespace, tenantId],
({ signal }) => {
return api.get(
'users-keycloak/_self',
`${permPath}/_self?expandPermissions=true`,
{ signal },
).json();
},
{
enabled: Boolean(user?.id && tenantId) && stripes.hasInterface('users-keycloak'),
keepPreviousData: true,
...options,
},
Expand Down
8 changes: 1 addition & 7 deletions src/hooks/useUserSelfTenantPermissions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ jest.mock('../components', () => ({
}));
jest.mock('../StripesContext', () => ({
useStripes: () => ({
user: {
user: {
id: 'userId'
}
},
hasInterface: () => true
}),
}));
Expand Down Expand Up @@ -58,14 +53,13 @@ describe('useUserSelfTenantPermissions', () => {

it('should fetch user permissions for specified tenant', async () => {
const options = {
userId: 'userId',
tenantId: 'tenantId',
};
const { result } = renderHook(() => useUserSelfTenantPermissions(options), { wrapper });

await waitFor(() => !result.current.isLoading);

expect(setHeaderMock).toHaveBeenCalledWith('X-Okapi-Tenant', options.tenantId);
expect(getMock).toHaveBeenCalledWith('users-keycloak/_self', expect.objectContaining({}));
expect(getMock).toHaveBeenCalledWith('users-keycloak/_self?expandPermissions=true', expect.objectContaining({}));
});
});
61 changes: 0 additions & 61 deletions src/hooks/useUserTenantPermissionNames.js

This file was deleted.

72 changes: 0 additions & 72 deletions src/hooks/useUserTenantPermissionNames.test.js

This file was deleted.

42 changes: 0 additions & 42 deletions src/hooks/useUserTenantPermissions.js

This file was deleted.

80 changes: 0 additions & 80 deletions src/hooks/useUserTenantPermissions.test.js

This file was deleted.

Loading