Added support for responses awaiting approval
authorAlexander Ebert <ebert@woltlab.com>
Wed, 8 Mar 2017 12:48:52 +0000 (13:48 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 8 Mar 2017 12:48:52 +0000 (13:48 +0100)
See #2219

com.woltlab.wcf/templates/commentListAddComment.tpl
com.woltlab.wcf/templates/commentResponseList.tpl
wcfsetup/install/files/js/WCF.Comment.js
wcfsetup/install/files/lib/data/comment/CommentAction.class.php
wcfsetup/install/files/lib/data/comment/StructuredCommentList.class.php
wcfsetup/install/files/style/ui/comment.scss

index 8b950510f249cbafa0e8071fef3d3984e7f4e357..7f120261cf6bf10eb225750759da044075c2baae 100644 (file)
@@ -3,7 +3,7 @@
        <div class="commentListAddComment collapsed" data-placeholder="{lang}wcf.comment.add{/lang}">
                <div class="commentListAddCommentEditorContainer">
                        {if !$commentList->getCommentManager()->canAddWithoutApproval($commentList->objectID)}
-                               <p class="info">{lang}wcf.comment.add.moderation.info{/lang}</p>
+                               <p class="info jsCommentAddRequiresApproval">{lang}wcf.comment.add.moderation.info{/lang}</p>
                        {/if}
                        
                        <textarea id="{$wysiwygSelector}" name="text" class="wysiwygTextarea"
index 16c8feaed54b1dbda5a71049652ced90688ed620..5da9c59fe35e04fb8d10b5aeed2c21f0ad5302d1 100644 (file)
                                                {/if}
                                                
                                                <small class="separatorLeft">{@$response->time|time}</small>
+                                               
+                                               {if $response->isDisabled}
+                                                       <span class="badge label green jsIconDisabled">{lang}wcf.message.status.disabled{/lang}</span>
+                                               {/if}
                                        </h3>
                                </div>
                                
index 92654a58ff115bd9ffa8c53e9e16b1a89e61eff2..af9f320a978b95b984fc0c847f326266b1a21b23 100644 (file)
@@ -524,6 +524,12 @@ WCF.Comment.Handler = Class.extend({
                $input.keyup(function(event) { self._keyUp(event, true); });
                
                comment.data('responsePlaceholder', $placeholder).data('responseInput', $listItem);
+               
+               // mirror the moderation notice
+               var commentRequireApproval = elBySel('.commentListAddCommentEditorContainer .jsCommentAddRequiresApproval', this._container[0]);
+               if (commentRequireApproval) {
+                       $inputContainer[0].insertBefore(commentRequireApproval.cloneNode(true), $inputContainer[0].firstChild);
+               }
        },
        
        /**
index d8e42c21b22b80b272377ec01c1d56bfcbb867f5..58914f7c2ca031c0f52f437cdef0a3c2c179af72 100644 (file)
@@ -404,6 +404,11 @@ class CommentAction extends AbstractDatabaseObjectAction implements IMessageInli
                // validate comment id
                $this->validateCommentID();
                
+               // disallow responses on disabled comments
+               if ($this->comment->isDisabled) {
+                       throw new PermissionDeniedException();
+               }
+               
                $objectType = $this->validateObjectType();
                
                // validate object id and permissions
@@ -438,8 +443,10 @@ class CommentAction extends AbstractDatabaseObjectAction implements IMessageInli
                        'time' => TIME_NOW,
                        'userID' => WCF::getUser()->userID ?: null,
                        'username' => WCF::getUser()->userID ? WCF::getUser()->username : $this->parameters['data']['username'],
-                       'message' => $this->parameters['data']['message']
+                       'message' => $this->parameters['data']['message'],
+                       'isDisabled' => $this->commentProcessor->canAddWithoutApproval($this->parameters['data']['objectID']) ? 0 : 1
                ]);
+               $this->createdResponse->setComment($this->comment);
                
                // update response data
                $responseIDs = $this->comment->getResponseIDs();
@@ -455,77 +462,12 @@ class CommentAction extends AbstractDatabaseObjectAction implements IMessageInli
                        'responses' => $responses
                ]);
                
-               // update counter
-               $this->commentProcessor->updateCounter($this->parameters['data']['objectID'], 1);
-               
-               // fire activity event
-               $objectType = ObjectTypeCache::getInstance()->getObjectType($this->comment->objectTypeID);
-               if ($this->createdResponse->userID && UserActivityEventHandler::getInstance()->getObjectTypeID($objectType->objectType.'.response.recentActivityEvent')) {
-                       UserActivityEventHandler::getInstance()->fireEvent($objectType->objectType.'.response.recentActivityEvent', $this->createdResponse->responseID);
-               }
-               
-               // fire notification event
-               if (UserNotificationHandler::getInstance()->getObjectTypeID($objectType->objectType.'.response.notification') && UserNotificationHandler::getInstance()->getObjectTypeID($objectType->objectType.'.notification')) {
-                       $notificationObjectType = UserNotificationHandler::getInstance()->getObjectTypeProcessor($objectType->objectType.'.notification');
-                       $notificationObject = new CommentResponseUserNotificationObject($this->createdResponse);
-                       
-                       if ($notificationObjectType instanceof IMultiRecipientCommentUserNotificationObjectType) {
-                               $recipientIDs = $notificationObjectType->getRecipientIDs($this->comment);
-                               
-                               // make sure that the active user gets no notification
-                               $recipientIDs = array_diff($recipientIDs, [WCF::getUser()->userID]);
-                               
-                               if (!empty($recipientIDs)) {
-                                       UserNotificationHandler::getInstance()->fireEvent(
-                                               'commentResponse',
-                                               $objectType->objectType . '.response.notification',
-                                               $notificationObject,
-                                               $recipientIDs,
-                                               [
-                                                       'commentID' => $this->comment->commentID,
-                                                       'objectID' => $this->comment->objectID,
-                                                       'userID' => $this->comment->userID
-                                               ]
-                                       );
-                               }
-                       }
-                       else {
-                               /** @var ICommentUserNotificationObjectType $notificationObjectType */
-                               
-                               $userID = $notificationObjectType->getOwnerID($this->comment->commentID);
-                               
-                               if ($this->comment->userID != WCF::getUser()->userID) {
-                                       UserNotificationHandler::getInstance()->fireEvent(
-                                               'commentResponse',
-                                               $objectType->objectType . '.response.notification',
-                                               $notificationObject,
-                                               [$this->comment->userID],
-                                               [
-                                                       'commentID' => $this->comment->commentID,
-                                                       'objectID' => $this->comment->objectID,
-                                                       'objectUserID' => $userID,
-                                                       'userID' => $this->comment->userID
-                                               ]
-                                       );
-                               }
-                               
-                               // notify the container owner
-                               if (UserNotificationHandler::getInstance()->getObjectTypeID($objectType->objectType.'.notification')) {
-                                       if ($userID != $this->comment->userID && $userID != WCF::getUser()->userID) {
-                                               UserNotificationHandler::getInstance()->fireEvent(
-                                                       'commentResponseOwner',
-                                                       $objectType->objectType . '.response.notification',
-                                                       $notificationObject,
-                                                       [$userID], [
-                                                               'commentID' => $this->comment->commentID,
-                                                               'objectID' => $this->comment->objectID,
-                                                               'objectUserID' => $userID,
-                                                               'userID' => $this->comment->userID
-                                                       ]
-                                               );
-                                       }
-                               }
-                       }
+               if (!$this->createdResponse->isDisabled) {
+                       $action = new CommentAction([], 'triggerPublicationResponse', [
+                               'commentProcessor' => $this->commentProcessor,
+                               'responses' => [$this->createdResponse]
+                       ]);
+                       $action->executeAction();
                }
                
                if (!$this->createdResponse->userID) {
@@ -548,6 +490,100 @@ class CommentAction extends AbstractDatabaseObjectAction implements IMessageInli
                ];
        }
        
+       public function triggerPublicationResponse() {
+               if (!empty($this->parameters['commentProcessor'])) {
+                       $objectType = null;
+                       if (!empty($this->parameters['responses'])) {
+                               /** @var CommentResponse $response */
+                               $response = reset($this->parameters['responses']);
+                               $objectType = $this->validateObjectType($response->getComment()->objectTypeID);
+                       }
+                       
+                       $this->commentProcessor = $this->parameters['commentProcessor'];
+               }
+               else {
+                       $objectType = $this->validateObjectType($this->parameters['objectTypeID']);
+                       $this->commentProcessor = $objectType->getProcessor();
+               }
+               
+               /** @var CommentResponseEditor $response */
+               foreach ($this->parameters['responses'] as $response) {
+                       $comment = $response->getComment();
+                       
+                       // update counter
+                       $this->commentProcessor->updateCounter($comment->objectID, 1);
+                       
+                       // fire activity event
+                       if ($this->createdResponse->userID && UserActivityEventHandler::getInstance()->getObjectTypeID($objectType->objectType.'.response.recentActivityEvent')) {
+                               UserActivityEventHandler::getInstance()->fireEvent($objectType->objectType.'.response.recentActivityEvent', $this->createdResponse->responseID);
+                       }
+                       
+                       // fire notification event
+                       if (UserNotificationHandler::getInstance()->getObjectTypeID($objectType->objectType.'.response.notification') && UserNotificationHandler::getInstance()->getObjectTypeID($objectType->objectType.'.notification')) {
+                               $notificationObjectType = UserNotificationHandler::getInstance()->getObjectTypeProcessor($objectType->objectType.'.notification');
+                               $notificationObject = new CommentResponseUserNotificationObject($this->createdResponse);
+                               
+                               if ($notificationObjectType instanceof IMultiRecipientCommentUserNotificationObjectType) {
+                                       $recipientIDs = $notificationObjectType->getRecipientIDs($comment);
+                                       
+                                       // make sure that the active user gets no notification
+                                       $recipientIDs = array_diff($recipientIDs, [WCF::getUser()->userID]);
+                                       
+                                       if (!empty($recipientIDs)) {
+                                               UserNotificationHandler::getInstance()->fireEvent(
+                                                       'commentResponse',
+                                                       $objectType->objectType . '.response.notification',
+                                                       $notificationObject,
+                                                       $recipientIDs,
+                                                       [
+                                                               'commentID' => $comment->commentID,
+                                                               'objectID' => $comment->objectID,
+                                                               'userID' => $comment->userID
+                                                       ]
+                                               );
+                                       }
+                               }
+                               else {
+                                       /** @var ICommentUserNotificationObjectType $notificationObjectType */
+                                       
+                                       $userID = $notificationObjectType->getOwnerID($comment->commentID);
+                                       
+                                       if ($comment->userID != WCF::getUser()->userID) {
+                                               UserNotificationHandler::getInstance()->fireEvent(
+                                                       'commentResponse',
+                                                       $objectType->objectType . '.response.notification',
+                                                       $notificationObject,
+                                                       [$this->comment->userID],
+                                                       [
+                                                               'commentID' => $comment->commentID,
+                                                               'objectID' => $comment->objectID,
+                                                               'objectUserID' => $userID,
+                                                               'userID' => $comment->userID
+                                                       ]
+                                               );
+                                       }
+                                       
+                                       // notify the container owner
+                                       if (UserNotificationHandler::getInstance()->getObjectTypeID($objectType->objectType.'.notification')) {
+                                               if ($userID != $comment->userID && $userID != WCF::getUser()->userID) {
+                                                       UserNotificationHandler::getInstance()->fireEvent(
+                                                               'commentResponseOwner',
+                                                               $objectType->objectType . '.response.notification',
+                                                               $notificationObject,
+                                                               [$userID], [
+                                                                       'commentID' => $comment->commentID,
+                                                                       'objectID' => $comment->objectID,
+                                                                       'objectUserID' => $userID,
+                                                                       'userID' => $comment->userID
+                                                               ]
+                                                       );
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+       
        /**
         * Validates parameters to edit a comment or a response.
         */
index fae20b38d44fcc776bf5c6d7d23ddaabdc55a2a4..f40515479b5878f183c87f3d616c8ee13ed371e8 100644 (file)
@@ -6,6 +6,7 @@ use wcf\data\like\object\LikeObject;
 use wcf\system\cache\runtime\UserProfileRuntimeCache;
 use wcf\system\comment\manager\ICommentManager;
 use wcf\system\like\LikeHandler;
+use wcf\system\WCF;
 
 /**
  * Provides a structured comment list fetching last responses for every comment.
@@ -89,6 +90,11 @@ class StructuredCommentList extends CommentList {
                $this->getConditionBuilder()->add("comment.objectTypeID = ?", [$objectTypeID]);
                $this->getConditionBuilder()->add("comment.objectID = ?", [$objectID]);
                $this->sqlLimit = $this->commentManager->getCommentsPerPage();
+               
+               if (!$this->commentManager->canModerate($objectTypeID, $objectID)) {
+                       if (WCF::getUser()->userID) $this->getConditionBuilder()->add('(comment.isDisabled = 0 OR comment.userID = ?)', [WCF::getUser()->userID]);
+                       else $this->getConditionBuilder()->add('comment.isDisabled = 0');
+               }
        }
        
        /**
index 2b464adc9efdbb70ab0f3b2eef1542575a7d9b1c..d951d95f3e4094707782726ab514ff4f3952e566 100644 (file)
        }
 }
 
-.commentListAddCommentEditorContainer > .info:first-child {
+.commentListAddCommentEditorContainer > .jsCommentAddRequiresApproval {
        margin-top: 0;
 }
 
+.commentResponseAdd > div > .jsCommentAddRequiresApproval {
+       margin-top: 0;
+       
+       & + textarea {
+               margin-top: 20px;
+       }
+}
+
 .commentEditorContainer {
        > .icon {
                left: calc(50% - 24px);