Skip to content

Commit

Permalink
Fix/restrict repo privatisation to email login (#1347)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
alexanderleegs authored Jul 19, 2023
1 parent 4e3c34b commit 7cbfee3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
22 changes: 15 additions & 7 deletions src/hooks/settingsHooks/useGetSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,25 @@ const extractPassword = (
}

export const useGetSettings = (
siteName: string
siteName: string,
isEmailLogin?: boolean
): UseQueryResult<SiteSettings> => {
const shouldGetPrivacyDetails =
isEmailLogin === undefined ? false : isEmailLogin
return useQuery<SiteSettings>(
[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)
Expand Down
6 changes: 5 additions & 1 deletion src/layouts/Settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down

0 comments on commit 7cbfee3

Please sign in to comment.