From d4de0a5358f2ee5c37a1fe18c225845ca761b039 Mon Sep 17 00:00:00 2001 From: Ian Krieger <48930920+IanKrieger@users.noreply.github.com> Date: Thu, 17 Aug 2023 10:46:39 -0400 Subject: [PATCH] fix: make sure campaign creation is not exposed accidentally (#865) * fix: make sure campaign creation is not exposed accidentally * fix: need userId * fix: equality check Co-authored-by: Graham Tackley * fix: change funtion signature --------- Co-authored-by: Graham Tackley --- src/components/Campaigns/CloneCampaign.tsx | 4 +++- src/form/fragmentUtil.ts | 2 ++ src/user/User.tsx | 9 +++++++++ src/user/campaignList/CampaignList.tsx | 1 - 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/components/Campaigns/CloneCampaign.tsx b/src/components/Campaigns/CloneCampaign.tsx index 67d3a4c7..2fad2d29 100644 --- a/src/components/Campaigns/CloneCampaign.tsx +++ b/src/components/Campaigns/CloneCampaign.tsx @@ -19,6 +19,7 @@ import { AdvertiserCampaignsDocument } from "graphql/advertiser.generated"; import { createCampaignFromFragment } from "form/fragmentUtil"; import { useAdvertiser } from "auth/hooks/queries/useAdvertiser"; import ContentCopyIcon from "@mui/icons-material/ContentCopy"; +import { useUser } from "auth/hooks/queries/useUser"; interface Props { campaignFragment?: CampaignFragment | null; @@ -27,6 +28,7 @@ interface Props { export function CloneCampaign({ campaignFragment, useChip }: Props) { const { advertiser } = useAdvertiser(); + const { userId } = useUser(); const history = useHistory(); const [open, setOpen] = useState(false); @@ -94,7 +96,7 @@ export function CloneCampaign({ campaignFragment, useChip }: Props) { if (campaignFragment) { copyCampaign({ variables: { - input: createCampaignFromFragment(campaignFragment), + input: createCampaignFromFragment(campaignFragment, userId), }, }); } else { diff --git a/src/form/fragmentUtil.ts b/src/form/fragmentUtil.ts index b7db3465..d95fd1ea 100644 --- a/src/form/fragmentUtil.ts +++ b/src/form/fragmentUtil.ts @@ -5,6 +5,7 @@ import { AdSetFragment } from "graphql/ad-set.generated"; export function createCampaignFromFragment( data: CampaignFragment, + userId?: string, ): CreateCampaignInput { const adSets: CreateAdSetInput[] = data.adSets.map((adSet) => createAdSetFromFragment(adSet), @@ -12,6 +13,7 @@ export function createCampaignFromFragment( const two = moment().utc().add(3, "days"); return { + userId, adSets: adSets && adSets.length > 0 ? adSets : undefined, advertiserId: data.advertiser.id, budget: data.budget, diff --git a/src/user/User.tsx b/src/user/User.tsx index 2b4e7c64..41ff4d2e 100644 --- a/src/user/User.tsx +++ b/src/user/User.tsx @@ -18,6 +18,7 @@ import { Navbar } from "components/Navigation/Navbar"; import { CampaignView } from "user/views/user/CampaignView"; import { CampaignReportView } from "user/views/user/CampaignReportView"; import { Profile } from "user/views/user/Profile"; +import { IAdvertiser } from "auth/context/auth.interface"; const buildApolloClient = () => { const httpLink = createHttpLink({ @@ -50,11 +51,13 @@ export function User() { a.selfServiceCreate} /> a.selfServiceEdit} /> boolean; } const ProtectedRoute = ({ authedComponent, unauthedComponent, path, + validateAdvertiserProperty = () => true, }: ProtectedProps) => { const { advertiser } = useAdvertiser(); @@ -105,6 +110,10 @@ const ProtectedRoute = ({ return ; } + if (!validateAdvertiserProperty(advertiser)) { + return ; + } + return ( void; } const CampaignCheckBox = (props: CheckBoxProps) => { - console.log(props.selectedCampaigns); const campaignSelected = props.selectedCampaigns.some( (c) => c === props.campaign.id, );