mirror of
https://github.com/glitch-soc/mastodon.git
synced 2024-11-27 02:24:03 -05:00
Add Reviewable
model concern (#31152)
This commit is contained in:
parent
2f0d0fc127
commit
7c26e5e4a1
@ -89,6 +89,7 @@ class Account < ApplicationRecord
|
|||||||
include DomainMaterializable
|
include DomainMaterializable
|
||||||
include DomainNormalizable
|
include DomainNormalizable
|
||||||
include Paginable
|
include Paginable
|
||||||
|
include Reviewable
|
||||||
|
|
||||||
enum :protocol, { ostatus: 0, activitypub: 1 }
|
enum :protocol, { ostatus: 0, activitypub: 1 }
|
||||||
enum :suspension_origin, { local: 0, remote: 1 }, prefix: true
|
enum :suspension_origin, { local: 0, remote: 1 }, prefix: true
|
||||||
@ -426,22 +427,6 @@ class Account < ApplicationRecord
|
|||||||
@synchronization_uri_prefix ||= "#{uri[URL_PREFIX_RE]}/"
|
@synchronization_uri_prefix ||= "#{uri[URL_PREFIX_RE]}/"
|
||||||
end
|
end
|
||||||
|
|
||||||
def requires_review?
|
|
||||||
reviewed_at.nil?
|
|
||||||
end
|
|
||||||
|
|
||||||
def reviewed?
|
|
||||||
reviewed_at.present?
|
|
||||||
end
|
|
||||||
|
|
||||||
def requested_review?
|
|
||||||
requested_review_at.present?
|
|
||||||
end
|
|
||||||
|
|
||||||
def requires_review_notification?
|
|
||||||
requires_review? && !requested_review?
|
|
||||||
end
|
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def readonly_attributes
|
def readonly_attributes
|
||||||
super - %w(statuses_count following_count followers_count)
|
super - %w(statuses_count following_count followers_count)
|
||||||
|
21
app/models/concerns/reviewable.rb
Normal file
21
app/models/concerns/reviewable.rb
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Reviewable
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
def requires_review?
|
||||||
|
reviewed_at.nil?
|
||||||
|
end
|
||||||
|
|
||||||
|
def reviewed?
|
||||||
|
reviewed_at.present?
|
||||||
|
end
|
||||||
|
|
||||||
|
def requested_review?
|
||||||
|
requested_review_at.present?
|
||||||
|
end
|
||||||
|
|
||||||
|
def requires_review_notification?
|
||||||
|
requires_review? && !requested_review?
|
||||||
|
end
|
||||||
|
end
|
@ -21,6 +21,7 @@ class PreviewCardProvider < ApplicationRecord
|
|||||||
include Paginable
|
include Paginable
|
||||||
include DomainNormalizable
|
include DomainNormalizable
|
||||||
include Attachmentable
|
include Attachmentable
|
||||||
|
include Reviewable
|
||||||
|
|
||||||
ICON_MIME_TYPES = %w(image/x-icon image/vnd.microsoft.icon image/png).freeze
|
ICON_MIME_TYPES = %w(image/x-icon image/vnd.microsoft.icon image/png).freeze
|
||||||
LIMIT = 1.megabyte
|
LIMIT = 1.megabyte
|
||||||
@ -36,22 +37,6 @@ class PreviewCardProvider < ApplicationRecord
|
|||||||
scope :reviewed, -> { where.not(reviewed_at: nil) }
|
scope :reviewed, -> { where.not(reviewed_at: nil) }
|
||||||
scope :pending_review, -> { where(reviewed_at: nil) }
|
scope :pending_review, -> { where(reviewed_at: nil) }
|
||||||
|
|
||||||
def requires_review?
|
|
||||||
reviewed_at.nil?
|
|
||||||
end
|
|
||||||
|
|
||||||
def reviewed?
|
|
||||||
reviewed_at.present?
|
|
||||||
end
|
|
||||||
|
|
||||||
def requested_review?
|
|
||||||
requested_review_at.present?
|
|
||||||
end
|
|
||||||
|
|
||||||
def requires_review_notification?
|
|
||||||
requires_review? && !requested_review?
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.matching_domain(domain)
|
def self.matching_domain(domain)
|
||||||
segments = domain.split('.')
|
segments = domain.split('.')
|
||||||
where(domain: segments.map.with_index { |_, i| segments[i..].join('.') }).by_domain_length.first
|
where(domain: segments.map.with_index { |_, i| segments[i..].join('.') }).by_domain_length.first
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
class Tag < ApplicationRecord
|
class Tag < ApplicationRecord
|
||||||
include Paginable
|
include Paginable
|
||||||
|
include Reviewable
|
||||||
|
|
||||||
# rubocop:disable Rails/HasAndBelongsToMany
|
# rubocop:disable Rails/HasAndBelongsToMany
|
||||||
has_and_belongs_to_many :statuses
|
has_and_belongs_to_many :statuses
|
||||||
has_and_belongs_to_many :accounts
|
has_and_belongs_to_many :accounts
|
||||||
@ -97,22 +99,6 @@ class Tag < ApplicationRecord
|
|||||||
|
|
||||||
alias trendable? trendable
|
alias trendable? trendable
|
||||||
|
|
||||||
def requires_review?
|
|
||||||
reviewed_at.nil?
|
|
||||||
end
|
|
||||||
|
|
||||||
def reviewed?
|
|
||||||
reviewed_at.present?
|
|
||||||
end
|
|
||||||
|
|
||||||
def requested_review?
|
|
||||||
requested_review_at.present?
|
|
||||||
end
|
|
||||||
|
|
||||||
def requires_review_notification?
|
|
||||||
requires_review? && !requested_review?
|
|
||||||
end
|
|
||||||
|
|
||||||
def decaying?
|
def decaying?
|
||||||
max_score_at && max_score_at >= Trends.tags.options[:max_score_cooldown].ago && max_score_at < 1.day.ago
|
max_score_at && max_score_at >= Trends.tags.options[:max_score_cooldown].ago && max_score_at < 1.day.ago
|
||||||
end
|
end
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe Account do
|
RSpec.describe Account do
|
||||||
|
include_examples 'Reviewable'
|
||||||
|
|
||||||
context 'with an account record' do
|
context 'with an account record' do
|
||||||
subject { Fabricate(:account) }
|
subject { Fabricate(:account) }
|
||||||
|
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe PreviewCardProvider do
|
describe PreviewCardProvider do
|
||||||
|
include_examples 'Reviewable'
|
||||||
|
|
||||||
describe 'scopes' do
|
describe 'scopes' do
|
||||||
let(:trendable_and_reviewed) { Fabricate(:preview_card_provider, trendable: true, reviewed_at: 5.days.ago) }
|
let(:trendable_and_reviewed) { Fabricate(:preview_card_provider, trendable: true, reviewed_at: 5.days.ago) }
|
||||||
let(:not_trendable_and_not_reviewed) { Fabricate(:preview_card_provider, trendable: false, reviewed_at: nil) }
|
let(:not_trendable_and_not_reviewed) { Fabricate(:preview_card_provider, trendable: false, reviewed_at: nil) }
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe Tag do
|
RSpec.describe Tag do
|
||||||
|
include_examples 'Reviewable'
|
||||||
|
|
||||||
describe 'validations' do
|
describe 'validations' do
|
||||||
it 'invalid with #' do
|
it 'invalid with #' do
|
||||||
expect(described_class.new(name: '#hello_world')).to_not be_valid
|
expect(described_class.new(name: '#hello_world')).to_not be_valid
|
||||||
|
54
spec/support/examples/models/concerns/reviewable.rb
Normal file
54
spec/support/examples/models/concerns/reviewable.rb
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
shared_examples 'Reviewable' do
|
||||||
|
subject { described_class.new(reviewed_at: reviewed_at, requested_review_at: requested_review_at) }
|
||||||
|
|
||||||
|
let(:reviewed_at) { nil }
|
||||||
|
let(:requested_review_at) { nil }
|
||||||
|
|
||||||
|
describe '#requires_review?' do
|
||||||
|
it { is_expected.to be_requires_review }
|
||||||
|
|
||||||
|
context 'when reviewed_at is not null' do
|
||||||
|
let(:reviewed_at) { 5.days.ago }
|
||||||
|
|
||||||
|
it { is_expected.to_not be_requires_review }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#reviewed?' do
|
||||||
|
it { is_expected.to_not be_reviewed }
|
||||||
|
|
||||||
|
context 'when reviewed_at is not null' do
|
||||||
|
let(:reviewed_at) { 5.days.ago }
|
||||||
|
|
||||||
|
it { is_expected.to be_reviewed }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#requested_review?' do
|
||||||
|
it { is_expected.to_not be_requested_review }
|
||||||
|
|
||||||
|
context 'when requested_reviewed_at is not null' do
|
||||||
|
let(:requested_review_at) { 5.days.ago }
|
||||||
|
|
||||||
|
it { is_expected.to be_requested_review }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#requires_review_notification?' do
|
||||||
|
it { is_expected.to be_requires_review_notification }
|
||||||
|
|
||||||
|
context 'when reviewed_at is not null' do
|
||||||
|
let(:reviewed_at) { 5.days.ago }
|
||||||
|
|
||||||
|
it { is_expected.to_not be_requires_review_notification }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when requested_reviewed_at is not null' do
|
||||||
|
let(:requested_review_at) { 5.days.ago }
|
||||||
|
|
||||||
|
it { is_expected.to_not be_requires_review_notification }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user