Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XWIKI-21730: Delete own comments should not require edit rights on page #2836

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Sereza7
Copy link
Contributor

@Sereza7 Sereza7 commented Feb 1, 2024

Jira URL

https://jira.xwiki.org/browse/XWIKI-21730

Changes

Description

  • Changed the permission needed for the delete comment action to be displayed

Clarifications

  • The code responsible for allowing or not to delete the comment was introduced in version 3.0-rc1 (see the commit), and apparently it was not a use case considered by those changes. So I don't see an issue with tying the comment deletion action to the comment right instead of the edit right.
  • The template for generating these action buttons is a bit of a mess. I considered for a moment changing the order of the buttons to make it cleaner. However after considering stakes, I realized the UI inconsistency between versions would be worst for users than the small code quality/optimization we would have gotten.

Screenshots & Video

In order to test those changes, I registered as a regular user (named '123456'). With the admin user, I changed regular user rights at the wiki level: removed the Edit right and kept the Comment right.
We can see that the delete button only appears after the changes in this PR. This is the behavior expected by the reporter of this ticket.
Before PR:
21730-beforePR
After PR:
21730-afterPR

Executed Tests

None, this change only changes the presence of the button in specific right configurations (No edit right but comment right, different from the default Edit+comment rights). I could only see one reference to this in a pageobject. This function is used only once with regular logged in user rights (in here).
Manual tests were conducted successfully, see the screenshots above.

Expected merging strategy

  • Prefers squash: Yes
  • Backport on branches:
    • 15.10.X - minor change with very low risk

* Changed the permission needed for the delete comment action to be displayed
@Sereza7 Sereza7 added the backport stable-15.10.x Used for automatic backport to 15.10.x branch. label Feb 1, 2024
@@ -184,7 +184,7 @@ $xwiki.ssfx.use('uicomponents/viewers/comments.css', true)
<a class="permalink btn btn-default btn-xs" data-toggle="modal" data-target="#permalinkModal" rel="nofollow"
href="$doc.getURL('view', 'viewer=comments')#xwikicomment_${comment.number}"
title="$services.localization.render('core.viewers.comments.permalink')">$services.icon.renderHTML('link')</a>
#if ($hasAdmin || ($hasEdit && $isUserComment))
#if ($hasAdmin || ($xwiki.hasAccessLevel('comment') && $isUserComment))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be consistent I would reuse the same condition than the one used for editing a comment, which is right now #if($hasAdmin || $isUserComment) (see line 180).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in f536a96 and f943ae6 . 👍

This selector was a bit more restrictive, actually checking for the comment right. Now, any user can delete their comments even if they don't have any right on a page.

@Sereza7 Sereza7 marked this pull request as draft February 2, 2024 09:10
Sereza7 and others added 2 commits February 7, 2024 14:41
* Added backend support for deletion of comments. This new action is very similar to regular object removal (which was the action used before), but is based on the Comment right instead of the Edit right.

See this demo: https://youtu.be/LwnLWfZFYZw
@Sereza7
Copy link
Contributor Author

Sereza7 commented Feb 7, 2024

Added backend support for deletion of comments. This new action is very similar to regular object removal (which was the action used before), but is based on the Comment right instead of the Edit right.

Changes are mostly contained in the oldcore module, because that's where all the backend logic for actions used in those buttons was already contained.

See a demo of this updated action.
This demo worked with just creating two symlinks on the updated jars for xwiki-oldcore and xwiki-security-authorization-bridge , and updating the commentsinline.vm template.

@Sereza7 Sereza7 marked this pull request as ready for review February 7, 2024 14:14
@@ -184,7 +184,7 @@ $xwiki.ssfx.use('uicomponents/viewers/comments.css', true)
<a class="permalink btn btn-default btn-xs" data-toggle="modal" data-target="#permalinkModal" rel="nofollow"
href="$doc.getURL('view', 'viewer=comments')#xwikicomment_${comment.number}"
title="$services.localization.render('core.viewers.comments.permalink')">$services.icon.renderHTML('link')</a>
#if ($hasAdmin || ($hasEdit && $isUserComment))
#if ($hasAdmin || $isUserComment)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about introducing a new variable to use in both if for edit and delete? That way we ensure that we'll keep them consistent.

* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package com.xpn.xwiki.web;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm normally we shouldn't introduce new stuff in this package, we should instead put stuff in org.xwiki... package, even in oldcore... Now it would make this class far from the other actions, so I'm not sure here...

try {
response.getWriter().write("failed");
response.setContentLength(6);
} catch (IOException e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing to handle the exception?

response.setContentType("text/plain");
try {
response.getWriter().write("failed");
response.setContentLength(6);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm really not a fan of this piece of code: at the very least "failed" should be in a String variable and you should eruse it also for the length. Now I'm not sure why you just answer "failed"?

String changeComment = localizePlainOrReturnKey("core.comment.deleteComment");

// Make sure the user is allowed to make this modification
context.getWiki().checkSavingDocument(userReference, doc, changeComment, true, context);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this check is working if you don't have edit right on the doc?

@Component
@Named("commentdelete")
@Singleton
public class CommentDeleteAction extends XWikiAction
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A test class should be provided too.

@Sereza7 Sereza7 marked this pull request as draft February 12, 2024 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport stable-15.10.x Used for automatic backport to 15.10.x branch.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants