Skip to content

Commit

Permalink
[FIX]: Edit cards from others (#320)
Browse files Browse the repository at this point in the history
* fix: edit own cards only

* fix: updateCardText function

* fix: previous commit

* fix: edit own comments only

* fix: remove not used code

* fix: change update and delete service of comment
  • Loading branch information
dvpfran authored Jul 12, 2022
1 parent f5bb4d6 commit 64e1400
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 25 deletions.
2 changes: 2 additions & 0 deletions backend/src/modules/cards/services/update.card.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ export default class UpdateCardServiceImpl implements UpdateCardService {
{
_id: boardId,
'columns.cards._id': cardId,
'columns.$.cards.$[card].createdBy': userId,
'columns.$.cards.$[card].items.$[item].createdBy': userId,
},
{
$set: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default class DeleteCommentServiceImpl implements DeleteCommentService {
{
_id: boardId,
'columns.cards.items.comments._id': commentId,
'columns.cards.items.comments.createdBy': userId,
},
{
$pull: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default class UpdateCommentServiceImpl implements UpdateCommentService {
{
_id: boardId,
'columns.cards.items.comments._id': commentId,
'columns.cards.items.comments.createdBy': userId,
},
{
$set: {
Expand Down
8 changes: 1 addition & 7 deletions frontend/src/components/Board/Card/CardBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,7 @@ const CardBoard = React.memo<CardBoardProps>(
<Text size="md" css={{ wordBreak: 'break-word' }}>
{card.text}
</Text>
{isSubmited && (
<Icon
name="menu-dots"
css={{ width: '$20', height: '$20' }}
/>
)}
{!isSubmited && (
{!isSubmited && userId === card?.createdBy?._id && (
<PopoverCardSettings
firstOne={false}
isItem={false}
Expand Down
8 changes: 1 addition & 7 deletions frontend/src/components/Board/Card/CardItem/CardItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React, { useState } from 'react';
import { styled } from 'styles/stitches/stitches.config';

import AddCardOrComment from 'components/Board/AddCardOrComment';
import Icon from 'components/icons/Icon';
import Flex from 'components/Primitives/Flex';
import Text from 'components/Primitives/Text';
import { CardItemType } from 'types/card/cardItem';
Expand Down Expand Up @@ -71,12 +70,7 @@ const CardItem: React.FC<CardItemProps> = React.memo(
<Flex direction="column">
<Flex justify="between" css={{ '& > div': { zIndex: 2 } }}>
<Text size="sm">{item.text}</Text>
{isSubmited && (
<Flex css={{ position: 'relative', top: firstOne ? '-35px' : 0 }}>
<Icon name="menu-dots" css={{ width: '$20', height: '$20' }} />
</Flex>
)}
{!isSubmited && (
{!isSubmited && userId === item?.createdBy?._id && (
<PopoverCardSettings
firstOne={firstOne}
columnId={columnId}
Expand Down
15 changes: 4 additions & 11 deletions frontend/src/components/Board/Comment/Comment.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from 'react';
import { useSession } from 'next-auth/react';

import Icon from 'components/icons/Icon';
import Flex from 'components/Primitives/Flex';
import Text from 'components/Primitives/Text';
import useComments from 'hooks/useComments';
Expand All @@ -21,6 +21,8 @@ interface CommentProps {
const Comment: React.FC<CommentProps> = React.memo(
({ comment, cardId, cardItemId, boardId, socketId, isSubmited }) => {
const { deleteComment } = useComments();
const { data: session } = useSession({ required: false });
const userId = session?.user.id;

const [editing, setEditing] = useState(false);

Expand Down Expand Up @@ -55,16 +57,7 @@ const Comment: React.FC<CommentProps> = React.memo(
<Flex direction="column">
<Flex justify="between" css={{ width: '100%' }}>
<Text size="xs">{comment.text}</Text>
{isSubmited && (
<Icon
name="menu-dots"
css={{
width: '$20',
height: '$20'
}}
/>
)}
{!isSubmited && (
{!isSubmited && userId === comment.createdBy._id && (
<PopoverCommentSettings
handleEditing={handleEditing}
handleDeleteComment={handleDeleteComment}
Expand Down

0 comments on commit 64e1400

Please sign in to comment.