Skip to content

Commit

Permalink
Merge pull request #378 from cofacts/hide-user-link
Browse files Browse the repository at this point in the history
Make profile page accessible for editors themselves only
  • Loading branch information
MrOrz authored Jan 21, 2021
2 parents f5c7395 + 13ef4ef commit 3ed70bb
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 68 deletions.
5 changes: 4 additions & 1 deletion components/ArticleReply/ArticleReply.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ const ArticleReply = React.memo(
return (
<>
<Box component="header" display="flex" alignItems="center">
<Avatar user={articleReply.user} className={classes.avatar} hasLink />
<Avatar
user={articleReply.user}
className={classes.avatar} /*hasLink*/
/>
<Box flexGrow={1}>
<ArticleReplySummary articleReply={articleReply} />
<ReplyInfo reply={reply} articleReplyCreatedAt={createdAt} />
Expand Down
2 changes: 1 addition & 1 deletion components/ArticleReplyFeedbackControl/Feedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function Feedback({ feedback }) {

return (
<div className={classes.root}>
<Avatar user={feedback.user} size={48} hasLink />
<Avatar user={feedback.user} size={48} /*hasLink*/ />
<Box px={2}>
<div className={classes.name}>{feedback.user?.name}</div>
<div>{feedback.comment}</div>
Expand Down
9 changes: 5 additions & 4 deletions components/ArticleReplySummary.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { t, jt } from 'ttag';
import gql from 'graphql-tag';
import ProfileLink from 'components/ProfileLink';
import { ProfileTooltip } from 'components/ProfileLink';
import cx from 'clsx';
import { TYPE_NAME } from 'constants/replyType';
import { makeStyles } from '@material-ui/core/styles';
Expand Down Expand Up @@ -33,9 +33,9 @@ function ArticleReplySummary({ articleReply, className, ...props }) {
const classes = useStyles({ replyType });

const authorElem = (
<ProfileLink key="editor" user={user} hasTooltip>
<ProfileTooltip key="editor" user={user}>
<span>{user?.name || t`Someone`}</span>
</ProfileLink>
</ProfileTooltip>
);

return (
Expand All @@ -51,9 +51,10 @@ ArticleReplySummary.fragments = {
replyType
user {
name
...ProfileLinkUserData
...ProfileTooltipUserData
}
}
${ProfileTooltip.fragments.ProfileTooltipUserData}
`,
};

Expand Down
29 changes: 24 additions & 5 deletions components/ProfileLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,27 @@ import Link from 'next/link';
import levelNames from '../constants/levelNames';
import Tooltip from './Tooltip';

export function ProfileTooltip({ user, children }) {
if (!user) {
return children;
}

const levelName = levelNames[user.level];
return (
<Tooltip title={t`Lv.${user.level} ${levelName}`} placement="top">
{children}
</Tooltip>
);
}

ProfileTooltip.fragments = {
ProfileTooltipUserData: gql`
fragment ProfileTooltipUserData on User {
level
}
`,
};

export default function ProfileLink({
user,
children,
Expand All @@ -19,7 +40,6 @@ export default function ProfileLink({
return children;
}

const levelName = levelNames[user.level];
const linkProps = user.slug
? {
href: '/user/[slug]',
Expand All @@ -33,9 +53,7 @@ export default function ProfileLink({
<Link {...linkProps}>
<a style={{ color: 'inherit' }} {...otherProps}>
{hasTooltip ? (
<Tooltip title={t`Lv.${user.level} ${levelName}`} placement="top">
{children}
</Tooltip>
<ProfileTooltip user={user}>{children}</ProfileTooltip>
) : (
children
)}
Expand All @@ -49,7 +67,8 @@ ProfileLink.fragments = {
fragment ProfileLinkUserData on User {
id
slug
level
...ProfileTooltipUserData
}
${ProfileTooltip.fragments.ProfileTooltipUserData}
`,
};
6 changes: 5 additions & 1 deletion components/ProfilePage/RepliedArticleTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ function ArticleReply({ articleReply }) {
style={{ gap: '16px' }}
>
{user && (
<Avatar size={40} user={user} className={classes.avatar} hasLink />
<Avatar
size={40}
user={user}
className={classes.avatar} /*hasLink*/
/>
)}
<Box flexGrow={1}>
<ArticleReplySummary articleReply={articleReply} />
Expand Down
57 changes: 20 additions & 37 deletions components/__snapshots__/ArticleReplySummary.stories.storyshot
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ exports[`Storyshots ArticleReplySummary Different Reply Types 1`] = `
<div
className="makeStyles-replyType makeStyles-replyType"
>
<ProfileLink
hasTooltip={true}
<ProfileTooltip
key="editor"
user={
Object {
Expand All @@ -27,40 +26,25 @@ exports[`Storyshots ArticleReplySummary Different Reply Types 1`] = `
}
}
>
<Link
href="/user?id=test-user"
<Tooltip
placement="top"
title="Lv.10 闢謠天行者"
>
<a
href="/user?id=test-user"
onClick={[Function]}
onMouseEnter={[Function]}
style={
Object {
"color": "inherit",
}
}
<span
aria-describedby={null}
className=""
onBlur={[Function]}
onFocus={[Function]}
onMouseLeave={[Function]}
onMouseOver={[Function]}
onTouchEnd={[Function]}
onTouchStart={[Function]}
title="Lv.10 闢謠天行者"
>
<Tooltip
placement="top"
title="Lv.10 闢謠天行者"
>
<span
aria-describedby={null}
className=""
onBlur={[Function]}
onFocus={[Function]}
onMouseLeave={[Function]}
onMouseOver={[Function]}
onTouchEnd={[Function]}
onTouchStart={[Function]}
title="Lv.10 闢謠天行者"
>
The user
</span>
</Tooltip>
</a>
</Link>
</ProfileLink>
The user
</span>
</Tooltip>
</ProfileTooltip>
mark this message
invalid request
</div>
Expand All @@ -79,15 +63,14 @@ exports[`Storyshots ArticleReplySummary No Valid User 1`] = `
<div
className="makeStyles-replyType makeStyles-replyType"
>
<ProfileLink
hasTooltip={true}
<ProfileTooltip
key="editor"
user={null}
>
<span>
Someone
</span>
</ProfileLink>
</ProfileTooltip>
mark this message
contains true information
</div>
Expand Down
40 changes: 25 additions & 15 deletions components/__snapshots__/ProfileLink.stories.storyshot
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,34 @@ exports[`Storyshots ProfileLink All Props 1`] = `
}
}
>
<Tooltip
placement="top"
title="Lv.10 闢謠天行者"
<ProfileTooltip
user={
Object {
"id": "123",
"level": 10,
"slug": "slug123",
}
}
>
<span
aria-describedby={null}
className=""
onBlur={[Function]}
onFocus={[Function]}
onMouseLeave={[Function]}
onMouseOver={[Function]}
onTouchEnd={[Function]}
onTouchStart={[Function]}
<Tooltip
placement="top"
title="Lv.10 闢謠天行者"
>
Child
</span>
</Tooltip>
<span
aria-describedby={null}
className=""
onBlur={[Function]}
onFocus={[Function]}
onMouseLeave={[Function]}
onMouseOver={[Function]}
onTouchEnd={[Function]}
onTouchStart={[Function]}
title="Lv.10 闢謠天行者"
>
Child
</span>
</Tooltip>
</ProfileTooltip>
</a>
</Link>
</ProfileLink>
Expand Down
8 changes: 4 additions & 4 deletions pages/reply/[id].js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import ExpandableText from 'components/ExpandableText';
import AppLayout from 'components/AppLayout';
import ArticleReply from 'components/ArticleReply';
import { Card, CardHeader, CardContent } from 'components/Card';
import ProfileLink from 'components/ProfileLink';
import { ProfileTooltip } from 'components/ProfileLink';
import Infos, { TimeInfo } from 'components/Infos';
import {
SideSection,
Expand Down Expand Up @@ -93,7 +93,7 @@ const LOAD_REPLY = gql`
}
}
${ArticleReply.fragments.ArticleReplyData}
${ProfileLink.fragments.ProfileLinkUserData}
${ProfileTooltip.fragments.ProfileTooltipUserData}
`;

const LOAD_REPLY_FOR_USER = gql`
Expand Down Expand Up @@ -283,9 +283,9 @@ function ReplyPage() {
</CardContent>
{otherArticleReplies.map(ar => {
const editorElem = (
<ProfileLink key="editor" user={ar.user} hasTooltip>
<ProfileTooltip key="editor" user={ar.user}>
<span>{ar?.user?.name || t`someone`}</span>
</ProfileLink>
</ProfileTooltip>
);

return (
Expand Down

0 comments on commit 3ed70bb

Please sign in to comment.