From 569fa9ffbb2087ecc79f09cd0f6e9d3fb42fe8a4 Mon Sep 17 00:00:00 2001 From: kyle-ssg Date: Tue, 17 Dec 2024 16:38:40 +0000 Subject: [PATCH] Don't fetch user overrides in edit feature if user has no permissions --- frontend/web/components/modals/CreateFlag.js | 52 ++++++++++++-------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/frontend/web/components/modals/CreateFlag.js b/frontend/web/components/modals/CreateFlag.js index 20fa7f1f9967..7b5abb74b185 100644 --- a/frontend/web/components/modals/CreateFlag.js +++ b/frontend/web/components/modals/CreateFlag.js @@ -46,6 +46,7 @@ import { saveFeatureWithValidation } from 'components/saveFeatureWithValidation' import PlanBasedBanner from 'components/PlanBasedAccess' import FeatureHistory from 'components/FeatureHistory' import WarningMessage from 'components/WarningMessage' +import { getPermission } from 'common/services/usePermission' const CreateFlag = class extends Component { static displayName = 'CreateFlag' @@ -220,26 +221,37 @@ const CreateFlag = class extends Component { userOverridesPage = (page) => { if (Utils.getIsEdge()) { if (!Utils.getShouldHideIdentityOverridesTab(ProjectStore.model)) { - data - .get( - `${Project.api}environments/${this.props.environmentId}/edge-identity-overrides?feature=${this.props.projectFlag.id}&page=${page}`, - ) - .then((userOverrides) => { - this.setState({ - userOverrides: userOverrides.results.map((v) => ({ - ...v.feature_state, - identity: { - id: v.identity_uuid, - identifier: v.identifier, - }, - })), - userOverridesPaging: { - count: userOverrides.count, - currentPage: page, - next: userOverrides.next, - }, - }) - }) + getPermission(getStore(), { + id: this.props.environmentId, + level: 'environment', + permissions: 'VIEW_IDENTITIES', + }).then((permissions) => { + if (permissions?.length) { + data + .get( + `${Project.api}environments/${this.props.environmentId}/edge-identity-overrides?feature=${this.props.projectFlag.id}&page=${page}`, + ) + .then((userOverrides) => { + this.setState({ + userOverrides: userOverrides.results.map((v) => ({ + ...v.feature_state, + identity: { + id: v.identity_uuid, + identifier: v.identifier, + }, + })), + userOverridesPaging: { + count: userOverrides.count, + currentPage: page, + next: userOverrides.next, + }, + }) + }) + .catch((e) => { + console.log('Cannot retrieve user overrides') + }) + } + }) } return