From 7cbfee38acdb1a0b225a5f6f594eec9c90389234 Mon Sep 17 00:00:00 2001 From: Alexander Lee Date: Wed, 19 Jul 2023 12:58:18 +0800 Subject: [PATCH] Fix/restrict repo privatisation to email login (#1347) * fix: add conditional return for useGetSettings if non-email login * chore: update useGetSettings call sites * fix: swap isEmailLogin to optional and block branch until launchdarkly --- src/hooks/settingsHooks/useGetSettings.ts | 22 +++++++++++++++------- src/layouts/Settings/Settings.tsx | 6 +++++- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/hooks/settingsHooks/useGetSettings.ts b/src/hooks/settingsHooks/useGetSettings.ts index bc1b1fb258..0c726c51dc 100644 --- a/src/hooks/settingsHooks/useGetSettings.ts +++ b/src/hooks/settingsHooks/useGetSettings.ts @@ -127,17 +127,25 @@ const extractPassword = ( } export const useGetSettings = ( - siteName: string + siteName: string, + isEmailLogin?: boolean ): UseQueryResult => { + const shouldGetPrivacyDetails = + isEmailLogin === undefined ? false : isEmailLogin return useQuery( - [SETTINGS_CONTENT_KEY, siteName], + [SETTINGS_CONTENT_KEY, siteName, shouldGetPrivacyDetails], async () => { const siteSettings = await SettingsService.get({ siteName }) - // TODO: reimplement actual functionality once netlify issue resolved - // const passwordSettings = await SettingsService.getPassword({ siteName }) - const passwordSettings = { - isAmplifySite: false, - password: "", + let passwordSettings + const isLaunchDarklyImplemented = false + if (shouldGetPrivacyDetails && isLaunchDarklyImplemented) { + // TODO: LaunchDarkly to allow specific groups to access this feature first + passwordSettings = await SettingsService.getPassword({ siteName }) + } else { + passwordSettings = { + isAmplifySite: false, + password: "", + } } const convertedSettings = convertFromBe(siteSettings) const parsedPassword = extractPassword(passwordSettings) diff --git a/src/layouts/Settings/Settings.tsx b/src/layouts/Settings/Settings.tsx index 01dab29141..d7d530aee5 100644 --- a/src/layouts/Settings/Settings.tsx +++ b/src/layouts/Settings/Settings.tsx @@ -14,6 +14,8 @@ import { useEffect, useRef } from "react" import { useForm, FormProvider } from "react-hook-form" import { useParams } from "react-router-dom" +import { useLoginContext } from "contexts/LoginContext" + import { useGetSettings, useUpdateSettings } from "hooks/settingsHooks" import { useErrorToast, useSuccessToast } from "utils/toasts" @@ -34,11 +36,13 @@ import { SocialMediaSettings } from "./SocialMediaSettings" export const Settings = (): JSX.Element => { const { siteName } = useParams<{ siteName: string }>() + const { userId } = useLoginContext() + const isGithubUser = userId !== "Unknown user" && !!userId const { data: settingsData, isLoading: isGetSettingsLoading, isError: isGetSettingsError, - } = useGetSettings(siteName) + } = useGetSettings(siteName, !isGithubUser) const errorToast = useErrorToast() // Trigger an error toast informing the user if settings data could not be fetched