-
-
Notifications
You must be signed in to change notification settings - Fork 554
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
base: master
Are you sure you want to change the base?
Conversation
* Changed the permission needed for the delete comment action to be displayed
@@ -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)) |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* 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
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. |
@@ -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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 9f841ae 👍
* 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; |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- We need a new action for the map in XWikiCachingRightService. This means that we cannot just reuse another action.
- All actions are already here.
- The code I used in this class is very similar to
ObjectRemoveAction
. It's mostly oldcore quality code. It'd probably need even more quality improvements to be anywhere else and I don't think it's worth spending that much time on rewriting it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's worth spending that much time on rewriting it.
Note that I was only talking about moving that class to another package. Now if it's using some package private stuff it's making this more complex indeed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly it does not make much sense to have CommentAddAction here and CommentDeleteAction elsewhere so +1 to keep it here.
try { | ||
response.getWriter().write("failed"); | ||
response.setContentLength(6); | ||
} catch (IOException e) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that most parts are the same as ObjectRemoveAction
. This empty exception handle has been in this other file since 2008 so it seems like it's not a huge problem.
This is bad quality I agree.
I added a log similar to what was done in XWikiAction.java
Line 385 in 4e2efc8
LOGGER.error("Failed to send error response to AJAX save and continue request.", e); |
Addressed in 767daac 👍
response.setContentType("text/plain"); | ||
try { | ||
response.getWriter().write("failed"); | ||
response.setContentLength(6); |
There was a problem hiding this comment.
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"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this part is pretty much the same as ObjectRemoveAction
.
I updated it and also changed ObjectRemoveAction
to match these changes.
See 6edbec1 👍
String changeComment = localizePlainOrReturnKey("core.comment.deleteComment"); | ||
|
||
// Make sure the user is allowed to make this modification | ||
context.getWiki().checkSavingDocument(userReference, doc, changeComment, true, context); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I can understand of this code I reused from ObjectRemoveAction, this does not check the rights of the current user but the state of the document (whether it's in a saveable state or not). I'm retesting things manually to make sure everything is alright.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I finally figured it out. The authorisation to do this action is handled at the level of XWikiCachingRightService
. This is also the reason why we need an independant action even thought it's pretty much the same as object deletion. From what I understand, one action can only be mapped to one right. Setting the other object editions to depend on the Comment right is wrong, we need to separate this into two actions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can confirm this. I forgot to put the security .jar on my local instance and the action wouldn't go through (with edit rights disabled but comment rights enabled). Updating it as expected fixed the backend permission issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm retesting things manually to make sure everything is alright.
Except for an oldcore exception that's unrelated to this PR, builds are okay.
@Component | ||
@Named("commentdelete") | ||
@Singleton | ||
public class CommentDeleteAction extends XWikiAction |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a test for this class.
For both the test and the new Java class, I made sure to reformat the code with XWiki standard on Intellij Idea
I successfully passed mvn clean install -f xwiki-platform-core/xwiki-platform-oldcore -Pquality
. All that was reported by SonarLint on both of the files are the @MockComponent
that are not used in the class , which is a false positive. They are needed for our test class to work properly.
Added the test class in 1579ded 👍
* Added a log on error of the AJAX write request
* Updated the render function on both ObjectRemoveAction and CommentDeleteAction
* Fixed codestyle * Added a test for the new action
This PR is ready for further reviewing. |
<a class="edit btn btn-default btn-xs" rel="nofollow" href="$doc.getURL('view', "viewer=comments&number=${comment.number}&xredirect=$doc.getURL('view')")" title="$services.localization.render('core.viewers.comments.edit')">$services.icon.renderHTML('pencil')</a> | ||
#end | ||
#end | ||
<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 ($hasCommentEditionRight) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm I'm not so sure about that change... Yeah I know I commented to have consistency in an early review :)
Have you tested if it actually works to edit a comment for a page in which the comment user doesn't have edit right?
* @version $Id$ | ||
* @since 17.0.0RC1 | ||
*/ | ||
@ComponentList |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm wrong annotation I think: this one takes as values a list of component. I guess you wanted to use @ComponentTest
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that you should not use @ComponentTest
either since you have @OldcoreTest
(it's one or the other).
<a class="edit btn btn-default btn-xs" rel="nofollow" href="$doc.getURL('view', "viewer=comments&number=${comment.number}&xredirect=$doc.getURL('view')")" title="$services.localization.render('core.viewers.comments.edit')">$services.icon.renderHTML('pencil')</a> | ||
#end | ||
#end | ||
<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 ($hasCommentEditionRight) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the indentation change on purpose ?
{ | ||
private static final String FAIL_MESSAGE = "failed"; | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(CommentDeleteAction.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a component, so you can inject a Logger (you find this kind of stuff in other actions because they used to not be components, but for new code let's do things by the book).
@@ -41,6 +43,8 @@ | |||
@Singleton | |||
public class ObjectRemoveAction extends XWikiAction | |||
{ | |||
private static final String FAIL_MESSAGE = "failed"; | |||
private static final Logger LOGGER = LoggerFactory.getLogger(ObjectRemoveAction.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above about injected Loggers.
*/ | ||
@ComponentList | ||
@ReferenceComponentList | ||
@OldcoreTest(mockXWiki = false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mockXWiki = false
sounds a bit strange, this was basically introduced for tests of XWiki, but tests not really testing XWiki itself generally don't want to do that
* @since 17.0.0RC1 | ||
*/ | ||
@Component | ||
@Named("commentdelete") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing critical but commentremove
would feel more consistent with objectremove
, especially since it's reusing ObjectRemoveForm
.
@Component | ||
@Named("commentdelete") | ||
@Singleton | ||
public class CommentDeleteAction extends XWikiAction |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might worth moving most of this class in some AbstractObjectRemoveAction
that would also be extended by ObjectRemoveAction
(to me it seems the main different is that CommentRemoveAction would indicate a hardcoded class to AbstractObjectRemoveAction instead of using the one provided by ObjectRemoveForm).
ScriptContext.ENGINE_SCOPE); | ||
} else { | ||
// Comment class reference | ||
DocumentReference commentClass = new DocumentReference(context.getWikiId(), XWiki.SYSTEM_SPACE, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need to create a DocumentReference ?
ObjectRemoveForm form = (ObjectRemoveForm) context.getForm(); | ||
BaseObject obj = null; | ||
|
||
String className = form.getClassName(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Manipulating the class name does not make sense for this action, since it's always about comments (or only to return an error if someone tried to be clever and use this action to delete another type of xobject with just comment right).
Jira URL
https://jira.xwiki.org/browse/XWIKI-21730
Changes
Description
Clarifications
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:
After PR:
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