001/*
002 *  Copyright 2014 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016
017package org.ametys.cms.repository.comment.ui;
018
019import java.io.IOException;
020import java.util.ArrayList;
021import java.util.HashMap;
022import java.util.List;
023import java.util.Map;
024
025import org.apache.avalon.framework.service.ServiceException;
026import org.apache.avalon.framework.service.ServiceManager;
027import org.apache.cocoon.ProcessingException;
028import org.apache.commons.lang.StringUtils;
029
030import org.ametys.cms.ObservationConstants;
031import org.ametys.cms.content.ContentHelper;
032import org.ametys.cms.repository.Content;
033import org.ametys.cms.repository.comment.Comment;
034import org.ametys.cms.repository.comment.CommentableContent;
035import org.ametys.cms.rights.ContentRightAssignmentContext;
036import org.ametys.core.observation.Event;
037import org.ametys.core.observation.ObservationManager;
038import org.ametys.core.right.RightManager.RightResult;
039import org.ametys.core.ui.Callable;
040import org.ametys.core.ui.StaticClientSideElement;
041import org.ametys.core.user.UserIdentity;
042import org.ametys.core.util.DateUtils;
043import org.ametys.plugins.repository.AmetysObjectResolver;
044import org.ametys.plugins.repository.UnknownAmetysObjectException;
045
046/**
047 * This client site elements creates a button representing the validation state of a content's comment
048 */
049public class CommentClientSideElement extends StaticClientSideElement
050{
051    /** The constant for the name of the author from parameters */
052    public static final String PARAMETER_AUTHOR_NAME = "author-name";
053    /** The constant for the email of the author from parameters */
054    public static final String PARAMETER_AUTHOR_EMAIL = "author-email";
055    /** The constant for the hidden status of the email of the author from parameters */
056    public static final String PARAMETER_AUTHOR_EMAILHIDDEN = "author-emailhidden";
057    /** The constant for the url of the author from parameters */
058    public static final String PARAMETER_AUTHOR_URL = "author-url";
059    /** The constant for the text from parameters */
060    public static final String PARAMETER_TEXT = "text";
061    /** The constant for the content id from parameters */
062    public static final String PARAMETER_CONTENT_ID = "contentId";
063    /** The constant for the comment id from parameters */
064    public static final String PARAMETER_COMMENT_ID = "commentId";
065    /** The Ametys object resolver */
066    protected AmetysObjectResolver _resolver;
067    /** The observation manager */
068    protected ObservationManager _observationManager;
069    /** The content helper */
070    private ContentHelper _contentHelper;
071
072    @Override
073    public void service(ServiceManager smanager) throws ServiceException
074    {
075        super.service(smanager);
076        _resolver = (AmetysObjectResolver) smanager.lookup(AmetysObjectResolver.ROLE);
077        _observationManager = (ObservationManager) smanager.lookup(ObservationManager.ROLE);
078        _contentHelper = (ContentHelper) smanager.lookup(ContentHelper.ROLE);
079    }
080    
081    /**
082     * Return the list of comments with its validation state
083     * @param parameters The contents and their comments
084     * @return The comments and their validated status
085     */
086    @Callable(rights = Callable.SKIP_BUILTIN_CHECK)
087    public Map<String, Object> getComments(Map<String, Object> parameters)
088    {
089        Map<String, Object> results = new HashMap<>();
090        results.put("comments", new ArrayList<>());
091        results.put("noright-contents", new ArrayList<>());
092        
093        UserIdentity user = _currentUserProvider.getUser();
094        
095        for (String contentId : parameters.keySet())
096        {
097            try
098            {
099                Content content = _resolver.resolveById(contentId);
100                if (_rightManager.hasRight(user, "CMS_Rights_CommentModerate", content) == RightResult.RIGHT_ALLOW)
101                {
102                    if (content instanceof CommentableContent)
103                    {
104                        CommentableContent cContent = (CommentableContent) content;
105                        
106                        @SuppressWarnings("unchecked")
107                        List<String> commentIds = (List<String>) parameters.get(contentId);
108                        
109                        for (String commentId : commentIds)
110                        {
111                            Comment comment = cContent.getComment(commentId);
112                            @SuppressWarnings("unchecked")
113                            List<Map<String, Object>> comments = (List<Map<String, Object>>) results.get("comments");
114                            comments.add(getCommentParameters(cContent, comment));
115                        }   
116                    }
117                    else
118                    {
119                        getLogger().warn("Ignoring request to get comments status on non commentable content " + contentId);
120                    }
121                }
122                else
123                {
124                    @SuppressWarnings("unchecked")
125                    List<Map<String, Object>> noRightContents = (List<Map<String, Object>>) results.get("noright-contents");
126                    noRightContents.add(getContentDefaultParameters(content));
127                    getLogger().warn("Ignoring request to get comments status on content" + contentId + " without sufficient right");
128                }
129            }
130            catch (UnknownAmetysObjectException e)
131            {
132                getLogger().warn("Ignoring request to get comments status on unnexisting content " + contentId, e);
133            }
134        }
135        
136        return results;
137    }
138    
139    /**
140     * Get a comment properties
141     * @param contentId the id of the content
142     * @param commentId the id of the comment. Can be null
143     * @return results the server's response in JSON.
144     * @throws IOException If an error occurred
145     * @throws ProcessingException If an error occurred
146     */
147    @Callable(rights = Callable.READ_ACCESS, paramIndex = 0, rightContext = ContentRightAssignmentContext.ID)
148    public Map<String, Object> getComment(String contentId, String commentId) throws IOException, ProcessingException
149    {
150        Map<String, Object> results = new HashMap<> ();
151        results.put("noright-contents", new ArrayList<>());
152               
153        UserIdentity user = _currentUserProvider.getUser();
154        
155        Map<String, Object> comments = new HashMap<> ();
156        
157        Content content = _resolver.resolveById(contentId);
158        if (StringUtils.isNotEmpty(commentId))
159        {
160            if (content instanceof CommentableContent)
161            {
162                if (_rightManager.hasRight(user, "CMS_Rights_CommentModerate", content) == RightResult.RIGHT_ALLOW)
163                {
164                    CommentableContent commentableContent = (CommentableContent) content;
165                    Comment comment = commentableContent.getComment(commentId);
166                    comments = _jsonifyComment(comment, content);
167                }
168            }
169            else
170            {
171                @SuppressWarnings("unchecked")
172                List<Map<String, Object>> noRightContents = (List<Map<String, Object>>) results.get("noright-contents");
173                noRightContents.add(getContentDefaultParameters(content));
174            }
175        }
176        
177        results.put("comments", comments);
178        return results;
179    }
180    
181    /**
182     * Get the default content's parameters
183     * @param content The content
184     * @return The default parameters
185     */
186    protected Map<String, Object> getContentDefaultParameters(Content content)
187    {
188        Map<String, Object> contentParams = new HashMap<>();
189        contentParams.put("id", content.getId());
190        contentParams.put("title", _contentHelper.getTitle(content));
191        
192        return contentParams;
193    }
194
195    /**
196     * Edit a comment if connected user has sufficient rights
197     * @param parameters the JS parameters. Necessarily contains the content and comment id, and the values to edit
198     * @return An empty map
199     */
200    @Callable(rights = Callable.SKIP_BUILTIN_CHECK)
201    public Map<String, Object> editComment(Map<String, Object> parameters)
202    {
203        String contentId = (String) parameters.get(PARAMETER_CONTENT_ID);
204        String commentId = (String) parameters.get(PARAMETER_COMMENT_ID);
205        
206        try
207        {
208            Content content = _resolver.resolveById(contentId);
209
210            if (!hasRight("CMS_Rights_CommentModerate", content))
211            {
212                String errorMessage = "User " + getCurrentUser() + " try to edit a comment on content of id '" + contentId + "' with no sufficient rights"; 
213                getLogger().error(errorMessage);
214                throw new IllegalStateException(errorMessage);
215            }
216            
217            if (!(content instanceof CommentableContent))
218            {
219                String errorMessage = "Can not edit comment for non-commentable content of id '" + contentId + "'"; 
220                getLogger().error(errorMessage);
221                throw new IllegalStateException(errorMessage);
222            }
223            
224            CommentableContent cContent = (CommentableContent) content;
225            
226            Comment comment = cContent.getComment(commentId);
227            
228            String oldAuthorName = comment.getAuthorName();
229            String oldAuthorEmail = comment.getAuthorEmail();
230            boolean oldAuthorEmailHidden = comment.isEmailHidden();
231            String oldAuthorURL = comment.getAuthorURL();
232            String oldContent = comment.getContent();
233            
234            boolean needSave = false;
235            
236            String authorName = (String) parameters.get(PARAMETER_AUTHOR_NAME);
237            if (!authorName.equals(oldAuthorName))
238            {
239                comment.setAuthorName(authorName);
240                needSave = true;
241            }
242            
243            String authorEmail = (String) parameters.get(PARAMETER_AUTHOR_EMAIL);
244            if (!authorEmail.equals(oldAuthorEmail))
245            {
246                comment.setAuthorEmail(authorEmail);
247                needSave = true;
248            }
249            
250            boolean authorEmailHidden = (Boolean) parameters.get(PARAMETER_AUTHOR_EMAILHIDDEN);
251            if (authorEmailHidden != oldAuthorEmailHidden)
252            {
253                comment.setEmailHiddenStatus(authorEmailHidden);
254                needSave = true;
255            }
256            
257            String authorUrl = (String) parameters.get(PARAMETER_AUTHOR_URL);
258            if (!authorUrl.equals(oldAuthorURL))
259            {
260                comment.setAuthorURL(authorUrl);
261                needSave = true;
262            }
263            
264            String text = (String) parameters.get(PARAMETER_TEXT);
265            if (!text.equals(oldContent))
266            {
267                comment.setContent(text);
268                needSave = true;
269            }
270            
271            if (needSave)
272            {
273                cContent.saveChanges();
274                
275                Map<String, Object> eventParams = new HashMap<>();
276                eventParams.put(ObservationConstants.ARGS_CONTENT, content);
277                eventParams.put(ObservationConstants.ARGS_COMMENT, comment);
278                eventParams.put("content.comment.old.author", oldAuthorName);
279                eventParams.put("content.comment.old.author.email", oldAuthorEmail);
280                eventParams.put("content.comment.old.author.email.hidden", oldAuthorEmailHidden);
281                eventParams.put("content.comment.old.author.url", oldAuthorURL);
282                eventParams.put("content.comment.old.content", oldContent);
283                
284                _observationManager.notify(new Event(ObservationConstants.EVENT_CONTENT_COMMENT_MODIFYING, getCurrentUser(), eventParams));
285            }
286        
287            return getCommentParameters(content, comment);
288        }
289        catch (UnknownAmetysObjectException e)
290        {
291            getLogger().error("Unknown content of id '" + contentId + "'", e);
292            throw new IllegalArgumentException("Unknown content of id '" + contentId + "'", e);
293        }
294    }
295    
296    /**
297     * Removes comments
298     * @param contents the contents with comments to remove
299     * @return the JSON result with deleted comments or not
300     */
301    @SuppressWarnings("unchecked")
302    @Callable(rights = Callable.SKIP_BUILTIN_CHECK)
303    public Map<String, Object> deleteComments(Map<String, List<String>> contents)
304    {
305        Map<String, Object> results = new HashMap<> ();
306        
307        results.put("deleted-comments", new ArrayList<>());
308        results.put("undeleted-comments", new ArrayList<>());
309        results.put("uncommentable-contents", new ArrayList<>());
310        results.put("noright-contents", new ArrayList<>());
311        results.put("unknown-contents", new ArrayList<>());
312        
313        for (String contentId : contents.keySet())
314        {
315            try
316            {
317                Content content = _resolver.resolveById(contentId);
318                
319                if (hasRight("CMS_Rights_CommentModerate", content))
320                {
321                    List<String> deleteCommentIds = new ArrayList<>();
322                    // For each associated comment
323                    for (String commentId : contents.get(contentId))
324                    {
325                        if (!_isParentCommentAlreadyDelete(deleteCommentIds, commentId))
326                        {
327                            Map<String, Object> commentParams = new HashMap<>();
328                            commentParams.put("id", commentId);
329                            commentParams.put("contentId", contentId);
330                            commentParams.put("contentTitle", _contentHelper.getTitle(content));
331                            
332                            if (content instanceof CommentableContent)
333                            {
334                                CommentableContent cContent = (CommentableContent) content;
335                                Comment comment = cContent.getComment(commentId);
336                                
337                                Map<String, Object> eventParams = new HashMap<>();
338                                eventParams.put(ObservationConstants.ARGS_CONTENT, content);
339                                eventParams.put(ObservationConstants.ARGS_COMMENT_ID, comment.getId());
340                                eventParams.put(ObservationConstants.ARGS_COMMENT_AUTHOR, comment.getAuthorName());
341                                eventParams.put(ObservationConstants.ARGS_COMMENT_AUTHOR_EMAIL, comment.getAuthorEmail());
342                                eventParams.put(ObservationConstants.ARGS_COMMENT_VALIDATED, comment.isValidated());
343                                eventParams.put(ObservationConstants.ARGS_COMMENT_CREATION_DATE, comment.getCreationDate());
344                                eventParams.put("comment.content", comment.getContent());
345                                
346                                _observationManager.notify(new Event(ObservationConstants.EVENT_CONTENT_COMMENT_DELETING, getCurrentUser(), eventParams));
347                                
348                                comment.remove();
349                                cContent.saveChanges();
350        
351                                List<Map<String, Object>> deletedComments = (List<Map<String, Object>>) results.get("deleted-comments");
352                                deletedComments.add(commentParams);
353                                deleteCommentIds.add(commentId);
354                                
355                                _observationManager.notify(new Event(ObservationConstants.EVENT_CONTENT_COMMENT_DELETED, getCurrentUser(), eventParams));
356                            }
357                            else
358                            {
359                                getLogger().error("Can not remove a comment on a non commentable content");
360                                
361                                List<Map<String, Object>> uncommentableContents = (List<Map<String, Object>>) results.get("uncommentable-contents");
362                                uncommentableContents.add(commentParams);
363                            }
364                        }
365                    }
366                }
367                else
368                {
369                    // No right
370                    getLogger().error("User '" + getCurrentUser() + "' does not have right to moderate comments on content '" + content.getId() + "'");
371                    
372                    Map<String, Object> contentParams = new HashMap<>();
373                    contentParams.put("contentId", contentId);
374                    contentParams.put("contentTitle", _contentHelper.getTitle(content));
375                    
376                    List<Map<String, Object>> norightContents = (List<Map<String, Object>>) results.get("noright-contents");
377                    norightContents.add(contentParams);
378                }
379            }
380            catch (UnknownAmetysObjectException e)
381            {
382                getLogger().error("Can not remove a comment on a non existing content", e);
383                
384                Map<String, Object> contentParams = new HashMap<>();
385                contentParams.put("contentId", contentId);
386                
387                List<Map<String, Object>> unknownContents = (List<Map<String, Object>>) results.get("unknown-contents");
388                unknownContents.add(contentParams);
389            }
390        }
391
392        return results;
393    }
394    
395    /**
396     * True if the a parent comment of the comment id is already deleted
397     * @param deleteCommentIds the delete comment ids
398     * @param commentId the comment id
399     * @return true if the a parent comment of the comment id is already deleted
400     */
401    protected boolean _isParentCommentAlreadyDelete(List<String> deleteCommentIds, String commentId)
402    {
403        for (String deleteCommentId : deleteCommentIds)
404        {
405            if (commentId.startsWith(deleteCommentId))
406            {
407                return true;
408            }
409        }
410        
411        return false;
412    }
413    
414    /**
415     * Validates comments when it is possible.
416     * @param contents the contents with comments to validate
417     * @return the JSON result with validated comments or not
418     */
419    @SuppressWarnings("unchecked")
420    @Callable(rights = Callable.SKIP_BUILTIN_CHECK)
421    public Map<String, Object> validateComments(Map<String, List<String>> contents)
422    {
423        Map<String, Object> results = new HashMap<>();
424
425        results.put("validated-comments", new ArrayList<>());
426        results.put("error-comments", new ArrayList<>());
427        results.put("uncommentable-contents", new ArrayList<>());
428        results.put("noright-contents", new ArrayList<>());
429        results.put("unknown-contents", new ArrayList<>());
430        
431        for (String contentId : contents.keySet())
432        {
433            try
434            {
435                Content content = _resolver.resolveById(contentId);
436                
437                if (hasRight("CMS_Rights_CommentModerate", content))
438                {
439                    // For each associated comment
440                    for (String commentId : contents.get(contentId))
441                    {
442                        Map<String, Object> commentParams = new HashMap<>();
443                        commentParams.put("id", commentId);
444                        commentParams.put("contentId", contentId);
445                        commentParams.put("contentTitle", _contentHelper.getTitle(content));
446                        
447                        if (content instanceof CommentableContent)
448                        {
449                            CommentableContent cContent = (CommentableContent) content;
450        
451                            Comment comment = cContent.getComment(commentId);
452                            commentParams.put("reportsCount", comment.getReportsCount());
453                            
454                            if (!comment.isValidated())
455                            {
456                                comment.setValidated(true);
457                                cContent.saveChanges();
458                                
459                                List<Map<String, Object>> validatedComments = (List<Map<String, Object>>) results.get("validated-comments");
460                                validatedComments.add(commentParams);
461                                
462                                Map<String, Object> eventParams = new HashMap<>();
463                                eventParams.put(ObservationConstants.ARGS_CONTENT, content);
464                                eventParams.put(ObservationConstants.ARGS_COMMENT, comment);
465                                _observationManager.notify(new Event(ObservationConstants.EVENT_CONTENT_COMMENT_VALIDATED, getCurrentUser(), eventParams));
466                            }
467                        }
468                        else
469                        {
470                            getLogger().error("Can not validate a comment on a non commentable content");
471                            
472                            List<Map<String, Object>> errorComments = (List<Map<String, Object>>) results.get("error-comments");
473                            errorComments.add(commentParams);
474                        }
475                    }
476                }
477                else
478                {
479                    // No right
480                    getLogger().error("User '" + getCurrentUser() + "' does not have right to validate comments on content '" + content.getId() + "'");
481                    
482                    Map<String, Object> contentParams = new HashMap<>();
483                    contentParams.put("contentId", contentId);
484                    contentParams.put("contentTitle", _contentHelper.getTitle(content));
485                }
486            }
487            catch (UnknownAmetysObjectException e)
488            {
489                getLogger().error("Can not validate a comment on a non existing content", e);
490                
491                Map<String, Object> contentParams = new HashMap<>();
492                contentParams.put("contentId", contentId);
493                
494                List<Map<String, Object>> unknownContents = (List<Map<String, Object>>) results.get("unknown-contents");
495                unknownContents.add(contentParams);
496            }
497        }
498
499        return results;
500    }
501    
502    /**
503     * Invalidates comments when it is possible.
504     * @param contents the contents with comments to invalidate
505     * @return the JSON result with invalidated comments or not
506     */
507    @SuppressWarnings("unchecked")
508    @Callable(rights = Callable.SKIP_BUILTIN_CHECK)
509    public Map<String, Object> invalidateComments(Map<String, List<String>> contents)
510    {
511        Map<String, Object> results = new HashMap<>();
512
513        results.put("unvalidated-comments", new ArrayList<>());
514        results.put("error-comments", new ArrayList<>());
515        results.put("uncommentable-contents", new ArrayList<>());
516        results.put("noright-contents", new ArrayList<>());
517        results.put("unknown-contents", new ArrayList<>());
518        
519        for (String contentId : contents.keySet())
520        {
521            try
522            {
523                Content content = _resolver.resolveById(contentId);
524                
525                if (hasRight("CMS_Rights_CommentModerate", content))
526                {
527                    // For each associated comment
528                    for (String commentId : contents.get(contentId))
529                    {
530                        Map<String, Object> commentParams = new HashMap<>();
531                        commentParams.put("id", commentId);
532                        commentParams.put("contentId", contentId);
533                        commentParams.put("contentTitle", _contentHelper.getTitle(content));
534                        
535                        if (content instanceof CommentableContent)
536                        {
537                            CommentableContent cContent = (CommentableContent) content;
538        
539                            Comment comment = cContent.getComment(commentId);
540                            commentParams.put("reportsCount", comment.getReportsCount());
541                            if (comment.isValidated())
542                            {
543                                comment.setValidated(false);
544                                cContent.saveChanges();
545
546                                List<Map<String, Object>> validatedComments = (List<Map<String, Object>>) results.get("unvalidated-comments");
547                                validatedComments.add(commentParams);
548
549                                Map<String, Object> eventParams = new HashMap<>();
550                                eventParams.put(ObservationConstants.ARGS_CONTENT, content);
551                                eventParams.put(ObservationConstants.ARGS_COMMENT, comment);
552                                _observationManager.notify(new Event(ObservationConstants.EVENT_CONTENT_COMMENT_UNVALIDATED, getCurrentUser(), eventParams));
553                            }
554                        }
555                        else
556                        {
557                            getLogger().error("Can not validate a comment on a non commentable content");
558                            
559                            List<Map<String, Object>> errorComments = (List<Map<String, Object>>) results.get("error-comments");
560                            errorComments.add(commentParams);
561                        }
562                    }
563                }
564                else
565                {
566                    // No right
567                    getLogger().error("User '" + getCurrentUser() + "' does not have right to validate comments on content '" + content.getId() + "'");
568                    
569                    Map<String, Object> contentParams = new HashMap<>();
570                    contentParams.put("contentId", contentId);
571                    contentParams.put("contentTitle", _contentHelper.getTitle(content));
572                }
573            }
574            catch (UnknownAmetysObjectException e)
575            {
576                getLogger().error("Can not validate a comment on a non existing content", e);
577                
578                Map<String, Object> contentParams = new HashMap<>();
579                contentParams.put("contentId", contentId);
580                
581                List<Map<String, Object>> unknownContents = (List<Map<String, Object>>) results.get("unknown-contents");
582                unknownContents.add(contentParams);
583            }
584        }
585
586        return results;
587    }
588    
589    /**
590     * Jsonify the comment.
591     * @param comment The comment
592     * @param content The content
593     * @return commentMap the comment map
594     */
595    protected Map<String, Object> _jsonifyComment (Comment comment, Content content) 
596    {
597        Map<String, Object> result = new HashMap<> ();
598        
599        Map<String, Object> commentMap = new HashMap<> ();
600            
601        
602        commentMap.put("validated", Boolean.toString(comment.isValidated()));
603        commentMap.put("id", comment.getId());
604        commentMap.put("creationDate", DateUtils.zonedDateTimeToString(comment.getCreationDate()));
605        
606        String authorName = comment.getAuthorName();
607        if (authorName != null)
608        {
609            commentMap.put("author-name", authorName);
610        }
611        
612        String authorEmail = comment.getAuthorEmail();
613        if (authorEmail != null)
614        {
615            Map<String, Object> authorEmailMap = new HashMap<> ();
616            authorEmailMap.put("hidden", Boolean.toString(comment.isEmailHidden()));
617            authorEmailMap.put("value", authorEmail);
618            commentMap.put("author-email", authorEmailMap);
619        }
620        
621        String authorUrl = comment.getAuthorURL();
622        if (authorUrl != null)
623        {
624            commentMap.put("author-url", authorUrl);
625        }
626        
627        String text = comment.getContent();
628        if (text != null)
629        {
630            commentMap.put("text", comment.getContent());
631        }
632        commentMap.put("content", _jsonifyContent(content));
633        
634        result.put("comment", commentMap);
635        
636        return result;
637    }
638    
639    /**
640     * Jsonify the content.
641     * @param content The content
642     * @return contentMap the content map
643     */
644    protected Map<String, Object> _jsonifyContent (Content content) 
645    {
646        Map<String, Object> contentMap = new HashMap<> ();
647        
648        contentMap.put("id", content.getId());
649        contentMap.put("title", _contentHelper.getTitle(content));
650        contentMap.put("name", content.getName());
651        
652        return contentMap;
653    }
654
655    /**
656     * Get the parameters for a comment
657     * @param content The content
658     * @param comment The comment
659     * @return The parameters
660     */
661    protected Map<String, Object> getCommentParameters (Content content, Comment comment)
662    {
663        Map<String, Object> params = new HashMap<>();
664        
665        params.put("contentId", content.getId());
666        params.put("contentTitle", _contentHelper.getTitle(content));
667        params.put("id", comment.getId());
668        params.put("validated", comment.isValidated());
669        params.put("reportsCount", comment.getReportsCount());
670        
671        return params;
672    }
673    
674    /**
675     * Get the current user
676     * @return The current user
677     */
678    protected UserIdentity getCurrentUser ()
679    {
680        return _currentUserProvider.getUser();
681    }
682
683    /**
684     * Determines if connected user has right on content
685     * @param rightId The right id
686     * @param content The content
687     * @return true if user has right
688     */
689    protected boolean hasRight (String rightId, Content content)
690    {
691        UserIdentity user = _currentUserProvider.getUser();
692        
693        return _rightManager.hasRight(user, "CMS_Rights_CommentModerate", content) == RightResult.RIGHT_ALLOW;
694    }
695}