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 2022-06-30 15:15:23 +00:00
commit 2f78b9ccc6
3 zmienionych plików z 38 dodań i 60 usunięć

Wyświetl plik

@ -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 = () => (
<Switch>
@ -12,6 +13,9 @@ const TestableComponent = () => (
<Route path='/@:username/media' exact><UI /></Route>
<Route path='/@:username' exact><UI /></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>
);
@ -33,53 +37,47 @@ describe('<UI />', () => {
});
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(
<TestableComponent />,
{},
store,
{ initialEntries: ['/@username'] },
);
describe('when viewing a Profile Page', () => {
it('should render the Profile page', async() => {
render(
<TestableComponent />,
{},
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(
<TestableComponent />,
{},
store,
{ initialEntries: ['/@username/posts/12'] },
);
describe('when viewing a Status Page', () => {
it('should render the Status page', async() => {
render(
<TestableComponent />,
{},
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(
<TestableComponent />,
{},
store,
{ initialEntries: ['/@username/media'] },
);
describe('when viewing Notifications', () => {
it('should redirect to the login page', async() => {
render(
<TestableComponent />,
{},
store,
{ initialEntries: ['/notifications'] },
);
await waitFor(() => {
expect(screen.getByTestId('sign-in')).toHaveTextContent('Sign in');
});
await waitFor(() => {
expect(screen.getByTestId('sign-in')).toHaveTextContent('Sign in');
});
});
});

Wyświetl plik

@ -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';
@ -258,7 +257,7 @@ const SwitchingColumnsArea: React.FC = ({ 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.profileDirectory && <WrappedRoute path='/directory' publicRoute page={DefaultPage} component={Directory} content={children} />}
@ -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<boolean>(false);
const [mobile, setMobile] = useState<boolean>(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 <Redirect to='/login' />;
}
type HotkeyHandlers = { [key: string]: (keyEvent?: KeyboardEvent) => void };
const handlers: HotkeyHandlers = {

Wyświetl plik

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