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