Skip to content

Commit

Permalink
Only show 'edit comment' if that is allowed. Only allow edit if comme…
Browse files Browse the repository at this point in the history
…nt says so.
  • Loading branch information
thisismeonmounteverest committed May 19, 2024
1 parent 8dbe887 commit 5eabd47
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
10 changes: 7 additions & 3 deletions build/members/pages/member.page.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,14 @@ protected function getSubmenuItems()
if ($this->message !== 0) {
$feedbackUrl .= "&messageId=" . $this->message;
}
if (isset($TCom[0])) {
if ($TCom[0]->AllowEdit) {
$tt = array_merge($tt, array('commmentsadd', "members/$username/comment/edit", '<i class="fa fa-fw fa-comment"></i> ' . $ww->EditComments, 'commentsadd'));
}
} else {
$tt = array_merge($tt, array('commmentsadd', "members/$username/comment/add", '<i class="fa fa-fw fa-comment"></i> ' . $ww->AddComments, 'commentsadd'));
}
$tt = array_merge($tt, [
(isset($TCom[0]))
? array('commmentsadd', "members/$username/comment/edit", '<i class="fa fa-fw fa-comment"></i> ' . $ww->EditComments, 'commentsadd')
: array('commmentsadd', "members/$username/comment/add", '<i class="fa fa-fw fa-comment"></i> ' . $ww->AddComments, 'commentsadd'),
(null === $relation)
? array('relationsadd', "members/$username/relation/add", '<i class="fa fa-fw fa-handshake"></i> ' . $words->get('profile.relation.add'), 'relationsadd')
: array('relationsadd', "members/$username/relation/edit", '<i class="fa fa-fw fa-handshake"></i> ' . $words->get('profile.relation.edit'), 'relationsadd'),
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/CommentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public function editComment(
return $this->redirectToRoute('add_comment', ['username' => $member->getUsername()]);
}

if ($comment->getQuality() == CommentQualityType::NEGATIVE && !$comment->getEditingAllowed()) {
if (!$comment->getEditingAllowed()) {
$this->addTranslatedFlash('notice', 'comment.editing.not.allowed', []);

return $this->redirectToRoute('members_profile', ['username' => $member->getUsername()]);
Expand Down
18 changes: 11 additions & 7 deletions src/Utilities/ProfileSubmenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private function getMemberInfo(Member $member, Member $loggedInMember): array

if (!$ownProfile) {
$comment = $commentRepository->findOneBy(['fromMember' => $loggedInMember, 'toMember' => $member]);
$memberInfo['comment'] = null !== $comment;
$memberInfo['comment'] = $comment;

$note = $noteRepository->findOneBy(['owner' => $loggedInMember, 'member' => $member]);
$memberInfo['note'] = null !== $note;
Expand Down Expand Up @@ -201,12 +201,16 @@ private function addSubmenuItemsProfile(Member $member, array $parameters)
]);
}

if ($parameters['comment']) {
$this->addSubmenuItem('comment', [
'key' => 'EditComments',
'icon' => 'comment',
'url' => $this->routing->generate('edit_comment', ['username' => $username]),
]);
/** @var Comment $comment */
$comment = $parameters['comment'];
if (null !== $comment) {
if ($comment->getEditingAllowed()) {
$this->addSubmenuItem('comment', [
'key' => 'EditComments',
'icon' => 'comment',
'url' => $this->routing->generate('edit_comment', ['username' => $username]),
]);
}
} else {
$this->addSubmenuItem('comment', [
'key' => 'AddComments',
Expand Down

0 comments on commit 5eabd47

Please sign in to comment.