FIX: Clear stale status of reloaded reviewables (#13750)

FIX: Clear stale status of reloaded reviewables (#13750)

  • FIX: Clear stale status of reloaded reviewables

Navigating away from and back to the reviewables reloaded Reviewable records, but did not clear the “stale” attribute.

  • FEATURE: Show user who last acted on reviewable

When a user acts on a reviewable, all other clients are notified and a generic “reviewable was resolved by someone” notice was shown instead of the buttons. There is no need to keep secret the username of the acting user.

diff --git a/app/assets/javascripts/discourse/app/components/reviewable-item.js b/app/assets/javascripts/discourse/app/components/reviewable-item.js
index 23071ca..d7173eb 100644
--- a/app/assets/javascripts/discourse/app/components/reviewable-item.js
+++ b/app/assets/javascripts/discourse/app/components/reviewable-item.js
@@ -29,14 +29,14 @@ export default Component.extend({
 
   @discourseComputed(
     "reviewable.type",
-    "reviewable.stale",
+    "reviewable.last_performing_username",
     "siteSettings.blur_tl0_flagged_posts_media",
     "reviewable.target_created_by_trust_level"
   )
-  customClasses(type, stale, blurEnabled, trustLevel) {
+  customClasses(type, lastPerformingUsername, blurEnabled, trustLevel) {
     let classes = type.dasherize();
 
-    if (stale) {
+    if (lastPerformingUsername) {
       classes = `${classes} reviewable-stale`;
     }
 
diff --git a/app/assets/javascripts/discourse/app/routes/review-index.js b/app/assets/javascripts/discourse/app/routes/review-index.js
index 187c91c..a19b0f9 100644
--- a/app/assets/javascripts/discourse/app/routes/review-index.js
+++ b/app/assets/javascripts/discourse/app/routes/review-index.js
@@ -39,6 +39,8 @@ export default DiscourseRoute.extend({
       sort_order: meta.sort_order,
       additionalFilters: meta.additional_filters || {},
     });
+
+    controller.reviewables.setEach("last_performing_username", null);
   },
 
   activate() {
@@ -62,7 +64,6 @@ export default DiscourseRoute.extend({
           const updates = data.updates[reviewable.id];
           if (updates) {
             reviewable.setProperties(updates);
-            reviewable.set("stale", true);
           }
         });
       }
diff --git a/app/assets/javascripts/discourse/app/templates/components/reviewable-item.hbs b/app/assets/javascripts/discourse/app/templates/components/reviewable-item.hbs
index 9288db1..df7a072 100644
--- a/app/assets/javascripts/discourse/app/templates/components/reviewable-item.hbs
+++ b/app/assets/javascripts/discourse/app/templates/components/reviewable-item.hbs
@@ -44,8 +44,8 @@
     {{/if}}
   </div>
   <div class="reviewable-actions">
-    {{#if reviewable.stale}}
-      <div class="stale-help">{{i18n "review.stale_help"}}</div>
+    {{#if reviewable.last_performing_username}}
+      <div class="stale-help">{{html-safe (i18n "review.stale_help" username=reviewable.last_performing_username)}}</div>
     {{else}}
       {{#if claimEnabled}}
         <div class="claimed-actions">
diff --git a/app/assets/javascripts/discourse/tests/acceptance/review-test.js b/app/assets/javascripts/discourse/tests/acceptance/review-test.js
index 522fe2c..23c7b64 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/review-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/review-test.js
@@ -197,7 +197,7 @@ acceptance("Review", function (needs) {
     publishToMessageBus("/reviewable_counts", {
       review_count: 1,
       updates: {
-        1234: { status: 1 },
+        1234: { last_performing_username: "foo", status: 1 },
       },
     });
 
@@ -206,5 +206,11 @@ acceptance("Review", function (needs) {
     assert.ok(reviewable.className.includes("reviewable-stale"));
     assert.equal(count("[data-reviewable-id=1234] .status .approved"), 1);
     assert.equal(count(".stale-help"), 1);
+    assert.ok(query(".stale-help").innerText.includes("foo"));
+
+    await visit("/");
+    await visit("/review"); // reload review
+
+    assert.equal(count(".stale-help"), 0);
   });
 });
diff --git a/app/jobs/regular/notify_reviewable.rb b/app/jobs/regular/notify_reviewable.rb
index 3205129..9c3e729 100644
--- a/app/jobs/regular/notify_reviewable.rb
+++ b/app/jobs/regular/notify_reviewable.rb
@@ -19,7 +19,10 @@ class Jobs::NotifyReviewable < ::Jobs::Base
 
     if args[:updated_reviewable_ids].present?
       Reviewable.where(id: args[:updated_reviewable_ids]).each do |r|
-        payload = { status: r.status }
+        payload = {
+          last_performing_username: args[:performing_username],
+          status: r.status
+        }
 
         all_updates[:admins][r.id] = payload
         all_updates[:moderators][r.id] = payload if r.reviewable_by_moderator?
diff --git a/app/models/reviewable.rb b/app/models/reviewable.rb
index e8998a1..bff1c63 100644
--- a/app/models/reviewable.rb
+++ b/app/models/reviewable.rb
@@ -371,7 +371,8 @@ class Reviewable < ActiveRecord::Base
       Jobs.enqueue(
         :notify_reviewable,
         reviewable_id: self.id,
-        updated_reviewable_ids: result.remove_reviewable_ids,
+        performing_username: performed_by.username,
+        updated_reviewable_ids: result.remove_reviewable_ids
       )
     end
 
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 8148481..96af2e7 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -426,7 +426,7 @@ en:
         type_bonus:
           name: "type bonus"
           title: "Certain reviewable types can be assigned a bonus by staff to make them a higher priority."
-      stale_help: "This reviewable has been resolved by someone else."
+      stale_help: "This reviewable has been resolved by <b>%{username}</b>."
       claim_help:
         optional: "You can claim this item to prevent others from reviewing it."
         required: "You must claim items before you can review them."

GitHub sha: 079d2af55fbb45b34b1c8ed5b82061d525266b17

This commit appears in #13750 which was approved by eviltrout and ZogStriP. It was merged by udan11.