diff --git a/package.json b/package.json index ad09a2912..a0c309e7c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "nosgestesclimat-site-nextjs", "license": "MIT", - "version": "2.9.2", + "version": "2.9.3", "description": "The leading open source climate footprint calculator", "repository": { "type": "git", diff --git a/src/app/(simulation)/(large-layout)/organisations/[orgaSlug]/campagnes/[pollSlug]/_components/AdminSection.tsx b/src/app/(simulation)/(large-layout)/organisations/[orgaSlug]/campagnes/[pollSlug]/_components/AdminSection.tsx index f7c55bde3..4514d3c1f 100644 --- a/src/app/(simulation)/(large-layout)/organisations/[orgaSlug]/campagnes/[pollSlug]/_components/AdminSection.tsx +++ b/src/app/(simulation)/(large-layout)/organisations/[orgaSlug]/campagnes/[pollSlug]/_components/AdminSection.tsx @@ -10,6 +10,8 @@ import { } from '@/constants/tracking/pages/pollDashboard' import ButtonLink from '@/design-system/inputs/ButtonLink' import CopyInput from '@/design-system/inputs/CopyInput' +import useFetchOrganisation from '@/hooks/organisations/useFetchOrganisation' +import { useUser } from '@/publicodes-state' import type { PublicOrganisationPoll } from '@/types/organisations' import { trackEvent } from '@/utils/matomo/trackEvent' import { useParams } from 'next/navigation' @@ -21,7 +23,25 @@ type Props = { export default function AdminSection({ poll }: Props) { const { orgaSlug, pollSlug } = useParams() - if (!poll?.organisation.administrators) return null + const { user } = useUser() + + // Organisation can only be fetched by a authentified organisation administrator + const { data: organisation, isLoading: isLoadingOrganisation } = + useFetchOrganisation() + + // Temp hotfix to display the admin section + const isAdmin = + poll?.organisation.administrators || + organisation?.administrators.find( + ({ userId, email }) => + userId === user.userId || + // Cover possible edge case where admin changes browser and looses his/her original userId + email === user.organisation?.administratorEmail || + // Unsecure remove as soon as possible + organisation?.slug === user.organisation?.slug + ) + + if (!isAdmin || isLoadingOrganisation) return null return (
diff --git a/src/types/organisations.d.ts b/src/types/organisations.d.ts index e77aed64a..74187f88b 100644 --- a/src/types/organisations.d.ts +++ b/src/types/organisations.d.ts @@ -24,6 +24,7 @@ type VerifiedUser = { optedInForCommunications: boolean createdAt: string updatedAt: string | null + userId: string } type BaseOrganisation = {