From 1ae780d6dafccbbfdfbc84ef0ef02cca9fed5f79 Mon Sep 17 00:00:00 2001 From: BentiGorlich Date: Mon, 19 Aug 2024 19:40:19 +0200 Subject: [PATCH 1/4] Add field to all content response DTOs: `canLoggedInUserModerate` - All content response DTOs (entry, entry_comment, post, post_comment) now have a field `canLoggedInUserModerate` which indicates whether the loggedin user can moderate said content --- src/Controller/Api/Entry/EntriesBaseApi.php | 15 ++++++++++++++- src/Controller/Api/Post/PostsBaseApi.php | 12 ++++++++++++ src/DTO/EntryCommentResponseDto.php | 4 ++++ src/DTO/EntryResponseDto.php | 1 + src/DTO/PostCommentResponseDto.php | 4 ++++ src/DTO/PostResponseDto.php | 6 +++++- 6 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/Controller/Api/Entry/EntriesBaseApi.php b/src/Controller/Api/Entry/EntriesBaseApi.php index 6dc816133..2596f7cae 100644 --- a/src/Controller/Api/Entry/EntriesBaseApi.php +++ b/src/Controller/Api/Entry/EntriesBaseApi.php @@ -10,6 +10,7 @@ use App\DTO\EntryCommentResponseDto; use App\DTO\EntryDto; use App\DTO\EntryRequestDto; +use App\DTO\EntryResponseDto; use App\DTO\ImageDto; use App\Entity\Entry; use App\Entity\EntryComment; @@ -34,7 +35,7 @@ public function setCommentsFactory(EntryCommentFactory $commentsFactory) /** * Serialize a single entry to JSON. */ - protected function serializeEntry(EntryDto|Entry $dto, array $tags) + protected function serializeEntry(EntryDto|Entry $dto, array $tags): EntryResponseDto { $response = $this->entryFactory->createResponseDto($dto, $tags); @@ -43,6 +44,10 @@ protected function serializeEntry(EntryDto|Entry $dto, array $tags) $response->userVote = $dto instanceof EntryDto ? $dto->userVote : $dto->getUserChoice($this->getUserOrThrow()); } + if ($user = $this->getUser()) { + $response->canLoggedInUserModerate = $dto->getMagazine()->userIsModerator($user) || $user->isModerator() || $user->isAdmin(); + } + return $response; } @@ -103,6 +108,10 @@ protected function serializeComment(EntryCommentDto $comment, array $tags): Entr $response->userVote = $comment->userVote; } + if ($user = $this->getUser()) { + $response->canLoggedInUserModerate = $comment->magazine->userIsModerator($user) || $user->isModerator() || $user->isAdmin(); + } + return $response; } @@ -174,6 +183,10 @@ protected function serializeCommentTree(?EntryComment $comment, ?int $depth = nu $commentTree = $this->commentsFactory->createResponseTree($comment, $depth); + if ($user = $this->getUser()) { + $commentTree->canLoggedInUserModerate = $comment->getMagazine()->userIsModerator($user) || $user->isModerator() || $user->isAdmin(); + } + return $commentTree->jsonSerialize(); } diff --git a/src/Controller/Api/Post/PostsBaseApi.php b/src/Controller/Api/Post/PostsBaseApi.php index 0a3dbe6b7..d17340801 100644 --- a/src/Controller/Api/Post/PostsBaseApi.php +++ b/src/Controller/Api/Post/PostsBaseApi.php @@ -30,6 +30,10 @@ protected function serializePost(PostDto $dto, array $tags): PostResponseDto $response->userVote = $dto instanceof PostDto ? $dto->userVote : $dto->getUserChoice($this->getUserOrThrow()); } + if ($user = $this->getUser()) { + $response->canLoggedInUserModerate = $dto->getMagazine()->userIsModerator($user) || $user->isModerator() || $user->isAdmin(); + } + return $response; } @@ -83,6 +87,10 @@ protected function serializePostComment(PostCommentDto $comment, array $tags): P $response->userVote = $comment instanceof PostCommentDto ? $comment->userVote : $comment->getUserChoice($this->getUserOrThrow()); } + if ($user = $this->getUser()) { + $response->canLoggedInUserModerate = $comment->getMagazine()->userIsModerator($user) || $user->isModerator() || $user->isAdmin(); + } + return $response; } @@ -150,6 +158,10 @@ protected function serializePostCommentTree(?PostComment $comment, ?int $depth = $commentTree = $this->postCommentFactory->createResponseTree($comment, $depth); + if ($user = $this->getUser()) { + $commentTree->canLoggedInUserModerate = $comment->getMagazine()->userIsModerator($user) || $user->isModerator() || $user->isAdmin(); + } + return $commentTree->jsonSerialize(); } } diff --git a/src/DTO/EntryCommentResponseDto.php b/src/DTO/EntryCommentResponseDto.php index 84770d96f..f9d7c5a4b 100644 --- a/src/DTO/EntryCommentResponseDto.php +++ b/src/DTO/EntryCommentResponseDto.php @@ -88,6 +88,7 @@ class EntryCommentResponseDto implements \JsonSerializable public array $children = []; #[OA\Property(description: 'The total number of children the comment has.')] public int $childCount = 0; + public ?bool $canLoggedInUserModerate = null; public static function create( ?int $id = null, @@ -111,6 +112,7 @@ public static function create( ?\DateTimeImmutable $editedAt = null, ?\DateTime $lastActive = null, int $childCount = 0, + ?bool $canLoggedInUserModerate = null, ): self { $dto = new EntryCommentResponseDto(); $dto->commentId = $id; @@ -134,6 +136,7 @@ public static function create( $dto->editedAt = $editedAt; $dto->lastActive = $lastActive; $dto->childCount = $childCount; + $dto->canLoggedInUserModerate = $canLoggedInUserModerate; return $dto; } @@ -184,6 +187,7 @@ public function jsonSerialize(): mixed 'lastActive' => $this->lastActive?->format(\DateTimeInterface::ATOM), 'childCount' => $this->childCount, 'children' => $this->children, + 'canLoggedInUserModerate' => $this->canLoggedInUserModerate, ]); } } diff --git a/src/DTO/EntryResponseDto.php b/src/DTO/EntryResponseDto.php index a43643db0..698451e72 100644 --- a/src/DTO/EntryResponseDto.php +++ b/src/DTO/EntryResponseDto.php @@ -44,6 +44,7 @@ class EntryResponseDto implements \JsonSerializable public ?string $type = null; public ?string $slug = null; public ?string $apId = null; + public ?bool $canLoggedInUserModerate = null; public static function create( ?int $id = null, diff --git a/src/DTO/PostCommentResponseDto.php b/src/DTO/PostCommentResponseDto.php index 2ab8a634d..a783604f4 100644 --- a/src/DTO/PostCommentResponseDto.php +++ b/src/DTO/PostCommentResponseDto.php @@ -80,6 +80,7 @@ class PostCommentResponseDto implements \JsonSerializable ] )] public array $children = []; + public ?bool $canLoggedInUserModerate = null; public static function create( int $id, @@ -102,6 +103,7 @@ public static function create( ?\DateTimeImmutable $createdAt = null, ?\DateTimeImmutable $editedAt = null, ?\DateTime $lastActive = null, + ?bool $canLoggedInUserModerate = null, ): self { $dto = new PostCommentResponseDto(); $dto->commentId = $id; @@ -125,6 +127,7 @@ public static function create( $dto->editedAt = $editedAt; $dto->lastActive = $lastActive; $dto->childCount = $childCount; + $dto->canLoggedInUserModerate = $canLoggedInUserModerate; return $dto; } @@ -171,6 +174,7 @@ public function jsonSerialize(): mixed 'lastActive' => $this->lastActive?->format(\DateTimeInterface::ATOM), 'childCount' => $this->childCount, 'children' => $this->children, + 'canLoggedInUserModerate' => $this->canLoggedInUserModerate, ]); } diff --git a/src/DTO/PostResponseDto.php b/src/DTO/PostResponseDto.php index 85a874a08..1ec69ee51 100644 --- a/src/DTO/PostResponseDto.php +++ b/src/DTO/PostResponseDto.php @@ -36,6 +36,7 @@ class PostResponseDto implements \JsonSerializable public ?\DateTimeImmutable $createdAt = null; public ?\DateTimeImmutable $editedAt = null; public ?\DateTime $lastActive = null; + public ?bool $canLoggedInUserModerate = null; public static function create( int $id, @@ -57,7 +58,8 @@ public static function create( ?\DateTimeImmutable $createdAt = null, ?\DateTimeImmutable $editedAt = null, ?\DateTime $lastActive = null, - ?string $slug = null + ?string $slug = null, + ?bool $canLoggedInUserModerate = null, ): self { $dto = new PostResponseDto(); $dto->postId = $id; @@ -80,6 +82,7 @@ public static function create( $dto->editedAt = $editedAt; $dto->lastActive = $lastActive; $dto->slug = $slug; + $dto->canLoggedInUserModerate = $canLoggedInUserModerate; return $dto; } @@ -124,6 +127,7 @@ public function jsonSerialize(): mixed 'editedAt' => $this->editedAt?->format(\DateTimeInterface::ATOM), 'lastActive' => $this->lastActive?->format(\DateTimeInterface::ATOM), 'slug' => $this->slug, + 'canLoggedInUserModerate' => $this->canLoggedInUserModerate, ]); } } From 3d2662d6c6e576e72de9976ecd525d1d14732ed1 Mon Sep 17 00:00:00 2001 From: BentiGorlich Date: Mon, 19 Aug 2024 21:40:06 +0200 Subject: [PATCH 2/4] Rename field to `canAuthUserModerate` --- src/Controller/Api/Entry/EntriesBaseApi.php | 6 +++--- src/Controller/Api/Post/PostsBaseApi.php | 6 +++--- src/DTO/EntryCommentResponseDto.php | 8 ++++---- src/DTO/EntryResponseDto.php | 7 +++++-- src/DTO/PostCommentResponseDto.php | 8 ++++---- src/DTO/PostResponseDto.php | 8 ++++---- 6 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/Controller/Api/Entry/EntriesBaseApi.php b/src/Controller/Api/Entry/EntriesBaseApi.php index 2596f7cae..75742fce7 100644 --- a/src/Controller/Api/Entry/EntriesBaseApi.php +++ b/src/Controller/Api/Entry/EntriesBaseApi.php @@ -45,7 +45,7 @@ protected function serializeEntry(EntryDto|Entry $dto, array $tags): EntryRespon } if ($user = $this->getUser()) { - $response->canLoggedInUserModerate = $dto->getMagazine()->userIsModerator($user) || $user->isModerator() || $user->isAdmin(); + $response->canAuthUserModerate = $dto->getMagazine()->userIsModerator($user) || $user->isModerator() || $user->isAdmin(); } return $response; @@ -109,7 +109,7 @@ protected function serializeComment(EntryCommentDto $comment, array $tags): Entr } if ($user = $this->getUser()) { - $response->canLoggedInUserModerate = $comment->magazine->userIsModerator($user) || $user->isModerator() || $user->isAdmin(); + $response->canAuthUserModerate = $comment->magazine->userIsModerator($user) || $user->isModerator() || $user->isAdmin(); } return $response; @@ -184,7 +184,7 @@ protected function serializeCommentTree(?EntryComment $comment, ?int $depth = nu $commentTree = $this->commentsFactory->createResponseTree($comment, $depth); if ($user = $this->getUser()) { - $commentTree->canLoggedInUserModerate = $comment->getMagazine()->userIsModerator($user) || $user->isModerator() || $user->isAdmin(); + $commentTree->canAuthUserModerate = $comment->getMagazine()->userIsModerator($user) || $user->isModerator() || $user->isAdmin(); } return $commentTree->jsonSerialize(); diff --git a/src/Controller/Api/Post/PostsBaseApi.php b/src/Controller/Api/Post/PostsBaseApi.php index d17340801..c97722803 100644 --- a/src/Controller/Api/Post/PostsBaseApi.php +++ b/src/Controller/Api/Post/PostsBaseApi.php @@ -31,7 +31,7 @@ protected function serializePost(PostDto $dto, array $tags): PostResponseDto } if ($user = $this->getUser()) { - $response->canLoggedInUserModerate = $dto->getMagazine()->userIsModerator($user) || $user->isModerator() || $user->isAdmin(); + $response->canAuthUserModerate = $dto->getMagazine()->userIsModerator($user) || $user->isModerator() || $user->isAdmin(); } return $response; @@ -88,7 +88,7 @@ protected function serializePostComment(PostCommentDto $comment, array $tags): P } if ($user = $this->getUser()) { - $response->canLoggedInUserModerate = $comment->getMagazine()->userIsModerator($user) || $user->isModerator() || $user->isAdmin(); + $response->canAuthUserModerate = $comment->getMagazine()->userIsModerator($user) || $user->isModerator() || $user->isAdmin(); } return $response; @@ -159,7 +159,7 @@ protected function serializePostCommentTree(?PostComment $comment, ?int $depth = $commentTree = $this->postCommentFactory->createResponseTree($comment, $depth); if ($user = $this->getUser()) { - $commentTree->canLoggedInUserModerate = $comment->getMagazine()->userIsModerator($user) || $user->isModerator() || $user->isAdmin(); + $commentTree->canAuthUserModerate = $comment->getMagazine()->userIsModerator($user) || $user->isModerator() || $user->isAdmin(); } return $commentTree->jsonSerialize(); diff --git a/src/DTO/EntryCommentResponseDto.php b/src/DTO/EntryCommentResponseDto.php index f9d7c5a4b..e9949870b 100644 --- a/src/DTO/EntryCommentResponseDto.php +++ b/src/DTO/EntryCommentResponseDto.php @@ -88,7 +88,7 @@ class EntryCommentResponseDto implements \JsonSerializable public array $children = []; #[OA\Property(description: 'The total number of children the comment has.')] public int $childCount = 0; - public ?bool $canLoggedInUserModerate = null; + public ?bool $canAuthUserModerate = null; public static function create( ?int $id = null, @@ -112,7 +112,7 @@ public static function create( ?\DateTimeImmutable $editedAt = null, ?\DateTime $lastActive = null, int $childCount = 0, - ?bool $canLoggedInUserModerate = null, + ?bool $canAuthUserModerate = null, ): self { $dto = new EntryCommentResponseDto(); $dto->commentId = $id; @@ -136,7 +136,7 @@ public static function create( $dto->editedAt = $editedAt; $dto->lastActive = $lastActive; $dto->childCount = $childCount; - $dto->canLoggedInUserModerate = $canLoggedInUserModerate; + $dto->canAuthUserModerate = $canAuthUserModerate; return $dto; } @@ -187,7 +187,7 @@ public function jsonSerialize(): mixed 'lastActive' => $this->lastActive?->format(\DateTimeInterface::ATOM), 'childCount' => $this->childCount, 'children' => $this->children, - 'canLoggedInUserModerate' => $this->canLoggedInUserModerate, + 'canAuthUserModerate' => $this->canAuthUserModerate, ]); } } diff --git a/src/DTO/EntryResponseDto.php b/src/DTO/EntryResponseDto.php index 698451e72..8d761a624 100644 --- a/src/DTO/EntryResponseDto.php +++ b/src/DTO/EntryResponseDto.php @@ -44,7 +44,7 @@ class EntryResponseDto implements \JsonSerializable public ?string $type = null; public ?string $slug = null; public ?string $apId = null; - public ?bool $canLoggedInUserModerate = null; + public ?bool $canAuthUserModerate = null; public static function create( ?int $id = null, @@ -71,7 +71,8 @@ public static function create( ?\DateTime $lastActive = null, ?string $type = null, ?string $slug = null, - ?string $apId = null + ?string $apId = null, + ?bool $canAuthUserModerate = null, ): self { $dto = new EntryResponseDto(); $dto->entryId = $id; @@ -99,6 +100,7 @@ public static function create( $dto->type = $type; $dto->slug = $slug; $dto->apId = $apId; + $dto->canAuthUserModerate = $canAuthUserModerate; return $dto; } @@ -151,6 +153,7 @@ public function jsonSerialize(): mixed 'type' => $this->type, 'slug' => $this->slug, 'apId' => $this->apId, + 'canAuthUserModerate' => $this->canAuthUserModerate, ]); } } diff --git a/src/DTO/PostCommentResponseDto.php b/src/DTO/PostCommentResponseDto.php index a783604f4..1925e073d 100644 --- a/src/DTO/PostCommentResponseDto.php +++ b/src/DTO/PostCommentResponseDto.php @@ -80,7 +80,7 @@ class PostCommentResponseDto implements \JsonSerializable ] )] public array $children = []; - public ?bool $canLoggedInUserModerate = null; + public ?bool $canAuthUserModerate = null; public static function create( int $id, @@ -103,7 +103,7 @@ public static function create( ?\DateTimeImmutable $createdAt = null, ?\DateTimeImmutable $editedAt = null, ?\DateTime $lastActive = null, - ?bool $canLoggedInUserModerate = null, + ?bool $canAuthUserModerate = null, ): self { $dto = new PostCommentResponseDto(); $dto->commentId = $id; @@ -127,7 +127,7 @@ public static function create( $dto->editedAt = $editedAt; $dto->lastActive = $lastActive; $dto->childCount = $childCount; - $dto->canLoggedInUserModerate = $canLoggedInUserModerate; + $dto->canAuthUserModerate = $canAuthUserModerate; return $dto; } @@ -174,7 +174,7 @@ public function jsonSerialize(): mixed 'lastActive' => $this->lastActive?->format(\DateTimeInterface::ATOM), 'childCount' => $this->childCount, 'children' => $this->children, - 'canLoggedInUserModerate' => $this->canLoggedInUserModerate, + 'canAuthUserModerate' => $this->canAuthUserModerate, ]); } diff --git a/src/DTO/PostResponseDto.php b/src/DTO/PostResponseDto.php index 1ec69ee51..c17d86a0a 100644 --- a/src/DTO/PostResponseDto.php +++ b/src/DTO/PostResponseDto.php @@ -36,7 +36,7 @@ class PostResponseDto implements \JsonSerializable public ?\DateTimeImmutable $createdAt = null; public ?\DateTimeImmutable $editedAt = null; public ?\DateTime $lastActive = null; - public ?bool $canLoggedInUserModerate = null; + public ?bool $canAuthUserModerate = null; public static function create( int $id, @@ -59,7 +59,7 @@ public static function create( ?\DateTimeImmutable $editedAt = null, ?\DateTime $lastActive = null, ?string $slug = null, - ?bool $canLoggedInUserModerate = null, + ?bool $canAuthUserModerate = null, ): self { $dto = new PostResponseDto(); $dto->postId = $id; @@ -82,7 +82,7 @@ public static function create( $dto->editedAt = $editedAt; $dto->lastActive = $lastActive; $dto->slug = $slug; - $dto->canLoggedInUserModerate = $canLoggedInUserModerate; + $dto->canAuthUserModerate = $canAuthUserModerate; return $dto; } @@ -127,7 +127,7 @@ public function jsonSerialize(): mixed 'editedAt' => $this->editedAt?->format(\DateTimeInterface::ATOM), 'lastActive' => $this->lastActive?->format(\DateTimeInterface::ATOM), 'slug' => $this->slug, - 'canLoggedInUserModerate' => $this->canLoggedInUserModerate, + 'canAuthUserModerate' => $this->canAuthUserModerate, ]); } } From b6e80638fc4ad62e9663c790696e9b6a4f7156f9 Mon Sep 17 00:00:00 2001 From: BentiGorlich Date: Mon, 19 Aug 2024 22:46:02 +0200 Subject: [PATCH 3/4] Make all comments in the tree have `canAuthUserModerate` --- src/Controller/Api/Entry/EntriesBaseApi.php | 9 +++++---- src/Factory/EntryCommentFactory.php | 5 +++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Controller/Api/Entry/EntriesBaseApi.php b/src/Controller/Api/Entry/EntriesBaseApi.php index 75742fce7..8b34c280f 100644 --- a/src/Controller/Api/Entry/EntriesBaseApi.php +++ b/src/Controller/Api/Entry/EntriesBaseApi.php @@ -180,13 +180,14 @@ protected function serializeCommentTree(?EntryComment $comment, ?int $depth = nu if (null === $depth) { $depth = self::constrainDepth($this->request->getCurrentRequest()->get('d', self::DEPTH)); } - - $commentTree = $this->commentsFactory->createResponseTree($comment, $depth); - + $canModerate = null; if ($user = $this->getUser()) { - $commentTree->canAuthUserModerate = $comment->getMagazine()->userIsModerator($user) || $user->isModerator() || $user->isAdmin(); + $canModerate = $comment->getMagazine()->userIsModerator($user) || $user->isModerator() || $user->isAdmin(); } + $commentTree = $this->commentsFactory->createResponseTree($comment, $depth, $canModerate); + $commentTree->canAuthUserModerate = $canModerate; + return $commentTree->jsonSerialize(); } diff --git a/src/Factory/EntryCommentFactory.php b/src/Factory/EntryCommentFactory.php index 79b0a0add..ecaf77cb6 100644 --- a/src/Factory/EntryCommentFactory.php +++ b/src/Factory/EntryCommentFactory.php @@ -62,12 +62,13 @@ public function createResponseDto(EntryCommentDto|EntryComment $comment, array $ ); } - public function createResponseTree(EntryComment $comment, int $depth = -1): EntryCommentResponseDto + public function createResponseTree(EntryComment $comment, int $depth = -1, ?bool $canModerate = null): EntryCommentResponseDto { $commentDto = $this->createDto($comment); $toReturn = $this->createResponseDto($commentDto, $this->tagLinkRepository->getTagsOfEntryComment($comment), array_reduce($comment->children->toArray(), EntryCommentResponseDto::class.'::recursiveChildCount', 0)); $toReturn->isFavourited = $commentDto->isFavourited; $toReturn->userVote = $commentDto->userVote; + $toReturn->canAuthUserModerate = $canModerate; if (0 === $depth) { return $toReturn; @@ -75,7 +76,7 @@ public function createResponseTree(EntryComment $comment, int $depth = -1): Entr foreach ($comment->children as $childComment) { \assert($childComment instanceof EntryComment); - $child = $this->createResponseTree($childComment, $depth > 0 ? $depth - 1 : -1); + $child = $this->createResponseTree($childComment, $depth > 0 ? $depth - 1 : -1, $canModerate); array_push($toReturn->children, $child); } From fe458a29ef6728e097da949f055f67a1947c6f45 Mon Sep 17 00:00:00 2001 From: BentiGorlich Date: Tue, 20 Aug 2024 09:21:07 +0200 Subject: [PATCH 4/4] Include `canAuthUserModerate` in every post comment --- src/Controller/Api/Post/PostsBaseApi.php | 8 +++++--- src/Factory/PostCommentFactory.php | 5 +++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Controller/Api/Post/PostsBaseApi.php b/src/Controller/Api/Post/PostsBaseApi.php index c97722803..d1df4625b 100644 --- a/src/Controller/Api/Post/PostsBaseApi.php +++ b/src/Controller/Api/Post/PostsBaseApi.php @@ -156,12 +156,14 @@ protected function serializePostCommentTree(?PostComment $comment, ?int $depth = $depth = self::constrainDepth($this->request->getCurrentRequest()->get('d', self::DEPTH)); } - $commentTree = $this->postCommentFactory->createResponseTree($comment, $depth); - + $canModerate = null; if ($user = $this->getUser()) { - $commentTree->canAuthUserModerate = $comment->getMagazine()->userIsModerator($user) || $user->isModerator() || $user->isAdmin(); + $canModerate = $comment->getMagazine()->userIsModerator($user) || $user->isModerator() || $user->isAdmin(); } + $commentTree = $this->postCommentFactory->createResponseTree($comment, $depth, $canModerate); + $commentTree->canAuthUserModerate = $canModerate; + return $commentTree->jsonSerialize(); } } diff --git a/src/Factory/PostCommentFactory.php b/src/Factory/PostCommentFactory.php index c58cc38bb..03926e93c 100644 --- a/src/Factory/PostCommentFactory.php +++ b/src/Factory/PostCommentFactory.php @@ -63,12 +63,13 @@ public function createResponseDto(PostCommentDto|PostComment $comment, array $ta ); } - public function createResponseTree(PostComment $comment, int $depth): PostCommentResponseDto + public function createResponseTree(PostComment $comment, int $depth, ?bool $canModerate = null): PostCommentResponseDto { $commentDto = $this->createDto($comment); $toReturn = $this->createResponseDto($commentDto, $this->tagLinkRepository->getTagsOfPostComment($comment), array_reduce($comment->children->toArray(), PostCommentResponseDto::class.'::recursiveChildCount', 0)); $toReturn->isFavourited = $commentDto->isFavourited; $toReturn->userVote = $commentDto->userVote; + $toReturn->canAuthUserModerate = $canModerate; if (0 === $depth) { return $toReturn; @@ -76,7 +77,7 @@ public function createResponseTree(PostComment $comment, int $depth): PostCommen foreach ($comment->children as $childComment) { \assert($childComment instanceof PostComment); - $child = $this->createResponseTree($childComment, $depth > 0 ? $depth - 1 : -1); + $child = $this->createResponseTree($childComment, $depth > 0 ? $depth - 1 : -1, $canModerate); array_push($toReturn->children, $child); }