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.
This commit is contained in:
Dan Ungureanu 2021-07-16 19:57:12 +03:00 committed by GitHub
parent 9b15affaae
commit 079d2af55f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 21 additions and 10 deletions

View File

@ -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`;
}

View File

@ -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);
}
});
}

View File

@ -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">

View File

@ -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);
});
});

View File

@ -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?

View File

@ -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

View File

@ -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."