diff options
author | Starfall <us@starfall.systems> | 2022-01-31 12:50:14 -0600 |
---|---|---|
committer | Starfall <us@starfall.systems> | 2022-01-31 12:50:14 -0600 |
commit | 17265f47f8f931e70699088dd8bd2a1c7b78112b (patch) | |
tree | a1dde2630cd8e481cc4c5d047c4af241a251def0 /app/models/concerns | |
parent | 129962006c2ebcd195561ac556887dc87d32081c (diff) | |
parent | d6f3261c6cb810ea4eb6f74b9ee62af0d94cbd52 (diff) |
Merge branch 'glitchsoc'
Diffstat (limited to 'app/models/concerns')
-rw-r--r-- | app/models/concerns/account_associations.rb | 8 | ||||
-rw-r--r-- | app/models/concerns/account_interactions.rb | 16 | ||||
-rw-r--r-- | app/models/concerns/account_merging.rb | 2 | ||||
-rw-r--r-- | app/models/concerns/attachmentable.rb | 61 |
4 files changed, 46 insertions, 41 deletions
diff --git a/app/models/concerns/account_associations.rb b/app/models/concerns/account_associations.rb index aaf371ebd..bbe269e8f 100644 --- a/app/models/concerns/account_associations.rb +++ b/app/models/concerns/account_associations.rb @@ -7,8 +7,7 @@ module AccountAssociations # Local users has_one :user, inverse_of: :account, dependent: :destroy - # Identity proofs - has_many :identity_proofs, class_name: 'AccountIdentityProof', dependent: :destroy, inverse_of: :account + # E2EE has_many :devices, dependent: :destroy, inverse_of: :account # Timelines @@ -43,7 +42,7 @@ module AccountAssociations has_many :account_moderation_notes, dependent: :destroy, inverse_of: :account has_many :targeted_moderation_notes, class_name: 'AccountModerationNote', foreign_key: :target_account_id, dependent: :destroy, inverse_of: :target_account has_many :account_warnings, dependent: :destroy, inverse_of: :account - has_many :targeted_account_warnings, class_name: 'AccountWarning', foreign_key: :target_account_id, dependent: :destroy, inverse_of: :target_account + has_many :strikes, class_name: 'AccountWarning', foreign_key: :target_account_id, dependent: :destroy, inverse_of: :target_account # Lists (that the account is on, not owned by the account) has_many :list_accounts, inverse_of: :account, dependent: :destroy @@ -66,5 +65,8 @@ module AccountAssociations # Follow recommendations has_one :follow_recommendation_suppression, inverse_of: :account, dependent: :destroy + + # Account statuses cleanup policy + has_one :statuses_cleanup_policy, class_name: 'AccountStatusesCleanupPolicy', inverse_of: :account, dependent: :destroy end end diff --git a/app/models/concerns/account_interactions.rb b/app/models/concerns/account_interactions.rb index 958f6c78e..ad1665dc4 100644 --- a/app/models/concerns/account_interactions.rb +++ b/app/models/concerns/account_interactions.rb @@ -81,6 +81,9 @@ module AccountInteractions has_many :following, -> { order('follows.id desc') }, through: :active_relationships, source: :target_account has_many :followers, -> { order('follows.id desc') }, through: :passive_relationships, source: :account + # Account notes + has_many :account_notes, dependent: :destroy + # Block relationships has_many :block_relationships, class_name: 'Block', foreign_key: 'account_id', dependent: :destroy has_many :blocking, -> { order('blocks.id desc') }, through: :block_relationships, source: :target_account @@ -192,6 +195,10 @@ module AccountInteractions !following_anyone? end + def followed_by?(other_account) + other_account.following?(self) + end + def blocking?(other_account) block_relationships.where(target_account: other_account).exists? end @@ -251,10 +258,13 @@ module AccountInteractions .where('users.current_sign_in_at > ?', User::ACTIVE_DURATION.ago) end - def remote_followers_hash(url_prefix) - Rails.cache.fetch("followers_hash:#{id}:#{url_prefix}") do + def remote_followers_hash(url) + url_prefix = url[Account::URL_PREFIX_RE] + return if url_prefix.blank? + + Rails.cache.fetch("followers_hash:#{id}:#{url_prefix}/") do digest = "\x00" * 32 - followers.where(Account.arel_table[:uri].matches(url_prefix + '%', false, true)).pluck_each(:uri) do |uri| + followers.where(Account.arel_table[:uri].matches("#{Account.sanitize_sql_like(url_prefix)}/%", false, true)).or(followers.where(uri: url_prefix)).pluck_each(:uri) do |uri| Xorcist.xor!(digest, Digest::SHA256.digest(uri)) end digest.unpack('H*')[0] diff --git a/app/models/concerns/account_merging.rb b/app/models/concerns/account_merging.rb index 8d37c6e56..119773e6b 100644 --- a/app/models/concerns/account_merging.rb +++ b/app/models/concerns/account_merging.rb @@ -13,7 +13,7 @@ module AccountMerging owned_classes = [ Status, StatusPin, MediaAttachment, Poll, Report, Tombstone, Favourite, - Follow, FollowRequest, Block, Mute, AccountIdentityProof, + Follow, FollowRequest, Block, Mute, AccountModerationNote, AccountPin, AccountStat, ListAccount, PollVote, Mention, AccountDeletionRequest, AccountNote, FollowRecommendationSuppression ] diff --git a/app/models/concerns/attachmentable.rb b/app/models/concerns/attachmentable.rb index c5febb828..01fae4236 100644 --- a/app/models/concerns/attachmentable.rb +++ b/app/models/concerns/attachmentable.rb @@ -15,50 +15,47 @@ module Attachmentable # those files, it is necessary to use the output of the # `file` utility instead INCORRECT_CONTENT_TYPES = %w( + audio/vorbis video/ogg video/webm ).freeze included do - before_post_process :obfuscate_file_name - before_post_process :set_file_extensions - before_post_process :check_image_dimensions - before_post_process :set_file_content_type + 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 + 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 private - def set_file_content_type - self.class.attachment_definitions.each_key do |attachment_name| - attachment = send(attachment_name) - - next if attachment.blank? || attachment.queued_for_write[:original].blank? || !INCORRECT_CONTENT_TYPES.include?(attachment.instance_read(:content_type)) + def set_file_content_type(attachment) # rubocop:disable Naming/AccessorMethodName + return if attachment.blank? || attachment.queued_for_write[:original].blank? || !INCORRECT_CONTENT_TYPES.include?(attachment.instance_read(:content_type)) - attachment.instance_write :content_type, calculated_content_type(attachment) - end + attachment.instance_write :content_type, calculated_content_type(attachment) end - def set_file_extensions - self.class.attachment_definitions.each_key do |attachment_name| - attachment = send(attachment_name) + def set_file_extension(attachment) # rubocop:disable Naming/AccessorMethodName + return if attachment.blank? - next if attachment.blank? - - attachment.instance_write :file_name, [Paperclip::Interpolations.basename(attachment, :original), appropriate_extension(attachment)].delete_if(&:blank?).join('.') - end + attachment.instance_write :file_name, [Paperclip::Interpolations.basename(attachment, :original), appropriate_extension(attachment)].delete_if(&:blank?).join('.') end - def check_image_dimensions - self.class.attachment_definitions.each_key do |attachment_name| - attachment = send(attachment_name) + def check_image_dimension(attachment) + return if attachment.blank? || !/image.*/.match?(attachment.content_type) || attachment.queued_for_write[:original].blank? - next if attachment.blank? || !/image.*/.match?(attachment.content_type) || attachment.queued_for_write[:original].blank? + width, height = FastImage.size(attachment.queued_for_write[:original].path) + matrix_limit = attachment.content_type == 'image/gif' ? GIF_MATRIX_LIMIT : MAX_MATRIX_LIMIT - width, height = FastImage.size(attachment.queued_for_write[:original].path) - matrix_limit = attachment.content_type == 'image/gif' ? GIF_MATRIX_LIMIT : MAX_MATRIX_LIMIT - - raise Mastodon::DimensionsValidationError, "#{width}x#{height} images are not supported" if width.present? && height.present? && (width * height > matrix_limit) - end + raise Mastodon::DimensionsValidationError, "#{width}x#{height} images are not supported" if width.present? && height.present? && (width * height > matrix_limit) end def appropriate_extension(attachment) @@ -79,13 +76,9 @@ module Attachmentable '' end - def obfuscate_file_name - self.class.attachment_definitions.each_key do |attachment_name| - attachment = send(attachment_name) + def obfuscate_file_name(attachment) + return if attachment.blank? || attachment.queued_for_write[:original].blank? || attachment.options[:preserve_files] - next if attachment.blank? || attachment.queued_for_write[:original].blank? || attachment.options[:preserve_files] - - attachment.instance_write :file_name, SecureRandom.hex(8) + File.extname(attachment.instance_read(:file_name)) - end + attachment.instance_write :file_name, SecureRandom.hex(8) + File.extname(attachment.instance_read(:file_name)) end end |