From 5f88fc267624ed39f445358c0b2597f3d9fd9a06 Mon Sep 17 00:00:00 2001 From: Ian Krieger Date: Thu, 17 Aug 2023 09:29:46 -0400 Subject: [PATCH 1/4] fix: make sure campaign creation is not exposed accidentally --- src/user/User.tsx | 18 ++++++++++++++++++ src/user/campaignList/CampaignList.tsx | 1 - 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/user/User.tsx b/src/user/User.tsx index 2b4e7c64..5da66d6f 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,19 @@ export function User() { { const { advertiser } = useAdvertiser(); @@ -105,6 +116,13 @@ const ProtectedRoute = ({ return ; } + if ( + validateAdvertiserProperty && + advertiser[validateAdvertiserProperty.key] != validateAdvertiserProperty.val + ) { + return ; + } + return ( void; } const CampaignCheckBox = (props: CheckBoxProps) => { - console.log(props.selectedCampaigns); const campaignSelected = props.selectedCampaigns.some( (c) => c === props.campaign.id, ); From 05543690173790e90beb96d88237bdbb8cd4354a Mon Sep 17 00:00:00 2001 From: Ian Krieger Date: Thu, 17 Aug 2023 09:55:37 -0400 Subject: [PATCH 2/4] fix: need userId --- src/components/Campaigns/CloneCampaign.tsx | 4 +++- src/form/fragmentUtil.ts | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) 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..ea1f8d9c 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, From 5c4bff440c13e81be3a43faf83ff19ac6cdb31a0 Mon Sep 17 00:00:00 2001 From: Ian Krieger <48930920+IanKrieger@users.noreply.github.com> Date: Thu, 17 Aug 2023 09:56:09 -0400 Subject: [PATCH 3/4] fix: equality check Co-authored-by: Graham Tackley --- src/user/User.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/user/User.tsx b/src/user/User.tsx index 5da66d6f..32184bad 100644 --- a/src/user/User.tsx +++ b/src/user/User.tsx @@ -118,7 +118,7 @@ const ProtectedRoute = ({ if ( validateAdvertiserProperty && - advertiser[validateAdvertiserProperty.key] != validateAdvertiserProperty.val + advertiser[validateAdvertiserProperty.key] !== validateAdvertiserProperty.val ) { return ; } From 38a23150e4107216ac5dd604b63dff15e3706020 Mon Sep 17 00:00:00 2001 From: Ian Krieger Date: Thu, 17 Aug 2023 10:01:00 -0400 Subject: [PATCH 4/4] fix: change funtion signature --- src/form/fragmentUtil.ts | 2 +- src/user/User.tsx | 19 +++++-------------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/form/fragmentUtil.ts b/src/form/fragmentUtil.ts index ea1f8d9c..d95fd1ea 100644 --- a/src/form/fragmentUtil.ts +++ b/src/form/fragmentUtil.ts @@ -5,7 +5,7 @@ import { AdSetFragment } from "graphql/ad-set.generated"; export function createCampaignFromFragment( data: CampaignFragment, - userId: string, + userId?: string, ): CreateCampaignInput { const adSets: CreateAdSetInput[] = data.adSets.map((adSet) => createAdSetFromFragment(adSet), diff --git a/src/user/User.tsx b/src/user/User.tsx index 5da66d6f..41ff4d2e 100644 --- a/src/user/User.tsx +++ b/src/user/User.tsx @@ -51,19 +51,13 @@ export function User() { a.selfServiceCreate} /> a.selfServiceEdit} /> boolean; } const ProtectedRoute = ({ authedComponent, unauthedComponent, path, - validateAdvertiserProperty, + validateAdvertiserProperty = () => true, }: ProtectedProps) => { const { advertiser } = useAdvertiser(); @@ -116,10 +110,7 @@ const ProtectedRoute = ({ return ; } - if ( - validateAdvertiserProperty && - advertiser[validateAdvertiserProperty.key] != validateAdvertiserProperty.val - ) { + if (!validateAdvertiserProperty(advertiser)) { return ; }