From dc048ef0476d8ab4490bc42702f3cfed245a031d Mon Sep 17 00:00:00 2001 From: Pavel Mineev Date: Sun, 21 Aug 2022 20:53:48 -0700 Subject: [PATCH] fix: anon cannot request data removal --- .../app/components/profile/profile.spec.tsx | 13 ++++++++++++- .../remark42/app/components/profile/profile.tsx | 5 +++-- frontend/apps/remark42/package.json | 1 + frontend/pnpm-lock.yaml | 2 ++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/frontend/apps/remark42/app/components/profile/profile.spec.tsx b/frontend/apps/remark42/app/components/profile/profile.spec.tsx index 42f6f662..0cb3a1b5 100644 --- a/frontend/apps/remark42/app/components/profile/profile.spec.tsx +++ b/frontend/apps/remark42/app/components/profile/profile.spec.tsx @@ -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'; @@ -190,4 +190,15 @@ describe('', () => { 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(); + + expect(screen.queryByText(/request my data removal/i)).not.toBeInTheDocument(); + }); }); diff --git a/frontend/apps/remark42/app/components/profile/profile.tsx b/frontend/apps/remark42/app/components/profile/profile.tsx index b113eee5..5b4fead2 100644 --- a/frontend/apps/remark42/app/components/profile/profile.tsx +++ b/frontend/apps/remark42/app/components/profile/profile.tsx @@ -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'; @@ -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'; @@ -219,7 +220,7 @@ export function Profile() { {comments === null && isCommentsLoading && } {comments !== null && commentsJSX} - {isCurrent ? ( + {isCurrent && !isUserAnonymous(user as unknown as User) ? (