Skip to content

Commit

Permalink
refactor(27674): secure DATAHUB_EDIT_POLICY_ENABLED
Browse files Browse the repository at this point in the history
  • Loading branch information
vanch3d committed Dec 16, 2024
1 parent a7b7f84 commit cba124d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Node } from 'reactflow'
import { useTranslation } from 'react-i18next'
import { Box, Button, HStack, Icon, Stack } from '@chakra-ui/react'

import config from '@/config'

import PolicyErrorReport from '@datahub/components/helpers/PolicyErrorReport.tsx'
import { usePolicyDryRun } from '@datahub/hooks/usePolicyDryRun.ts'
import useDataHubDraftStore from '@datahub/hooks/useDataHubDraftStore.ts'
Expand Down Expand Up @@ -34,8 +36,7 @@ export const ToolboxDryRun: FC<ToolboxDryRunProps> = ({ onActiveStep, onShowNode
} = usePolicyChecksStore()

const CheckIcon = useMemo(() => getDryRunStatusIcon(status), [status])
const isEditEnabled =
import.meta.env.VITE_FLAG_DATAHUB_EDIT_POLICY_ENABLED === 'true' || statusDraft === DesignerStatus.DRAFT
const isEditEnabled = config.features.DATAHUB_EDIT_POLICY_ENABLED || statusDraft === DesignerStatus.DRAFT

const handleCheckPolicy = () => {
if (!selectedNode) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { FC } from 'react'
import { useTranslation } from 'react-i18next'
import { HStack, Text, VStack, ButtonGroup } from '@chakra-ui/react'

import config from '@/config'

import { DataHubNodeType, DesignerStatus } from '@datahub/types.ts'
import Tool from '@datahub/components/controls/Tool.tsx'
import { DesignerToolBoxProps } from '@datahub/components/controls/DesignerToolbox.tsx'
Expand All @@ -11,8 +13,7 @@ export const ToolboxNodes: FC<DesignerToolBoxProps> = () => {
const { t } = useTranslation('datahub')
const { nodes, status } = useDataHubDraftStore()

const isEditEnabled =
import.meta.env.VITE_FLAG_DATAHUB_EDIT_POLICY_ENABLED === 'true' || status === DesignerStatus.DRAFT
const isEditEnabled = config.features.DATAHUB_EDIT_POLICY_ENABLED || status === DesignerStatus.DRAFT
const isDraftEmpty = nodes.length === 0

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { UseMutateAsyncFunction } from '@tanstack/react-query'
import { Box, Button, HStack, Icon, Stack, useToast } from '@chakra-ui/react'
import { MdPublishedWithChanges } from 'react-icons/md'

import config from '@/config'

import { BehaviorPolicy, DataPolicy, Schema, Script } from '@/api/__generated__'

import { useCreateDataPolicy } from '@datahub/api/hooks/DataHubDataPoliciesService/useCreateDataPolicy.tsx'
Expand Down Expand Up @@ -57,8 +59,7 @@ export const ToolboxPublish: FC<DesignerToolBoxProps> = ({ onActiveStep }) => {
const createBehaviorPolicy = useCreateBehaviorPolicy()
const toast = useToast()

const isEditEnabled =
import.meta.env.VITE_FLAG_DATAHUB_EDIT_POLICY_ENABLED === 'true' || statusDraft === DesignerStatus.DRAFT
const isEditEnabled = config.features.DATAHUB_EDIT_POLICY_ENABLED || statusDraft === DesignerStatus.DRAFT
const isValid = !!report && report.length >= 1 && report?.every((e) => !e.error)

const handleMutation = async (promise: Promise<ValidMutate>, type: DataHubNodeType) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ButtonGroup } from '@chakra-ui/react'
import IconButton from '@/components/Chakra/IconButton.tsx'
import { useTranslation } from 'react-i18next'
import { LuFileEdit, LuTrash2, LuFileSearch, LuDownload } from 'react-icons/lu'
import config from '@/config'

interface DataHubListActionProps {
onEdit?: MouseEventHandler<HTMLButtonElement>
Expand All @@ -13,7 +14,7 @@ interface DataHubListActionProps {

const DataHubListAction: FC<DataHubListActionProps> = ({ onEdit, onDelete, onDownload, isAccessDisabled = false }) => {
const { t } = useTranslation('datahub')
const isEditEnabled = import.meta.env.VITE_FLAG_DATAHUB_EDIT_POLICY_ENABLED === 'true'
const isEditEnabled = config.features.DATAHUB_EDIT_POLICY_ENABLED

return (
<ButtonGroup size="sm" isAttached>
Expand Down

0 comments on commit cba124d

Please sign in to comment.