Skip to content

Commit

Permalink
Merge pull request Sage-Bionetworks#1309 from jay-hodgson/PORTALS-3293
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgros authored Oct 23, 2024
2 parents 6e408e4 + 8e45eac commit 425f6c4
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion apps/SageAccountWeb/src/AppInitializer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function AppInitializer(props: { children?: React.ReactNode }) {
let redirectRoute = undefined
if (termsOfServiceStatus) {
if (
termsOfServiceStatus.usersCurrentTermsOfServiceState !=
termsOfServiceStatus.userCurrentTermsOfServiceState !=
TermsOfServiceState.UP_TO_DATE &&
skippedSigningUpdatedToS === false
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@ export const SignUpdatedTermsOfUsePage = (
const { mutate: signTermsOfService } = SynapseQueries.useSignTermsOfService()

const { data: tosInfo } = SynapseQueries.useTermsOfServiceInfo()
const { data: tosStatus } = SynapseQueries.useTermsOfServiceStatus()
const { data: tosStatus } = SynapseQueries.useTermsOfServiceStatus(
accessToken,
{
enabled: !!accessToken,
},
)

const isSkipAvailable =
tosStatus?.usersCurrentTermsOfServiceState ==
tosStatus?.userCurrentTermsOfServiceState ==
TermsOfServiceState.MUST_AGREE_SOON
const onSignTermsOfUse = async (event: React.SyntheticEvent) => {
event.preventDefault()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@ export const termsOfServiceNewUserStatus: TermsOfServiceStatus = {
userId: '12345',
lastAgreementDate: null,
lastAgreementVersion: null,
usersCurrentTermsOfServiceState: TermsOfServiceState.MUST_AGREE_NOW,
userCurrentTermsOfServiceState: TermsOfServiceState.MUST_AGREE_NOW,
}

export const termsOfServiceUpdatedMustAgreeNowStatus: TermsOfServiceStatus = {
userId: '12345',
lastAgreementDate: '2024-09-15T12:34:56Z',
lastAgreementVersion: '2.0.0',
usersCurrentTermsOfServiceState: TermsOfServiceState.MUST_AGREE_NOW,
userCurrentTermsOfServiceState: TermsOfServiceState.MUST_AGREE_NOW,
}

export const termsOfServiceUpdatedMustAgreeSoonStatus: TermsOfServiceStatus = {
userId: '12345',
lastAgreementDate: '2024-09-15T12:34:56Z',
lastAgreementVersion: '2.0.0',
usersCurrentTermsOfServiceState: TermsOfServiceState.MUST_AGREE_SOON,
userCurrentTermsOfServiceState: TermsOfServiceState.MUST_AGREE_SOON,
}

export const termsOfServiceUpToDateStatus: TermsOfServiceStatus = {
userId: '12345',
lastAgreementDate: '2024-09-15T12:34:56Z',
lastAgreementVersion: '2.0.0',
usersCurrentTermsOfServiceState: TermsOfServiceState.UP_TO_DATE,
userCurrentTermsOfServiceState: TermsOfServiceState.UP_TO_DATE,
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ export function useTermsOfServiceInfo(
}

export function useTermsOfServiceStatus(
accessToken?: string, //usually we can fetch the access token from the context, but this hook is used by ApplicationSessionManager which sets the access token in the context (ApplicationSessionContextProvider)!
options?: Partial<UseQueryOptions<TermsOfServiceStatus, SynapseClientError>>,
) {
const { accessToken, keyFactory } = useSynapseContext()
const { keyFactory } = useSynapseContext()
return useQuery({
...options,
queryKey: keyFactory.getTermsOfServiceStatus(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const EXPECTED_ANONYMOUS_STATE: Partial<ApplicationSessionContextType> = {
}
const TERMS_OF_SERVICE_STATUS_UP_TO_DATE: TermsOfServiceStatus = {
userId: `${MOCK_USER_ID}`,
usersCurrentTermsOfServiceState: TermsOfServiceState.UP_TO_DATE,
userCurrentTermsOfServiceState: TermsOfServiceState.UP_TO_DATE,
lastAgreementDate: '',
lastAgreementVersion: '0.0.0',
}
Expand All @@ -81,7 +81,7 @@ const EXPECTED_AUTH_STATE: Partial<ApplicationSessionContextType> = {

const TERMS_OF_SERVICE_STATUS_MUST_AGREE_NOW: TermsOfServiceStatus = {
userId: `${MOCK_USER_ID}`,
usersCurrentTermsOfServiceState: TermsOfServiceState.MUST_AGREE_NOW,
userCurrentTermsOfServiceState: TermsOfServiceState.MUST_AGREE_NOW,
lastAgreementDate: '',
lastAgreementVersion: '0.0.0',
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,9 @@ export function ApplicationSessionManager(
setHasInitializedSession(true)
})
}, [onNoAccessTokenFound])
const { data: tosStatus } = useTermsOfServiceStatus({
const { data: tosStatus } = useTermsOfServiceStatus(token, {
enabled: !!token,
})

const refreshSession = useCallback(async () => {
setTwoFactorAuthSSOError(undefined)
let token
Expand Down
2 changes: 1 addition & 1 deletion packages/synapse-types/src/TermsOfService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type TermsOfServiceStatus = {
userId: string // The ID of the user
lastAgreementDate?: string | null // The date/time when the user last agreed to the ToS, or null if never agreed
lastAgreementVersion?: string | null // The version of ToS the user last agreed to, or null if never agreed
usersCurrentTermsOfServiceState: TermsOfServiceState // Defines the user's current ToS state. Used to guide the UI in what the user needs to do with their ToS agreements. This will always be provided.
userCurrentTermsOfServiceState: TermsOfServiceState // Defines the user's current ToS state. Used to guide the UI in what the user needs to do with their ToS agreements. This will always be provided.
}

export enum TermsOfServiceState {
Expand Down

0 comments on commit 425f6c4

Please sign in to comment.