From e7e1b7b67e908d269e97cbbeb67b12b99759cbc1 Mon Sep 17 00:00:00 2001 From: Marko Haarni Date: Fri, 27 Oct 2023 12:14:23 +0300 Subject: [PATCH] HAI-2083 Fix application edit and delete buttons not displayed (#400) 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. --- .../hanke/hankeUsers/UserRightsCheck.test.tsx | 18 ++++++++++++++++++ .../hanke/hankeUsers/UserRightsCheck.tsx | 6 ++++++ 2 files changed, 24 insertions(+) diff --git a/src/domain/hanke/hankeUsers/UserRightsCheck.test.tsx b/src/domain/hanke/hankeUsers/UserRightsCheck.test.tsx index b2a5f8b1c..06be23cfb 100644 --- a/src/domain/hanke/hankeUsers/UserRightsCheck.test.tsx +++ b/src/domain/hanke/hankeUsers/UserRightsCheck.test.tsx @@ -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( + +

Children

+
, + ); + + await waitFor(() => { + expect(screen.getByText('Children')).toBeInTheDocument(); + }); + + jest.resetModules(); + window._env_ = OLD_ENV; +}); diff --git a/src/domain/hanke/hankeUsers/UserRightsCheck.tsx b/src/domain/hanke/hankeUsers/UserRightsCheck.tsx index 0db403f75..a6189086f 100644 --- a/src/domain/hanke/hankeUsers/UserRightsCheck.tsx +++ b/src/domain/hanke/hankeUsers/UserRightsCheck.tsx @@ -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. @@ -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;