FEATURE: Include a user's pending posts in the topic view

FEATURE: Include a user’s pending posts in the topic view

Also includes a refactor to TopicView’s serializer which was not building our attributes using serializers properly.

diff --git a/app/assets/javascripts/discourse/controllers/composer.js.es6 b/app/assets/javascripts/discourse/controllers/composer.js.es6
index 0641f11..be239a8 100644
--- a/app/assets/javascripts/discourse/controllers/composer.js.es6
+++ b/app/assets/javascripts/discourse/controllers/composer.js.es6
@@ -679,6 +679,13 @@ export default Ember.Controller.extend({
       .then(result => {
         if (result.responseJson.action === "enqueued") {
           this.send("postWasEnqueued", result.responseJson);
+          if (result.responseJson.pending_post) {
+            let pendingPosts = this.get("topicController.model.pending_posts");
+            if (pendingPosts) {
+              pendingPosts.pushObject(result.responseJson.pending_post);
+            }
+          }
+
           this.destroyDraft();
           this.close();
           this.appEvents.trigger("post-stream:refresh");
diff --git a/app/assets/javascripts/discourse/controllers/topic.js.es6 b/app/assets/javascripts/discourse/controllers/topic.js.es6
index a51c2dd..7c0ba8b 100644
--- a/app/assets/javascripts/discourse/controllers/topic.js.es6
+++ b/app/assets/javascripts/discourse/controllers/topic.js.es6
@@ -202,6 +202,14 @@ export default Ember.Controller.extend(bufferedProperty("model"), {
   },
 
   actions: {
+    deletePending(pending) {
+      return ajax(`/review/${pending.id}`, { type: "DELETE" })
+        .then(() => {
+          this.get("model.pending_posts").removeObject(pending);
+        })
+        .catch(popupAjaxError);
+    },
+
     showPostFlags(post) {
       return this.send("showFlags", post);
     },
diff --git a/app/assets/javascripts/discourse/templates/topic.hbs b/app/assets/javascripts/discourse/templates/topic.hbs
index 9b09579..ae8c8e58 100644
--- a/app/assets/javascripts/discourse/templates/topic.hbs
+++ b/app/assets/javascripts/discourse/templates/topic.hbs
@@ -211,10 +211,41 @@
           {{#conditional-loading-spinner condition=model.postStream.loadingFilter}}
             {{#if loadedAllPosts}}
 
-              {{#if model.pending_posts_count}}
+              {{#if model.pending_posts}}
+                <div class='pending-posts'>
+                  {{#each model.pending_posts as |pending|}}
+                    <div class='reviewable-item'>
+                      <div class='reviewable-meta-data'>
+                        <span class='reviewable-type'>
+                          {{i18n "review.awaiting_approval"}}
+                        </span>
+                        <span class='created-at'>
+                          {{age-with-tooltip pending.created_at}}
+                        </span>
+                      </div>
+                      <div class='post-contents-wrapper'>
+                        {{reviewable-created-by user=currentUser tagName=''}}
+                        <div class='post-contents'>
+                          {{reviewable-created-by-name user=currentUser tagName=''}}
+                          <div class='post-body'>{{cook-text pending.raw}}</div>
+                        </div>
+                      </div>
+                      <div class='reviewable-actions'>
+                        {{d-button
+                          class="btn-danger"
+                          label="review.delete"
+                          icon="trash-alt"
+                          action=(action "deletePending" pending) }}
+                      </div>
+                    </div>
+                  {{/each}}
+                </div>
+              {{/if}}
+
+              {{#if model.queued_posts_count}}
                 <div class="has-pending-posts">
                   <div>
-                    {{{i18n "review.topic_has_pending" count=model.pending_posts_count}}}
+                    {{{i18n "review.topic_has_pending" count=model.queued_posts_count}}}
                   </div>
 
                   {{#link-to 'review' (query-params topic_id=model.id type="ReviewableQueuedPost" status="pending")}}
diff --git a/app/assets/stylesheets/common/base/topic.scss b/app/assets/stylesheets/common/base/topic.scss
index b54bca6..dd9fcb5 100644
--- a/app/assets/stylesheets/common/base/topic.scss
+++ b/app/assets/stylesheets/common/base/topic.scss
@@ -266,3 +266,17 @@ a.topic-featured-link {
     margin-right: 3px;
   }
 }
+
+.topic-area {
+  .pending-posts {
+    max-width: calc(
+      #{$topic-body-width} + #{$topic-avatar-width} + #{$topic-body-width-padding *
+        2}
+    );
+    .reviewable-item {
+      .post-body {
+        max-height: unset;
+      }
+    }
+  }
+}
diff --git a/app/controllers/reviewables_controller.rb b/app/controllers/reviewables_controller.rb
index f91dcbf..3551c9d 100644
--- a/app/controllers/reviewables_controller.rb
+++ b/app/controllers/reviewables_controller.rb
@@ -96,6 +96,15 @@ class ReviewablesController < ApplicationController
     )
   end
 
+  def destroy
+    reviewable = Reviewable.find_by(id: params[:reviewable_id], created_by: current_user)
+    raise Discourse::NotFound.new if reviewable.blank?
+
+    reviewable.perform(current_user, :delete)
+
+    render json: success_json
+  end
+
   def update
     reviewable = find_reviewable
     editable = reviewable.editable_for(guardian)
diff --git a/app/models/reviewable.rb b/app/models/reviewable.rb
index 5debd5b..5e9969a 100644
--- a/app/models/reviewable.rb
+++ b/app/models/reviewable.rb
@@ -482,8 +482,9 @@ end
 #
 # Indexes
 #
-#  index_reviewables_on_status_and_created_at  (status,created_at)
-#  index_reviewables_on_status_and_score       (status,score)
-#  index_reviewables_on_status_and_type        (status,type)
-#  index_reviewables_on_type_and_target_id     (type,target_id) UNIQUE
+#  index_reviewables_on_status_and_created_at                  (status,created_at)
+#  index_reviewables_on_status_and_score                       (status,score)
+#  index_reviewables_on_status_and_type                        (status,type)
+#  index_reviewables_on_topic_id_and_status_and_created_by_id  (topic_id,status,created_by_id)
+#  index_reviewables_on_type_and_target_id                     (type,target_id) UNIQUE
 #
diff --git a/app/models/reviewable_flagged_post.rb b/app/models/reviewable_flagged_post.rb
index 67ae263..be98034 100644
--- a/app/models/reviewable_flagged_post.rb
+++ b/app/models/reviewable_flagged_post.rb
@@ -304,8 +304,9 @@ end
 #
 # Indexes
 #
-#  index_reviewables_on_status_and_created_at  (status,created_at)
-#  index_reviewables_on_status_and_score       (status,score)
-#  index_reviewables_on_status_and_type        (status,type)
-#  index_reviewables_on_type_and_target_id     (type,target_id) UNIQUE
+#  index_reviewables_on_status_and_created_at                  (status,created_at)
+#  index_reviewables_on_status_and_score                       (status,score)
+#  index_reviewables_on_status_and_type                        (status,type)
+#  index_reviewables_on_topic_id_and_status_and_created_by_id  (topic_id,status,created_by_id)
+#  index_reviewables_on_type_and_target_id                     (type,target_id) UNIQUE
 #
diff --git a/app/models/reviewable_queued_post.rb b/app/models/reviewable_queued_post.rb
index c60fd5d..8f8bf12 100644
--- a/app/models/reviewable_queued_post.rb
+++ b/app/models/reviewable_queued_post.rb
@@ -9,18 +9,20 @@ class ReviewableQueuedPost < Reviewable
   end
 
   def build_actions(actions, guardian, args)
-    return unless guardian.is_staff?
-
-    actions.add(:approve) unless approved?
-    actions.add(:reject) unless rejected?
-
-    if pending? && guardian.can_delete_user?(created_by)
-      actions.add(:delete_user) do |action|
-        action.icon = 'trash-alt'
-        action.label = 'reviewables.actions.delete_user.title'
-        action.confirm_message = 'reviewables.actions.delete_user.confirm'
+    if guardian.is_staff?
+      actions.add(:approve) unless approved?
+      actions.add(:reject) unless rejected?
+
+      if pending? && guardian.can_delete_user?(created_by)
+        actions.add(:delete_user) do |action|
+          action.icon = 'trash-alt'

[... diff too long, it was truncated ...]

GitHub sha: a5d9afe3

1 Like

This commit has been mentioned on Discourse Meta. There might be relevant details there: