Skip to content

Commit

Permalink
HAI-2083 Fix application edit and delete buttons not displayed (#400)
Browse files Browse the repository at this point in the history
Fixed a problem where application edit and delete buttons would not
be displayed in application view when access rights feature was disabled.
Made it so that when the feature is disabled, buttons are rendered without
checking for user permissions.
  • Loading branch information
markohaarni authored Oct 27, 2023
1 parent 5bcd4b2 commit e7e1b7b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/domain/hanke/hankeUsers/UserRightsCheck.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,21 @@ test('Should not render children if user does not have required right', async ()
expect(screen.queryByText('Children')).not.toBeInTheDocument();
});
});

test('Should render children when access right feature is not enabled', async () => {
const OLD_ENV = window._env_;
window._env_.REACT_APP_FEATURE_ACCESS_RIGHTS = 0;

render(
<UserRightsCheck requiredRight="EDIT" hankeTunnus="HAI22-2">
<p>Children</p>
</UserRightsCheck>,
);

await waitFor(() => {
expect(screen.getByText('Children')).toBeInTheDocument();
});

jest.resetModules();
window._env_ = OLD_ENV;
});
6 changes: 6 additions & 0 deletions src/domain/hanke/hankeUsers/UserRightsCheck.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import useUserRightsForHanke from './hooks/useUserRightsForHanke';
import { Rights } from './hankeUser';
import { useFeatureFlags } from '../../../common/components/featureFlags/FeatureFlagsContext';

/**
* Check that user has required rights.
Expand All @@ -18,6 +19,11 @@ function UserRightsCheck({
children: React.ReactElement | null;
}) {
const { data: signedInUser } = useUserRightsForHanke(hankeTunnus);
const features = useFeatureFlags();

if (!features.accessRights) {
return children;
}

if (signedInUser?.kayttooikeudet.includes(requiredRight)) {
return children;
Expand Down

0 comments on commit e7e1b7b

Please sign in to comment.