Merge branch 'remove-unauth-setting' into 'develop'

Remove the guestExperience setting

See merge request soapbox-pub/soapbox-fe!1582
environments/review-develop-3zknud/deployments/443
Alex Gleason 2 years ago
commit 2f78b9ccc6

@ -5,6 +5,7 @@ import { Route, Switch } from 'react-router-dom';
import { render, screen, waitFor } from '../../../jest/test-helpers'; import { render, screen, waitFor } from '../../../jest/test-helpers';
import { normalizeAccount } from '../../../normalizers'; import { normalizeAccount } from '../../../normalizers';
import UI from '../index'; import UI from '../index';
import { WrappedRoute } from '../util/react_router_helpers';
const TestableComponent = () => ( const TestableComponent = () => (
<Switch> <Switch>
@ -12,6 +13,9 @@ const TestableComponent = () => (
<Route path='/@:username/media' exact><UI /></Route> <Route path='/@:username/media' exact><UI /></Route>
<Route path='/@:username' exact><UI /></Route> <Route path='/@:username' exact><UI /></Route>
<Route path='/login' exact><span data-testid='sign-in'>Sign in</span></Route> <Route path='/login' exact><span data-testid='sign-in'>Sign in</span></Route>
{/* WrappedRount will redirect to /login for logged out users... which will resolve to the route above! */}
<WrappedRoute path='/notifications' />
</Switch> </Switch>
); );
@ -33,53 +37,47 @@ describe('<UI />', () => {
}); });
describe('when logged out', () => { describe('when logged out', () => {
describe('with guest experience disabled', () => { describe('when viewing a Profile Page', () => {
beforeEach(() => { it('should render the Profile page', async() => {
store = { ...store, soapbox: ImmutableMap({ guestExperience: false }) }; render(
}); <TestableComponent />,
{},
describe('when viewing a Profile Page', () => { store,
it('should render the Profile page', async() => { { initialEntries: ['/@username'] },
render( );
<TestableComponent />,
{},
store,
{ initialEntries: ['/@username'] },
);
await waitFor(() => { await waitFor(() => {
expect(screen.getByTestId('cta-banner')).toHaveTextContent('Sign up now to discuss'); expect(screen.getByTestId('cta-banner')).toHaveTextContent('Sign up now to discuss');
});
}); });
}); });
});
describe('when viewing a Status Page', () => { describe('when viewing a Status Page', () => {
it('should render the Status page', async() => { it('should render the Status page', async() => {
render( render(
<TestableComponent />, <TestableComponent />,
{}, {},
store, store,
{ initialEntries: ['/@username/posts/12'] }, { initialEntries: ['/@username/posts/12'] },
); );
await waitFor(() => { await waitFor(() => {
expect(screen.getByTestId('cta-banner')).toHaveTextContent('Sign up now to discuss'); expect(screen.getByTestId('cta-banner')).toHaveTextContent('Sign up now to discuss');
});
}); });
}); });
});
describe('when viewing any other page', () => { describe('when viewing Notifications', () => {
it('should redirect to the login page', async() => { it('should redirect to the login page', async() => {
render( render(
<TestableComponent />, <TestableComponent />,
{}, {},
store, store,
{ initialEntries: ['/@username/media'] }, { initialEntries: ['/notifications'] },
); );
await waitFor(() => { await waitFor(() => {
expect(screen.getByTestId('sign-in')).toHaveTextContent('Sign in'); expect(screen.getByTestId('sign-in')).toHaveTextContent('Sign in');
});
}); });
}); });
}); });

@ -5,7 +5,7 @@ import React, { useState, useEffect, useRef, useCallback } from 'react';
import { HotKeys } from 'react-hotkeys'; import { HotKeys } from 'react-hotkeys';
import { defineMessages, useIntl } from 'react-intl'; import { defineMessages, useIntl } from 'react-intl';
import { useDispatch } from 'react-redux'; 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 { fetchFollowRequests } from 'soapbox/actions/accounts';
import { fetchReports, fetchUsers, fetchConfig } from 'soapbox/actions/admin'; 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 RemoteInstancePage from 'soapbox/pages/remote_instance_page';
import StatusPage from 'soapbox/pages/status_page'; import StatusPage from 'soapbox/pages/status_page';
import { getAccessToken, getVapidKey } from 'soapbox/utils/auth'; import { getAccessToken, getVapidKey } from 'soapbox/utils/auth';
import { cacheCurrentUrl } from 'soapbox/utils/redirect';
import { isStandalone } from 'soapbox/utils/state'; import { isStandalone } from 'soapbox/utils/state';
// import GroupSidebarPanel from '../groups/sidebar_panel'; // import GroupSidebarPanel from '../groups/sidebar_panel';
@ -258,7 +257,7 @@ const SwitchingColumnsArea: React.FC = ({ children }) => {
<WrappedRoute path='/notifications' page={DefaultPage} component={Notifications} content={children} /> <WrappedRoute path='/notifications' page={DefaultPage} component={Notifications} content={children} />
<WrappedRoute path='/search' publicRoute page={DefaultPage} component={Search} content={children} /> <WrappedRoute path='/search' page={DefaultPage} component={Search} content={children} />
{features.suggestions && <WrappedRoute path='/suggestions' publicRoute page={DefaultPage} component={FollowRecommendations} content={children} />} {features.suggestions && <WrappedRoute path='/suggestions' publicRoute page={DefaultPage} component={FollowRecommendations} content={children} />}
{features.profileDirectory && <WrappedRoute path='/directory' publicRoute page={DefaultPage} component={Directory} content={children} />} {features.profileDirectory && <WrappedRoute path='/directory' publicRoute page={DefaultPage} component={Directory} content={children} />}
@ -329,7 +328,6 @@ const UI: React.FC = ({ children }) => {
const intl = useIntl(); const intl = useIntl();
const history = useHistory(); const history = useHistory();
const dispatch = useDispatch(); const dispatch = useDispatch();
const { guestExperience } = useSoapboxConfig();
const [draggingOver, setDraggingOver] = useState<boolean>(false); const [draggingOver, setDraggingOver] = useState<boolean>(false);
const [mobile, setMobile] = useState<boolean>(isMobile(window.innerWidth)); const [mobile, setMobile] = useState<boolean>(isMobile(window.innerWidth));
@ -608,23 +606,6 @@ const UI: React.FC = ({ children }) => {
// Wait for login to succeed or fail // Wait for login to succeed or fail
if (me === null) return null; 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 <Redirect to='/login' />;
}
type HotkeyHandlers = { [key: string]: (keyEvent?: KeyboardEvent) => void }; type HotkeyHandlers = { [key: string]: (keyEvent?: KeyboardEvent) => void };
const handlers: HotkeyHandlers = { const handlers: HotkeyHandlers = {

@ -115,7 +115,6 @@ export const SoapboxConfigRecord = ImmutableRecord({
singleUserMode: false, singleUserMode: false,
singleUserModeProfile: '', singleUserModeProfile: '',
linkFooterMessage: '', linkFooterMessage: '',
guestExperience: true,
links: ImmutableMap<string, string>(), links: ImmutableMap<string, string>(),
}, 'SoapboxConfig'); }, 'SoapboxConfig');

Loading…
Cancel
Save