[MGNLCMNT-94] make sure commenting works with anonymous user Created: 04/Feb/14  Updated: 03/Mar/14  Resolved: 19/Feb/14

Status: Closed
Project: Commenting (closed)
Component/s: security, VersionHandler
Affects Version/s: None
Fix Version/s: 2.2

Type: Task Priority: Neutral
Reporter: Christoph Meier Assignee: Christoph Meier
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
causality
is causing MGNLCMNT-99 Commenting requires cache 5.2.3 Closed
dependency
depends upon MGNLCACHE-54 CLONE - uuid-cache key mapping is not... Closed
relation
is related to MGNLCMNT-97 Flushing cache after commenting is tr... Closed
is related to MGNLCMNT-57 Commenting form is showing to all use... Closed
Template:
Acceptance criteria:
Empty
Task DoR:
Empty
Date of First Response:

 Description   

Commenting requires the role "forum-pagecomments-user". Add this to user anonymous to ensure he is able to comment.



 Comments   
Comment by Christoph Meier [ 04/Feb/14 ]

Added role forum-pagecomments-user to anonymous-user, but:
anonymous-user can add comments, but cannot see them. To see the comments, the user must be logged in.

Comment by Christoph Meier [ 07/Feb/14 ]

Probably a caching problem; ReferencedPageFlushPolicy or super-class not working properly.

Comment by Christoph Meier [ 13/Feb/14 ]

Defintely a caching problem; ReferencedPageFlushPolicy or super-class not working properly.
(Beside the fact that it also triggered too late.)
The page seems to be cached at the very first time, when there is no comment on it, after that is always served from cache; even if somebody added comment(s).
Adding a comment tiggers an event which is treated in ReferencedPageFlushPolicy which should result in flushing that page; but the flushing fails all the time.

If somebody wants to tackle this one: startt debuging in ReferencedPageFlushPolicy#handleSingleEvent,
follow the track to AbstractListeningFlushPolicy#flushByUUID; there, size of Object[] cacheEntryKeys is lways 0; so flushing never works.
Going deeper show, that in info.magnolia.module.cache.cachepolicy.Default private method getUUIDKeySetFromCacheSafely has very strange impl. ... here is one of th reasons, why Object[] cacheEntryKeys.size is always 0.

I also tried to flush the page from PageComments (the model of the template which renders the commenting-messages), but was not able to do so.

Comment by Christoph Meier [ 17/Feb/14 ]

Since MGNLCACHE-54 is fixed now, flushing from cache the page with the comments now works,
but it occurs too late, ReferencedPageFlushPolicy is triggered too late.
To see the changes, a user must reload the page again to see his latest comment.

Comment by Christoph Meier [ 18/Feb/14 ]

I'll set this one to resolved to integrate the other work which was done here (adding the appr. role to anonymous).
The still remaining bug is now in a follow-up-ticket: MGNLCMNT-97

Comment by Espen Jervidalo [ 18/Feb/14 ]

remove all the commented lines in CommentingModuleVersionHandler

Comment by Roman Kovařík [ 19/Feb/14 ]
                try {
                    usersSession = installContext.getJCRSession(RepositoryConstants.USERS);
                    userRolesSession = installContext.getJCRSession(RepositoryConstants.USER_ROLES);
                    anonymousUserNode = usersSession.getRootNode().getNode("system/anonymous");
                    forumPpagecommentsUser_role_node =  userRolesSession.getRootNode().getNode("forum-pagecomments-user");

                } catch (Exception ex) {
                    installContext.warn("Exception while trying to add role forum-pagecomments-user to anonymous; "+ex.getLocalizedMessage());
                }
                return anonymousUserNode!=null && forumPpagecommentsUser_role_node!=null;

That's not the right way how to check if anonymous user / forum-pagecomments-user role exists, you should use info.magnolia.cms.security.RoleManager.getRole(String)/ UserManager.getAnonymousUser() to get such information

That code should be replaced, but couple of hints for next time:

  1. You can use NodeExistDelegateTask for checking of node existence in version handlers, no need to create new ConditionalDelegateTask.
  2. You should use session.nodeExists(), not session.getNode() and catch exception if you need to check node existence.
  3. forumPpagecommentsUser_role_node we try to not use underscores in variables
Generated at Mon Feb 12 00:03:06 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.