diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/account.rb | 4 | ||||
-rw-r--r-- | app/models/account_filter.rb | 2 | ||||
-rw-r--r-- | app/models/concerns/attachmentable.rb | 5 | ||||
-rw-r--r-- | app/models/preview_card_provider.rb | 1 | ||||
-rw-r--r-- | app/models/report_note.rb | 2 | ||||
-rw-r--r-- | app/models/status.rb | 48 | ||||
-rw-r--r-- | app/models/tag.rb | 4 |
7 files changed, 36 insertions, 30 deletions
diff --git a/app/models/account.rb b/app/models/account.rb index 4fc7b9d08..215f8ce09 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -411,10 +411,8 @@ class Account < ApplicationRecord DISALLOWED_TSQUERY_CHARACTERS = /['?\\:‘’]/.freeze TEXTSEARCH = "(setweight(to_tsvector('simple', accounts.display_name), 'A') || setweight(to_tsvector('simple', accounts.username), 'B') || setweight(to_tsvector('simple', coalesce(accounts.domain, '')), 'C'))" - REPUTATION_SCORE_FUNCTION = '(greatest(0, coalesce(s.followers_count, 0)) / (greatest(0, coalesce(s.following_count, 0)) + 1.0))' - FOLLOWERS_SCORE_FUNCTION = 'log(greatest(0, coalesce(s.followers_count, 0)) + 2)' TIME_DISTANCE_FUNCTION = '(case when s.last_status_at is null then 0 else exp(-1.0 * ((greatest(0, abs(extract(DAY FROM age(s.last_status_at))) - 30.0)^2) / (2.0 * ((-1.0 * 30^2) / (2.0 * ln(0.3)))))) end)' - BOOST = "((#{REPUTATION_SCORE_FUNCTION} + #{FOLLOWERS_SCORE_FUNCTION} + #{TIME_DISTANCE_FUNCTION}) / 3.0)" + BOOST = "(#{TIME_DISTANCE_FUNCTION})" def readonly_attributes super - %w(statuses_count following_count followers_count) diff --git a/app/models/account_filter.rb b/app/models/account_filter.rb index 1666ea883..55d34e85c 100644 --- a/app/models/account_filter.rb +++ b/app/models/account_filter.rb @@ -55,7 +55,7 @@ class AccountFilter when 'by_domain' Account.where(domain: value.to_s.strip) when 'username' - Account.matches_username(value.to_s.strip) + Account.matches_username(value.to_s.strip.delete_prefix('@')) when 'display_name' Account.matches_display_name(value.to_s.strip) when 'email' diff --git a/app/models/concerns/attachmentable.rb b/app/models/concerns/attachmentable.rb index d44c22438..28591ab72 100644 --- a/app/models/concerns/attachmentable.rb +++ b/app/models/concerns/attachmentable.rb @@ -22,15 +22,14 @@ module Attachmentable included do def self.has_attached_file(name, options = {}) # rubocop:disable Naming/PredicateName - options = { validate_media_type: false }.merge(options) super(name, options) - send(:"before_#{name}_post_process") do + + send(:"before_#{name}_validate") do attachment = send(name) check_image_dimension(attachment) set_file_content_type(attachment) obfuscate_file_name(attachment) set_file_extension(attachment) - Paperclip::Validators::MediaTypeSpoofDetectionValidator.new(attributes: [name]).validate(self) end end end diff --git a/app/models/preview_card_provider.rb b/app/models/preview_card_provider.rb index 1dd95fc91..9f5f6d3cb 100644 --- a/app/models/preview_card_provider.rb +++ b/app/models/preview_card_provider.rb @@ -18,6 +18,7 @@ # class PreviewCardProvider < ApplicationRecord + include Paginable include DomainNormalizable include Attachmentable diff --git a/app/models/report_note.rb b/app/models/report_note.rb index 74b46027e..8307badd6 100644 --- a/app/models/report_note.rb +++ b/app/models/report_note.rb @@ -18,5 +18,5 @@ class ReportNote < ApplicationRecord scope :latest, -> { reorder(created_at: :desc) } - validates :content, presence: true, length: { maximum: 500 } + validates :content, presence: true, length: { maximum: 2000 } end diff --git a/app/models/status.rb b/app/models/status.rb index 8a58e5d68..863e1a56b 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -442,33 +442,41 @@ class Status < ApplicationRecord super || build_status_stat end - # Hack to use a "INSERT INTO ... SELECT ..." query instead of "INSERT INTO ... VALUES ..." query + # This is a hack to ensure that no reblogs of discarded statuses are created, + # as this cannot be enforced through database constraints the same way we do + # for reblogs of deleted statuses. + # + # To achieve this, we redefine the internal method responsible for issuing + # the "INSERT" statement and replace the "INSERT INTO ... VALUES ..." query + # with an "INSERT INTO ... SELECT ..." query with a "WHERE deleted_at IS NULL" + # clause on the reblogged status to ensure consistency at the database level. + # + # Otherwise, the code is kept as close as possible to ActiveRecord::Persistence + # code, and actually calls it if we are not handling a reblog. def self._insert_record(values) - if values.is_a?(Hash) && values['reblog_of_id'].present? - primary_key = self.primary_key - primary_key_value = nil + return super unless values.is_a?(Hash) && values['reblog_of_id'].present? - if primary_key - primary_key_value = values[primary_key] + primary_key = self.primary_key + primary_key_value = nil - if !primary_key_value && prefetch_primary_key? - primary_key_value = next_sequence_value - values[primary_key] = primary_key_value - end + if primary_key + primary_key_value = values[primary_key] + + if !primary_key_value && prefetch_primary_key? + primary_key_value = next_sequence_value + values[primary_key] = primary_key_value end + end - # The following line is where we differ from stock ActiveRecord implementation - im = _compile_reblog_insert(values) + # The following line is where we differ from stock ActiveRecord implementation + im = _compile_reblog_insert(values) - # Since we are using SELECT instead of VALUES, a non-error `nil` return is possible. - # For our purposes, it's equivalent to a foreign key constraint violation - result = connection.insert(im, "#{self} Create", primary_key || false, primary_key_value) - raise ActiveRecord::InvalidForeignKey, "(reblog_of_id)=(#{values['reblog_of_id']}) is not present in table \"statuses\"" if result.nil? + # Since we are using SELECT instead of VALUES, a non-error `nil` return is possible. + # For our purposes, it's equivalent to a foreign key constraint violation + result = connection.insert(im, "#{self} Create", primary_key || false, primary_key_value) + raise ActiveRecord::InvalidForeignKey, "(reblog_of_id)=(#{values['reblog_of_id']}) is not present in table \"statuses\"" if result.nil? - result - else - super - end + result end def self._compile_reblog_insert(values) diff --git a/app/models/tag.rb b/app/models/tag.rb index 554a92d90..9fb32cd06 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -31,8 +31,8 @@ class Tag < ApplicationRecord HASHTAG_FIRST_SEQUENCE_CHUNK_ONE = "[[:word:]_][[:word:]#{HASHTAG_SEPARATORS}]*[[:alpha:]#{HASHTAG_SEPARATORS}]" HASHTAG_FIRST_SEQUENCE_CHUNK_TWO = "[[:word:]#{HASHTAG_SEPARATORS}]*[[:word:]_]" HASHTAG_FIRST_SEQUENCE = "(#{HASHTAG_FIRST_SEQUENCE_CHUNK_ONE}#{HASHTAG_FIRST_SEQUENCE_CHUNK_TWO})" - HASTAG_LAST_SEQUENCE = '([[:word:]_]*[[:alpha:]][[:word:]_]*)' - HASHTAG_NAME_PAT = "#{HASHTAG_FIRST_SEQUENCE}|#{HASTAG_LAST_SEQUENCE}" + HASHTAG_LAST_SEQUENCE = '([[:word:]_]*[[:alpha:]][[:word:]_]*)' + HASHTAG_NAME_PAT = "#{HASHTAG_FIRST_SEQUENCE}|#{HASHTAG_LAST_SEQUENCE}" HASHTAG_RE = /(?:^|[^\/\)\w])#(#{HASHTAG_NAME_PAT})/i HASHTAG_NAME_RE = /\A(#{HASHTAG_NAME_PAT})\z/i |