Merge branch 'master' into glitch-soc/merge-upstream

Conflicts:
- app/models/status.rb
- app/services/remove_status_service.rb
- db/schema.rb

All conflicts were due to the addition of a `deleted_at` attribute
to Statuses and reworked database indexes.
This commit is contained in:
Thibaut Girka
2019-08-29 12:07:50 +02:00
66 changed files with 848 additions and 186 deletions

View File

@@ -19,20 +19,25 @@ class Admin::AccountAction
:report_id,
:warning_preset_id
attr_reader :warning, :send_email_notification
attr_reader :warning, :send_email_notification, :include_statuses
def send_email_notification=(value)
@send_email_notification = ActiveModel::Type::Boolean.new.cast(value)
end
def include_statuses=(value)
@include_statuses = ActiveModel::Type::Boolean.new.cast(value)
end
def save!
ApplicationRecord.transaction do
process_action!
process_warning!
end
queue_email!
process_email!
process_reports!
process_queue!
end
def report
@@ -110,7 +115,6 @@ class Admin::AccountAction
authorize(target_account, :suspend?)
log_action(:suspend, target_account)
target_account.suspend!
queue_suspension_worker!
end
def text_for_warning
@@ -121,16 +125,22 @@ class Admin::AccountAction
Admin::SuspensionWorker.perform_async(target_account.id)
end
def queue_email!
return unless warnable?
def process_queue!
queue_suspension_worker! if type == 'suspend'
end
UserMailer.warning(target_account.user, warning).deliver_later!
def process_email!
UserMailer.warning(target_account.user, warning, status_ids).deliver_now! if warnable?
end
def warnable?
send_email_notification && target_account.local?
end
def status_ids
@report.status_ids if @report && include_statuses
end
def warning_preset
@warning_preset ||= AccountWarningPreset.find(warning_preset_id) if warning_preset_id.present?
end

View File

@@ -34,7 +34,8 @@ class Form::StatusBatch
def delete_statuses
Status.where(id: status_ids).reorder(nil).find_each do |status|
RemovalWorker.perform_async(status.id)
status.discard
RemovalWorker.perform_async(status.id, redraft: false)
Tombstone.find_or_create_by(uri: status.uri, account: status.account, by_moderator: true)
log_action :destroy, status
end

View File

@@ -43,7 +43,7 @@ class Report < ApplicationRecord
end
def statuses
Status.where(id: status_ids).includes(:account, :media_attachments, :mentions)
Status.with_discarded.where(id: status_ids).includes(:account, :media_attachments, :mentions)
end
def media_attachments

View File

@@ -25,15 +25,19 @@
# full_status_text :text default(""), not null
# poll_id :bigint(8)
# content_type :string
# deleted_at :datetime
#
class Status < ApplicationRecord
before_destroy :unlink_from_conversations
include Discard::Model
include Paginable
include Cacheable
include StatusThreadingConcern
self.discard_column = :deleted_at
# If `override_timestamps` is set at creation time, Snowflake ID creation
# will be based on current time instead of `created_at`
attr_accessor :override_timestamps
@@ -77,7 +81,7 @@ class Status < ApplicationRecord
accepts_nested_attributes_for :poll
default_scope { recent }
default_scope { recent.kept }
scope :recent, -> { reorder(id: :desc) }
scope :remote, -> { where(local: false).where.not(uri: nil) }