FEATURE: Reviewed by filter. (#11405)
New reviewable filter to only display reviewables handled by a specific user.
This commit is contained in:
parent
477538bf2d
commit
4d9686c494
|
@ -11,6 +11,7 @@ export default Controller.extend({
|
|||
"category_id",
|
||||
"topic_id",
|
||||
"username",
|
||||
"reviewed_by",
|
||||
"from_date",
|
||||
"to_date",
|
||||
"sort_order",
|
||||
|
@ -24,6 +25,7 @@ export default Controller.extend({
|
|||
topic_id: null,
|
||||
filtersExpanded: false,
|
||||
username: "",
|
||||
reviewed_by: "",
|
||||
from_date: null,
|
||||
to_date: null,
|
||||
sort_order: null,
|
||||
|
@ -147,6 +149,7 @@ export default Controller.extend({
|
|||
status: this.filterStatus,
|
||||
category_id: this.filterCategoryId,
|
||||
username: this.filterUsername,
|
||||
reviewed_by: this.filterReviewedBy,
|
||||
from_date: isPresent(this.filterFromDate)
|
||||
? this.filterFromDate.toISOString(true).split("T")[0]
|
||||
: null,
|
||||
|
|
|
@ -32,6 +32,7 @@ export default DiscourseRoute.extend({
|
|||
filterPriority: meta.priority,
|
||||
reviewableTypes: meta.reviewable_types,
|
||||
filterUsername: meta.username,
|
||||
filterReviewedBy: meta.reviewed_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,
|
||||
|
|
|
@ -58,6 +58,17 @@
|
|||
}}
|
||||
</div>
|
||||
|
||||
<div class="reviewable-filter topic-filter">
|
||||
{{i18n "review.filtered_reviewed_by"}}
|
||||
{{user-selector
|
||||
excludeCurrentUser=false
|
||||
usernames=filterReviewedBy
|
||||
fullWidthWrap=true
|
||||
single=true
|
||||
class="user-selector"
|
||||
canReceiveUpdates=true}}
|
||||
</div>
|
||||
|
||||
<div class="reviewable-filter topic-filter">
|
||||
{{i18n "review.filtered_user"}}
|
||||
{{user-selector
|
||||
|
|
|
@ -30,7 +30,7 @@ class ReviewablesController < ApplicationController
|
|||
additional_filters: additional_filters.reject { |_, v| v.blank? }
|
||||
}
|
||||
|
||||
%i[priority username from_date to_date type sort_order].each do |filter_key|
|
||||
%i[priority username reviewed_by from_date to_date type sort_order].each do |filter_key|
|
||||
filters[filter_key] = params[filter_key]
|
||||
end
|
||||
|
||||
|
|
|
@ -437,6 +437,7 @@ class Reviewable < ActiveRecord::Base
|
|||
offset: nil,
|
||||
priority: nil,
|
||||
username: nil,
|
||||
reviewed_by: nil,
|
||||
sort_order: nil,
|
||||
from_date: nil,
|
||||
to_date: nil,
|
||||
|
@ -470,6 +471,21 @@ class Reviewable < ActiveRecord::Base
|
|||
result = result.where("reviewables.created_at >= ?", from_date) if from_date
|
||||
result = result.where("reviewables.created_at <= ?", to_date) if to_date
|
||||
|
||||
if reviewed_by
|
||||
reviewed_by_id = User.find_by_username(reviewed_by)&.id
|
||||
return [] if reviewed_by_id.nil?
|
||||
|
||||
result = result.joins(<<~SQL
|
||||
INNER JOIN(
|
||||
SELECT reviewable_id
|
||||
FROM reviewable_histories
|
||||
WHERE reviewable_history_type = #{ReviewableHistory.types[:transitioned]} AND
|
||||
status <> #{Reviewable.statuses[:pending]} AND created_by_id = #{reviewed_by_id}
|
||||
) AS rh ON rh.reviewable_id = reviewables.id
|
||||
SQL
|
||||
)
|
||||
end
|
||||
|
||||
if min_score > 0 && status == :pending
|
||||
result = result.where("reviewables.score >= ? OR reviewables.force_review", min_score)
|
||||
elsif min_score > 0
|
||||
|
|
|
@ -457,6 +457,7 @@ en:
|
|||
topic: "Topic:"
|
||||
filtered_topic: "You have filtered to reviewable content in a single topic."
|
||||
filtered_user: "User"
|
||||
filtered_reviewed_by: "Reviewed By"
|
||||
show_all_topics: "show all topics"
|
||||
deleted_post: "(post deleted)"
|
||||
deleted_user: "(user deleted)"
|
||||
|
|
|
@ -149,6 +149,18 @@ RSpec.describe Reviewable, type: :model do
|
|||
expect(reviewables).not_to include(qp)
|
||||
end
|
||||
|
||||
it 'can filter by who reviewed the flag' do
|
||||
reviewable = Fabricate(:reviewable_flagged_post)
|
||||
admin = Fabricate(:admin)
|
||||
reviewable.perform(admin, :ignore)
|
||||
|
||||
reviewables = Reviewable.list_for(
|
||||
user, status: :all, reviewed_by: admin.username
|
||||
)
|
||||
|
||||
expect(reviewables).to contain_exactly(reviewable)
|
||||
end
|
||||
|
||||
it 'Does not filter by status when status parameter is set to all' do
|
||||
rejected_reviewable = Fabricate(:reviewable, target: post, status: Reviewable.statuses[:rejected])
|
||||
reviewables = Reviewable.list_for(user, status: :all)
|
||||
|
|
Loading…
Reference in New Issue