Skip to content

Commit

Permalink
fix: anon cannot request data removal
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Mineev authored and Paul Mineev committed Aug 22, 2022
1 parent d6b2960 commit dc048ef
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
13 changes: 12 additions & 1 deletion frontend/apps/remark42/app/components/profile/profile.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import '@testing-library/jest-dom';
import { waitFor, fireEvent } from '@testing-library/preact';
import { waitFor, fireEvent, screen } from '@testing-library/preact';

import { render } from 'tests/utils';
import * as api from 'common/api';
Expand Down Expand Up @@ -190,4 +190,15 @@ describe('<Profile />', () => {
fireEvent.click(await findByRole('button', { name: /load more/i }));
expect(queryByTestId('preloader')).not.toBeInTheDocument();
});

it('should not render removal button for anonymous user', async () => {
jest
.spyOn(api, 'getUserComments')
.mockImplementation(async () => ({ comments: new Array(10).fill(commentStub), count: 15 }));
jest.spyOn(pq, 'parseQuery').mockImplementation(() => ({ ...userParamsStub, name: 'anonymous_1' }));

render(<Profile />);

expect(screen.queryByText(/request my data removal/i)).not.toBeInTheDocument();
});
});
5 changes: 3 additions & 2 deletions frontend/apps/remark42/app/components/profile/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { parseQuery } from 'utils/parse-query';
import { requestDeletion } from 'utils/email';
import { setStyles } from 'utils/set-dom-props';
import { Avatar } from 'components/avatar';
import { isUserAnonymous } from 'utils/isUserAnonymous';
import { postMessageToParent } from 'utils/post-message';
import { Comment } from 'components/comment';
import { Preloader } from 'components/preloader';
Expand All @@ -18,7 +19,7 @@ import { CrossIcon } from 'components/icons/cross';
import { IconButton } from 'components/icon-button/icon-button';
import { Button } from 'components/auth/components/button';
import { messages as authMessages } from 'components/auth/auth.messsages';
import type { Comment as CommentType, Theme } from 'common/types';
import type { Comment as CommentType, Theme, User } from 'common/types';

import styles from './profile.module.css';
import { Counter } from './components/counter';
Expand Down Expand Up @@ -219,7 +220,7 @@ export function Profile() {
{comments === null && isCommentsLoading && <Preloader className={styles.preloader} />}
{comments !== null && commentsJSX}
</section>
{isCurrent ? (
{isCurrent && !isUserAnonymous(user as unknown as User) ? (
<footer className={clsx('profile-footer', styles.footer)}>
<Button kind="hollow" size="sm" onClick={handleClickRequestRemoveData}>
<FormattedMessage id="profile.request-to-delete-data" defaultMessage="Request my data removal" />
Expand Down
1 change: 1 addition & 0 deletions frontend/apps/remark42/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"@formatjs/cli": "^5.0.2",
"@mavrin/stylelint-declaration-use-css-custom-properties": "^2.0.0",
"@prefresh/babel-plugin": "^0.4.3",
"@prefresh/core": "^1.3.4",
"@prefresh/webpack": "^3.3.4",
"@size-limit/file": "^7.0.8",
"@swc/core": "1.2.205",
Expand Down
2 changes: 2 additions & 0 deletions frontend/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dc048ef

Please sign in to comment.