mirror of https://github.com/tootsuite/mastodon
Add `reviewed` and `unreviewed` scopes to `Reviewable` model concern (#31988)
parent
c922af2737
commit
04a939d640
|
@ -3,6 +3,11 @@
|
||||||
module Reviewable
|
module Reviewable
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
included do
|
||||||
|
scope :reviewed, -> { where.not(reviewed_at: nil) }
|
||||||
|
scope :unreviewed, -> { where(reviewed_at: nil) }
|
||||||
|
end
|
||||||
|
|
||||||
def requires_review?
|
def requires_review?
|
||||||
reviewed_at.nil?
|
reviewed_at.nil?
|
||||||
end
|
end
|
||||||
|
|
|
@ -34,8 +34,6 @@ class PreviewCardProvider < ApplicationRecord
|
||||||
|
|
||||||
scope :trendable, -> { where(trendable: true) }
|
scope :trendable, -> { where(trendable: true) }
|
||||||
scope :not_trendable, -> { where(trendable: false) }
|
scope :not_trendable, -> { where(trendable: false) }
|
||||||
scope :reviewed, -> { where.not(reviewed_at: nil) }
|
|
||||||
scope :pending_review, -> { where(reviewed_at: nil) }
|
|
||||||
|
|
||||||
def self.matching_domain(domain)
|
def self.matching_domain(domain)
|
||||||
segments = domain.split('.')
|
segments = domain.split('.')
|
||||||
|
|
|
@ -50,8 +50,6 @@ class Tag < ApplicationRecord
|
||||||
validate :validate_name_change, if: -> { !new_record? && name_changed? }
|
validate :validate_name_change, if: -> { !new_record? && name_changed? }
|
||||||
validate :validate_display_name_change, if: -> { !new_record? && display_name_changed? }
|
validate :validate_display_name_change, if: -> { !new_record? && display_name_changed? }
|
||||||
|
|
||||||
scope :reviewed, -> { where.not(reviewed_at: nil) }
|
|
||||||
scope :unreviewed, -> { where(reviewed_at: nil) }
|
|
||||||
scope :pending_review, -> { unreviewed.where.not(requested_review_at: nil) }
|
scope :pending_review, -> { unreviewed.where.not(requested_review_at: nil) }
|
||||||
scope :usable, -> { where(usable: [true, nil]) }
|
scope :usable, -> { where(usable: [true, nil]) }
|
||||||
scope :not_usable, -> { where(usable: false) }
|
scope :not_usable, -> { where(usable: false) }
|
||||||
|
@ -127,7 +125,7 @@ class Tag < ApplicationRecord
|
||||||
|
|
||||||
query = Tag.matches_name(stripped_term)
|
query = Tag.matches_name(stripped_term)
|
||||||
query = query.merge(Tag.listable) if options[:exclude_unlistable]
|
query = query.merge(Tag.listable) if options[:exclude_unlistable]
|
||||||
query = query.merge(matching_name(stripped_term).or(where.not(reviewed_at: nil))) if options[:exclude_unreviewed]
|
query = query.merge(matching_name(stripped_term).or(reviewed)) if options[:exclude_unreviewed]
|
||||||
|
|
||||||
query.order(Arel.sql('length(name) ASC, name ASC'))
|
query.order(Arel.sql('length(name) ASC, name ASC'))
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
|
|
|
@ -41,7 +41,7 @@ class Trends::PreviewCardProviderFilter
|
||||||
when 'rejected'
|
when 'rejected'
|
||||||
PreviewCardProvider.not_trendable
|
PreviewCardProvider.not_trendable
|
||||||
when 'pending_review'
|
when 'pending_review'
|
||||||
PreviewCardProvider.pending_review
|
PreviewCardProvider.unreviewed
|
||||||
else
|
else
|
||||||
raise Mastodon::InvalidParameterError, "Unknown status: #{value}"
|
raise Mastodon::InvalidParameterError, "Unknown status: #{value}"
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
%li= filter_link_to t('generic.all'), status: nil
|
%li= filter_link_to t('generic.all'), status: nil
|
||||||
%li= filter_link_to t('admin.trends.approved'), status: 'approved'
|
%li= filter_link_to t('admin.trends.approved'), status: 'approved'
|
||||||
%li= filter_link_to t('admin.trends.rejected'), status: 'rejected'
|
%li= filter_link_to t('admin.trends.rejected'), status: 'rejected'
|
||||||
%li= filter_link_to safe_join([t('admin.accounts.moderation.pending'), "(#{PreviewCardProvider.pending_review.count})"], ' '), status: 'pending_review'
|
%li= filter_link_to safe_join([t('admin.accounts.moderation.pending'), "(#{PreviewCardProvider.unreviewed.count})"], ' '), status: 'pending_review'
|
||||||
.back-link
|
.back-link
|
||||||
= link_to admin_trends_links_path do
|
= link_to admin_trends_links_path do
|
||||||
= material_symbol 'chevron_left'
|
= material_symbol 'chevron_left'
|
||||||
|
|
|
@ -24,21 +24,5 @@ RSpec.describe PreviewCardProvider do
|
||||||
expect(results).to eq([not_trendable_and_not_reviewed])
|
expect(results).to eq([not_trendable_and_not_reviewed])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'reviewed' do
|
|
||||||
it 'returns the relevant records' do
|
|
||||||
results = described_class.reviewed
|
|
||||||
|
|
||||||
expect(results).to eq([trendable_and_reviewed])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'pending_review' do
|
|
||||||
it 'returns the relevant records' do
|
|
||||||
results = described_class.pending_review
|
|
||||||
|
|
||||||
expect(results).to eq([not_trendable_and_not_reviewed])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,6 +6,31 @@ RSpec.shared_examples 'Reviewable' do
|
||||||
let(:reviewed_at) { nil }
|
let(:reviewed_at) { nil }
|
||||||
let(:requested_review_at) { nil }
|
let(:requested_review_at) { nil }
|
||||||
|
|
||||||
|
describe 'Scopes' do
|
||||||
|
let!(:reviewed_record) { Fabricate factory_name, reviewed_at: 10.days.ago }
|
||||||
|
let!(:un_reviewed_record) { Fabricate factory_name, reviewed_at: nil }
|
||||||
|
|
||||||
|
describe '.reviewed' do
|
||||||
|
it 'returns reviewed records' do
|
||||||
|
expect(described_class.reviewed)
|
||||||
|
.to include(reviewed_record)
|
||||||
|
.and not_include(un_reviewed_record)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '.unreviewed' do
|
||||||
|
it 'returns non reviewed records' do
|
||||||
|
expect(described_class.unreviewed)
|
||||||
|
.to include(un_reviewed_record)
|
||||||
|
.and not_include(reviewed_record)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def factory_name
|
||||||
|
described_class.name.underscore.to_sym
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe '#requires_review?' do
|
describe '#requires_review?' do
|
||||||
it { is_expected.to be_requires_review }
|
it { is_expected.to be_requires_review }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue