mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 11:02:46 +08:00
FEATURE: add support for "Flagged By" filter in reviewable (#30197)
Previous to this change there was no way to find all the flags a user raised. New filter allows you to find all the flags raised by a user.
This commit is contained in:
parent
cd8e03086f
commit
58e3e0cc4f
|
@ -19,6 +19,7 @@ export default class ReviewIndexController extends Controller {
|
|||
"to_date",
|
||||
"sort_order",
|
||||
"additional_filters",
|
||||
"flagged_by",
|
||||
];
|
||||
|
||||
type = null;
|
||||
|
@ -30,6 +31,7 @@ export default class ReviewIndexController extends Controller {
|
|||
filtersExpanded = this.site.desktopView;
|
||||
username = "";
|
||||
reviewed_by = "";
|
||||
flagged_by = "";
|
||||
from_date = null;
|
||||
to_date = null;
|
||||
sort_order = null;
|
||||
|
@ -161,6 +163,7 @@ export default class ReviewIndexController extends Controller {
|
|||
category_id: this.filterCategoryId,
|
||||
username: this.filterUsername,
|
||||
reviewed_by: this.filterReviewedBy,
|
||||
flagged_by: this.filterFlaggedBy,
|
||||
from_date: isPresent(this.filterFromDate)
|
||||
? this.filterFromDate.toISOString(true).split("T")[0]
|
||||
: null,
|
||||
|
@ -189,6 +192,11 @@ export default class ReviewIndexController extends Controller {
|
|||
this.set("filterReviewedBy", selected.firstObject);
|
||||
}
|
||||
|
||||
@action
|
||||
updateFilterFlaggedBy(selected) {
|
||||
this.set("filterFlaggedBy", selected.firstObject);
|
||||
}
|
||||
|
||||
@action
|
||||
updateFilterUsername(selected) {
|
||||
this.set("filterUsername", selected.firstObject);
|
||||
|
|
|
@ -41,6 +41,7 @@ export default class ReviewIndex extends DiscourseRoute {
|
|||
reviewableTypes: meta.reviewable_types,
|
||||
filterUsername: meta.username,
|
||||
filterReviewedBy: meta.reviewed_by,
|
||||
filterFlaggedBy: meta.flagged_by,
|
||||
filterFromDate: isPresent(meta.from_date) ? moment(meta.from_date) : null,
|
||||
filterToDate: isPresent(meta.to_date) ? moment(meta.to_date) : null,
|
||||
filterSortOrder: meta.sort_order,
|
||||
|
|
|
@ -75,6 +75,21 @@
|
|||
/>
|
||||
</div>
|
||||
|
||||
<div class="reviewable-filter topic-filter">
|
||||
<label class="filter-label">
|
||||
{{i18n "review.filtered_flagged_by"}}
|
||||
</label>
|
||||
<EmailGroupUserChooser
|
||||
@value={{this.filterFlaggedBy}}
|
||||
@onChange={{action "updateFilterFlaggedBy"}}
|
||||
@options={{hash
|
||||
maximum=1
|
||||
excludeCurrentUser=false
|
||||
fullWidthWrap=true
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="reviewable-filter topic-filter">
|
||||
<label class="filter-label">
|
||||
{{i18n "review.filtered_reviewed_by"}}
|
||||
|
|
|
@ -32,9 +32,16 @@ class ReviewablesController < ApplicationController
|
|||
additional_filters: additional_filters.reject { |_, v| v.blank? },
|
||||
}
|
||||
|
||||
%i[priority username reviewed_by from_date to_date type sort_order].each do |filter_key|
|
||||
filters[filter_key] = params[filter_key]
|
||||
end
|
||||
%i[
|
||||
priority
|
||||
username
|
||||
reviewed_by
|
||||
from_date
|
||||
to_date
|
||||
type
|
||||
sort_order
|
||||
flagged_by
|
||||
].each { |filter_key| filters[filter_key] = params[filter_key] }
|
||||
|
||||
total_rows = Reviewable.list_for(current_user, **filters).count
|
||||
reviewables =
|
||||
|
|
|
@ -448,7 +448,8 @@ class Reviewable < ActiveRecord::Base
|
|||
to_date: nil,
|
||||
additional_filters: {},
|
||||
preload: true,
|
||||
include_claimed_by_others: true
|
||||
include_claimed_by_others: true,
|
||||
flagged_by: nil
|
||||
)
|
||||
order =
|
||||
case sort_order
|
||||
|
@ -466,19 +467,28 @@ class Reviewable < ActiveRecord::Base
|
|||
user_id = User.find_by_username(username)&.id
|
||||
return none if user_id.blank?
|
||||
end
|
||||
|
||||
return none if user.blank?
|
||||
result = viewable_by(user, order: order, preload: preload)
|
||||
|
||||
result = viewable_by(user, order: order, preload: preload)
|
||||
result = by_status(result, status)
|
||||
result = result.where(id: ids) if ids
|
||||
|
||||
result = result.where("reviewables.type = ?", Reviewable.sti_class_for(type).sti_name) if type
|
||||
result = result.where("reviewables.category_id = ?", category_id) if category_id
|
||||
result = result.where("reviewables.topic_id = ?", topic_id) if topic_id
|
||||
result = result.where("reviewables.created_at >= ?", from_date) if from_date
|
||||
result = result.where("reviewables.created_at <= ?", to_date) if to_date
|
||||
|
||||
if flagged_by
|
||||
flagged_by_id = User.find_by_username(flagged_by)&.id
|
||||
return none if flagged_by_id.nil?
|
||||
result = result.where(<<~SQL, flagged_by_id: flagged_by_id)
|
||||
EXISTS(
|
||||
SELECT 1 FROM reviewable_scores
|
||||
WHERE reviewable_scores.reviewable_id = reviewables.id AND reviewable_scores.user_id = :flagged_by_id
|
||||
)
|
||||
SQL
|
||||
end
|
||||
|
||||
if reviewed_by
|
||||
reviewed_by_id = User.find_by_username(reviewed_by)&.id
|
||||
return none if reviewed_by_id.nil?
|
||||
|
|
|
@ -573,6 +573,7 @@ en:
|
|||
order_by: "Order by"
|
||||
date_filter: "Posted between"
|
||||
in_reply_to: "in reply to"
|
||||
filtered_flagged_by: "Flagged by"
|
||||
explain:
|
||||
why: "explain why this item ended up in the queue"
|
||||
title: "Reviewable Scoring"
|
||||
|
|
|
@ -75,6 +75,31 @@ RSpec.describe ReviewablesController do
|
|||
expect(json["meta"]["status"]).to eq("pending")
|
||||
end
|
||||
|
||||
it "supports filtering by flagged_by" do
|
||||
# this is not flagged by the user
|
||||
reviewable = Fabricate(:reviewable)
|
||||
reviewable.reviewable_scores.create!(
|
||||
user: admin,
|
||||
score: 1000,
|
||||
status: "pending",
|
||||
reviewable_score_type: 1,
|
||||
)
|
||||
|
||||
reviewable = Fabricate(:reviewable)
|
||||
user = Fabricate(:user)
|
||||
reviewable.reviewable_scores.create!(
|
||||
user: user,
|
||||
score: 1000,
|
||||
status: "pending",
|
||||
reviewable_score_type: 1,
|
||||
)
|
||||
|
||||
get "/review.json?flagged_by=#{user.username}"
|
||||
expect(response.code).to eq("200")
|
||||
json = response.parsed_body
|
||||
expect(json["reviewables"].length).to eq(1)
|
||||
end
|
||||
|
||||
it "supports filtering by score" do
|
||||
get "/review.json?min_score=1000"
|
||||
expect(response.code).to eq("200")
|
||||
|
@ -216,7 +241,7 @@ RSpec.describe ReviewablesController do
|
|||
let(:reviewables) { response.parsed_body["reviewables"] }
|
||||
|
||||
it "returns an empty array when no reviewable matches the date range" do
|
||||
reviewable = Fabricate(:reviewable)
|
||||
Fabricate(:reviewable)
|
||||
|
||||
get "/review.json?from_date=#{from}&to_date=#{to}"
|
||||
|
||||
|
@ -269,7 +294,7 @@ RSpec.describe ReviewablesController do
|
|||
|
||||
it "supports filtering by id" do
|
||||
reviewable_a = Fabricate(:reviewable)
|
||||
reviewable_b = Fabricate(:reviewable)
|
||||
_reviewable_b = Fabricate(:reviewable)
|
||||
|
||||
get "/review.json?ids[]=#{reviewable_a.id}"
|
||||
|
||||
|
@ -323,7 +348,7 @@ RSpec.describe ReviewablesController do
|
|||
end
|
||||
|
||||
it "responds with current user's reviewables count" do
|
||||
reviewable = Fabricate(:reviewable)
|
||||
_reviewable = Fabricate(:reviewable)
|
||||
|
||||
get "/review/user-menu-list.json"
|
||||
|
||||
|
@ -497,7 +522,7 @@ RSpec.describe ReviewablesController do
|
|||
end
|
||||
|
||||
it "doesn't send email when `send_email` is false" do
|
||||
other_reviewable = Fabricate(:reviewable)
|
||||
_other_reviewable = Fabricate(:reviewable)
|
||||
|
||||
SiteSetting.must_approve_users = true
|
||||
put "/review/#{reviewable.id}/perform/approve_user.json?version=#{reviewable.version}&send_email=false"
|
||||
|
|
Loading…
Reference in New Issue
Block a user