about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authorStarfall <us@starfall.systems>2022-11-28 16:41:29 -0600
committerStarfall <us@starfall.systems>2022-11-28 16:41:29 -0600
commitcb9dad90b01c9f53d1910cf128eb22200bdb9884 (patch)
tree1935d74f49853ed371e36cfac2d44ac33d2e8a2e /app/models
parentc3c3b6953f37462f26f011b6c6cbd1655d5dcbea (diff)
parent1a7aa37b60769a10077c585fa76ec848b6866d9a (diff)
Merge remote-tracking branch 'glitch/main'
Diffstat (limited to 'app/models')
-rw-r--r--app/models/account/field.rb3
-rw-r--r--app/models/account_filter.rb8
-rw-r--r--app/models/admin/import.rb35
-rw-r--r--app/models/form/account_batch.rb4
-rw-r--r--app/models/media_attachment.rb1
-rw-r--r--app/models/poll.rb1
-rw-r--r--app/models/status.rb15
-rw-r--r--app/models/user.rb5
8 files changed, 44 insertions, 28 deletions
diff --git a/app/models/account/field.rb b/app/models/account/field.rb
index ffc8dce80..4db4cac30 100644
--- a/app/models/account/field.rb
+++ b/app/models/account/field.rb
@@ -46,7 +46,8 @@ class Account::Field < ActiveModelSerializers::Model
       parsed_url.user.nil? &&
       parsed_url.password.nil? &&
       parsed_url.host.present? &&
-      parsed_url.normalized_host == parsed_url.host
+      parsed_url.normalized_host == parsed_url.host &&
+      (parsed_url.path.empty? || parsed_url.path == parsed_url.normalized_path)
   rescue Addressable::URI::InvalidURIError, IDN::Idna::IdnaError
     false
   end
diff --git a/app/models/account_filter.rb b/app/models/account_filter.rb
index e09ce4ec2..3a4ac0492 100644
--- a/app/models/account_filter.rb
+++ b/app/models/account_filter.rb
@@ -43,13 +43,13 @@ class AccountFilter
     when 'status'
       status_scope(value)
     when 'by_domain'
-      Account.where(domain: value.to_s)
+      Account.where(domain: value.to_s.strip)
     when 'username'
-      Account.matches_username(value.to_s)
+      Account.matches_username(value.to_s.strip)
     when 'display_name'
-      Account.matches_display_name(value.to_s)
+      Account.matches_display_name(value.to_s.strip)
     when 'email'
-      accounts_with_users.merge(User.matches_email(value.to_s))
+      accounts_with_users.merge(User.matches_email(value.to_s.strip))
     when 'ip'
       valid_ip?(value) ? accounts_with_users.merge(User.matches_ip(value).group('users.id, accounts.id')) : Account.none
     when 'invited_by'
diff --git a/app/models/admin/import.rb b/app/models/admin/import.rb
index c305be237..79c0722d5 100644
--- a/app/models/admin/import.rb
+++ b/app/models/admin/import.rb
@@ -2,28 +2,31 @@
 
 # A non-activerecord helper class for csv upload
 class Admin::Import
-  extend ActiveModel::Callbacks
   include ActiveModel::Model
-  include Paperclip::Glue
 
-  FILE_TYPES = %w(text/plain text/csv application/csv).freeze
+  ROWS_PROCESSING_LIMIT = 20_000
 
-  # Paperclip required callbacks
-  define_model_callbacks :save, only: [:after]
-  define_model_callbacks :destroy, only: [:before, :after]
+  attr_accessor :data
 
-  attr_accessor :data_file_name, :data_content_type
+  validates :data, presence: true
+  validate :validate_data
 
-  has_attached_file :data
-  validates_attachment_content_type :data, content_type: FILE_TYPES
-  validates_attachment_presence :data
-  validates_with AdminImportValidator, on: :create
-
-  def save
-    run_callbacks :save
+  def data_file_name
+    data.original_filename
   end
 
-  def destroy
-    run_callbacks :destroy
+  private
+
+  def validate_data
+    return if data.blank?
+
+    csv_data = CSV.read(data.path, encoding: 'UTF-8')
+
+    row_count  = csv_data.size
+    row_count -= 1 if csv_data.first&.first == '#domain'
+
+    errors.add(:data, I18n.t('imports.errors.over_rows_processing_limit', count: ROWS_PROCESSING_LIMIT)) if row_count > ROWS_PROCESSING_LIMIT
+  rescue CSV::MalformedCSVError => e
+    errors.add(:data, I18n.t('imports.errors.invalid_csv_file', error: e.message))
   end
 end
diff --git a/app/models/form/account_batch.rb b/app/models/form/account_batch.rb
index 5cfcf7205..473622edf 100644
--- a/app/models/form/account_batch.rb
+++ b/app/models/form/account_batch.rb
@@ -115,6 +115,10 @@ class Form::AccountBatch
     authorize(account, :suspend?)
     log_action(:suspend, account)
     account.suspend!(origin: :local)
+    account.strikes.create!(
+      account: current_account,
+      action: :suspend
+    )
     Admin::SuspensionWorker.perform_async(account.id)
   end
 
diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb
index 6f079dd18..f2b34e4cd 100644
--- a/app/models/media_attachment.rb
+++ b/app/models/media_attachment.rb
@@ -104,6 +104,7 @@ class MediaAttachment < ApplicationRecord
         'c:v' => 'h264',
         'maxrate' => '1300K',
         'bufsize' => '1300K',
+        'b:v' => '1300K',
         'frames:v' => 60 * 60 * 3,
         'crf' => 18,
         'map_metadata' => '-1',
diff --git a/app/models/poll.rb b/app/models/poll.rb
index 1a326e452..af3b09315 100644
--- a/app/models/poll.rb
+++ b/app/models/poll.rb
@@ -85,6 +85,7 @@ class Poll < ApplicationRecord
   def reset_votes!
     self.cached_tallies = options.map { 0 }
     self.votes_count = 0
+    self.voters_count = 0
     votes.delete_all unless new_record?
   end
 
diff --git a/app/models/status.rb b/app/models/status.rb
index 044816be7..6cfe19d23 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -68,6 +68,7 @@ class Status < ApplicationRecord
   has_many :reblogged_by_accounts, through: :reblogs, class_name: 'Account', source: :account
   has_many :replies, foreign_key: 'in_reply_to_id', class_name: 'Status', inverse_of: :thread
   has_many :mentions, dependent: :destroy, inverse_of: :status
+  has_many :mentioned_accounts, through: :mentions, source: :account, class_name: 'Account'
   has_many :active_mentions, -> { active }, class_name: 'Mention', inverse_of: :status
   has_many :media_attachments, dependent: :nullify
 
@@ -146,11 +147,11 @@ class Status < ApplicationRecord
     ids << account_id if local?
 
     if preloaded.nil?
-      ids += mentions.where(account: Account.local, silent: false).pluck(:account_id)
-      ids += favourites.where(account: Account.local).pluck(:account_id)
-      ids += reblogs.where(account: Account.local).pluck(:account_id)
-      ids += bookmarks.where(account: Account.local).pluck(:account_id)
-      ids += poll.votes.where(account: Account.local).pluck(:account_id) if poll.present?
+      ids += mentions.joins(:account).merge(Account.local).active.pluck(:account_id)
+      ids += favourites.joins(:account).merge(Account.local).pluck(:account_id)
+      ids += reblogs.joins(:account).merge(Account.local).pluck(:account_id)
+      ids += bookmarks.joins(:account).merge(Account.local).pluck(:account_id)
+      ids += poll.votes.joins(:account).merge(Account.local).pluck(:account_id) if poll.present?
     else
       ids += preloaded.mentions[id] || []
       ids += preloaded.favourites[id] || []
@@ -590,8 +591,8 @@ class Status < ApplicationRecord
   def unlink_from_conversations
     return unless direct_visibility?
 
-    mentioned_accounts = (association(:mentions).loaded? ? mentions : mentions.includes(:account)).map(&:account)
-    inbox_owners       = mentioned_accounts.select(&:local?) + (account.local? ? [account] : [])
+    inbox_owners = mentioned_accounts.local
+    inbox_owners += [account] if account.local?
 
     inbox_owners.each do |inbox_owner|
       AccountConversation.remove_status(inbox_owner, self)
diff --git a/app/models/user.rb b/app/models/user.rb
index 0e8a87aea..0eb975dec 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -237,6 +237,11 @@ class User < ApplicationRecord
   end
 
   def functional?
+
+    functional_or_moved?
+  end
+
+  def functional_or_moved?
     confirmed? && approved? && !disabled? && !account.suspended? && !account.memorial?
   end