From 89e0eef60f98be2f3c789fd4e1da4d9ad8186365 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 28 Jun 2022 14:28:20 -0500 Subject: [PATCH 1/2] Remove the guestExperience setting --- .../features/ui/__tests__/index.test.tsx | 74 +++++++++---------- app/soapbox/features/ui/index.tsx | 21 +----- .../normalizers/soapbox/soapbox_config.ts | 1 - 3 files changed, 37 insertions(+), 59 deletions(-) diff --git a/app/soapbox/features/ui/__tests__/index.test.tsx b/app/soapbox/features/ui/__tests__/index.test.tsx index e4a360dff..5a3164996 100644 --- a/app/soapbox/features/ui/__tests__/index.test.tsx +++ b/app/soapbox/features/ui/__tests__/index.test.tsx @@ -5,6 +5,7 @@ import { Route, Switch } from 'react-router-dom'; import { render, screen, waitFor } from '../../../jest/test-helpers'; import { normalizeAccount } from '../../../normalizers'; import UI from '../index'; +import { WrappedRoute } from '../util/react_router_helpers'; const TestableComponent = () => ( @@ -12,6 +13,9 @@ const TestableComponent = () => ( Sign in + + {/* WrappedRount will redirect to /login for logged out users... which will resolve to the route above! */} + ); @@ -33,53 +37,47 @@ describe('', () => { }); describe('when logged out', () => { - describe('with guest experience disabled', () => { - beforeEach(() => { - store = { ...store, soapbox: ImmutableMap({ guestExperience: false }) }; - }); - - describe('when viewing a Profile Page', () => { - it('should render the Profile page', async() => { - render( - , - {}, - store, - { initialEntries: ['/@username'] }, - ); + describe('when viewing a Profile Page', () => { + it('should render the Profile page', async() => { + render( + , + {}, + store, + { initialEntries: ['/@username'] }, + ); - await waitFor(() => { - expect(screen.getByTestId('cta-banner')).toHaveTextContent('Sign up now to discuss'); - }); + await waitFor(() => { + expect(screen.getByTestId('cta-banner')).toHaveTextContent('Sign up now to discuss'); }); }); + }); - describe('when viewing a Status Page', () => { - it('should render the Status page', async() => { - render( - , - {}, - store, - { initialEntries: ['/@username/posts/12'] }, - ); + describe('when viewing a Status Page', () => { + it('should render the Status page', async() => { + render( + , + {}, + store, + { initialEntries: ['/@username/posts/12'] }, + ); - await waitFor(() => { - expect(screen.getByTestId('cta-banner')).toHaveTextContent('Sign up now to discuss'); - }); + await waitFor(() => { + expect(screen.getByTestId('cta-banner')).toHaveTextContent('Sign up now to discuss'); }); }); + }); - describe('when viewing any other page', () => { - it('should redirect to the login page', async() => { - render( - , - {}, - store, - { initialEntries: ['/@username/media'] }, - ); + describe('when viewing Notifications', () => { + it('should redirect to the login page', async() => { + render( + , + {}, + store, + { initialEntries: ['/notifications'] }, + ); - await waitFor(() => { - expect(screen.getByTestId('sign-in')).toHaveTextContent('Sign in'); - }); + await waitFor(() => { + expect(screen.getByTestId('sign-in')).toHaveTextContent('Sign in'); }); }); }); diff --git a/app/soapbox/features/ui/index.tsx b/app/soapbox/features/ui/index.tsx index be3afefd9..8cf66b530 100644 --- a/app/soapbox/features/ui/index.tsx +++ b/app/soapbox/features/ui/index.tsx @@ -5,7 +5,7 @@ import React, { useState, useEffect, useRef, useCallback } from 'react'; import { HotKeys } from 'react-hotkeys'; import { defineMessages, useIntl } from 'react-intl'; import { useDispatch } from 'react-redux'; -import { Switch, useHistory, useLocation, matchPath, Redirect } from 'react-router-dom'; +import { Switch, useHistory, useLocation, Redirect } from 'react-router-dom'; import { fetchFollowRequests } from 'soapbox/actions/accounts'; import { fetchReports, fetchUsers, fetchConfig } from 'soapbox/actions/admin'; @@ -34,7 +34,6 @@ import ProfilePage from 'soapbox/pages/profile_page'; import RemoteInstancePage from 'soapbox/pages/remote_instance_page'; import StatusPage from 'soapbox/pages/status_page'; import { getAccessToken, getVapidKey } from 'soapbox/utils/auth'; -import { cacheCurrentUrl } from 'soapbox/utils/redirect'; import { isStandalone } from 'soapbox/utils/state'; // import GroupSidebarPanel from '../groups/sidebar_panel'; @@ -329,7 +328,6 @@ const UI: React.FC = ({ children }) => { const intl = useIntl(); const history = useHistory(); const dispatch = useDispatch(); - const { guestExperience } = useSoapboxConfig(); const [draggingOver, setDraggingOver] = useState(false); const [mobile, setMobile] = useState(isMobile(window.innerWidth)); @@ -608,23 +606,6 @@ const UI: React.FC = ({ children }) => { // Wait for login to succeed or fail if (me === null) return null; - const isProfileOrStatusPage = !!matchPath( - history.location.pathname, - [ - '/@:username', - '/@:username/posts/:statusId', - '/users/:username', - '/users/:username/statuses/:statusId', - ], - ); - - // Require login if Guest Experience is disabled and we're not trying - // to render a Profile or Status. - if (!me && (!guestExperience && !isProfileOrStatusPage)) { - cacheCurrentUrl(history.location); - return ; - } - type HotkeyHandlers = { [key: string]: (keyEvent?: KeyboardEvent) => void }; const handlers: HotkeyHandlers = { diff --git a/app/soapbox/normalizers/soapbox/soapbox_config.ts b/app/soapbox/normalizers/soapbox/soapbox_config.ts index d9860909d..efb3b0044 100644 --- a/app/soapbox/normalizers/soapbox/soapbox_config.ts +++ b/app/soapbox/normalizers/soapbox/soapbox_config.ts @@ -115,7 +115,6 @@ export const SoapboxConfigRecord = ImmutableRecord({ singleUserMode: false, singleUserModeProfile: '', linkFooterMessage: '', - guestExperience: true, links: ImmutableMap(), }, 'SoapboxConfig'); From 2e3718e5487cde888edab316e8d0d357cb82ae57 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 29 Jun 2022 10:14:04 -0500 Subject: [PATCH 2/2] Make /search a non-public route --- app/soapbox/features/ui/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/soapbox/features/ui/index.tsx b/app/soapbox/features/ui/index.tsx index 8cf66b530..8cd5218d6 100644 --- a/app/soapbox/features/ui/index.tsx +++ b/app/soapbox/features/ui/index.tsx @@ -257,7 +257,7 @@ const SwitchingColumnsArea: React.FC = ({ children }) => { - + {features.suggestions && } {features.profileDirectory && }