diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/account.rb | 30 | ||||
-rw-r--r-- | app/models/account_stat.rb | 25 | ||||
-rw-r--r-- | app/models/account_warning.rb | 2 | ||||
-rw-r--r-- | app/models/admin/account_action.rb | 11 | ||||
-rw-r--r-- | app/models/admin/action_log_filter.rb | 2 | ||||
-rw-r--r-- | app/models/announcement.rb | 1 | ||||
-rw-r--r-- | app/models/form/account_batch.rb | 8 | ||||
-rw-r--r-- | app/models/tag.rb | 2 |
8 files changed, 65 insertions, 16 deletions
diff --git a/app/models/account.rb b/app/models/account.rb index 1b8afe594..b0def4028 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -50,6 +50,8 @@ # avatar_storage_schema_version :integer # header_storage_schema_version :integer # devices_url :string +# sensitized_at :datetime +# suspension_origin :integer # require_dereference :boolean default(FALSE), not null # show_replies :boolean default(TRUE), not null # show_unlisted :boolean default(TRUE), not null @@ -82,6 +84,7 @@ class Account < ApplicationRecord }.freeze enum protocol: [:ostatus, :activitypub] + enum suspension_origin: [:local, :remote], _prefix: true validates :username, presence: true validates_with UniqueUsernameValidator, if: -> { will_save_change_to_username? } @@ -102,6 +105,7 @@ class Account < ApplicationRecord scope :partitioned, -> { order(Arel.sql('row_number() over (partition by domain)')) } scope :silenced, -> { where.not(silenced_at: nil) } scope :suspended, -> { where.not(suspended_at: nil) } + scope :sensitized, -> { where.not(sensitized_at: nil) } scope :without_suspended, -> { where(suspended_at: nil) } scope :without_silenced, -> { where(silenced_at: nil) } scope :recent, -> { reorder(id: :desc) } @@ -231,20 +235,40 @@ class Account < ApplicationRecord suspended_at.present? end - def suspend!(date = Time.now.utc) + def suspended_permanently? + suspended? && deletion_request.nil? + end + + def suspended_temporarily? + suspended? && deletion_request.present? + end + + def suspend!(date: Time.now.utc, origin: :local) transaction do create_deletion_request! - update!(suspended_at: date) + update!(suspended_at: date, suspension_origin: origin) end end def unsuspend! transaction do deletion_request&.destroy! - update!(suspended_at: nil) + update!(suspended_at: nil, suspension_origin: nil) end end + def sensitized? + sensitized_at.present? + end + + def sensitize!(date = Time.now.utc) + update!(sensitized_at: date) + end + + def unsensitize! + update!(sensitized_at: nil) + end + def memorialize! update!(memorial: true) end diff --git a/app/models/account_stat.rb b/app/models/account_stat.rb index c84e4217c..e70b54d79 100644 --- a/app/models/account_stat.rb +++ b/app/models/account_stat.rb @@ -21,26 +21,26 @@ class AccountStat < ApplicationRecord def increment_count!(key) update(attributes_for_increment(key)) - rescue ActiveRecord::StaleObjectError + rescue ActiveRecord::StaleObjectError, ActiveRecord::RecordNotUnique begin reload_with_id rescue ActiveRecord::RecordNotFound - # Nothing to do - else - retry + return end + + retry end def decrement_count!(key) - update(key => [public_send(key) - 1, 0].max) - rescue ActiveRecord::StaleObjectError + update(attributes_for_decrement(key)) + rescue ActiveRecord::StaleObjectError, ActiveRecord::RecordNotUnique begin reload_with_id rescue ActiveRecord::RecordNotFound - # Nothing to do - else - retry + return end + + retry end private @@ -51,8 +51,13 @@ class AccountStat < ApplicationRecord attrs end + def attributes_for_decrement(key) + attrs = { key => [public_send(key) - 1, 0].max } + attrs + end + def reload_with_id - self.id = find_by!(account: account).id if new_record? + self.id = self.class.find_by!(account: account).id if new_record? reload end end diff --git a/app/models/account_warning.rb b/app/models/account_warning.rb index 157e6c04d..5efc924d5 100644 --- a/app/models/account_warning.rb +++ b/app/models/account_warning.rb @@ -13,7 +13,7 @@ # class AccountWarning < ApplicationRecord - enum action: %i(none disable silence suspend), _suffix: :action + enum action: %i(none disable sensitive silence suspend), _suffix: :action belongs_to :account, inverse_of: :account_warnings belongs_to :target_account, class_name: 'Account', inverse_of: :targeted_account_warnings diff --git a/app/models/admin/account_action.rb b/app/models/admin/account_action.rb index c4ac09520..bf222391f 100644 --- a/app/models/admin/account_action.rb +++ b/app/models/admin/account_action.rb @@ -8,6 +8,7 @@ class Admin::AccountAction TYPES = %w( none disable + sensitive silence suspend ).freeze @@ -64,6 +65,8 @@ class Admin::AccountAction case type when 'disable' handle_disable! + when 'sensitive' + handle_sensitive! when 'silence' handle_silence! when 'suspend' @@ -109,6 +112,12 @@ class Admin::AccountAction target_account.user&.disable! end + def handle_sensitive! + authorize(target_account, :sensitive?) + log_action(:sensitive, target_account) + target_account.sensitize! + end + def handle_silence! authorize(target_account, :silence?) log_action(:silence, target_account) @@ -118,7 +127,7 @@ class Admin::AccountAction def handle_suspend! authorize(target_account, :suspend?) log_action(:suspend, target_account) - target_account.suspend! + target_account.suspend!(origin: :local) end def text_for_warning diff --git a/app/models/admin/action_log_filter.rb b/app/models/admin/action_log_filter.rb index 0ba7e1609..3a1b67e06 100644 --- a/app/models/admin/action_log_filter.rb +++ b/app/models/admin/action_log_filter.rb @@ -35,9 +35,11 @@ class Admin::ActionLogFilter reopen_report: { target_type: 'Report', action: 'reopen' }.freeze, reset_password_user: { target_type: 'User', action: 'reset_password' }.freeze, resolve_report: { target_type: 'Report', action: 'resolve' }.freeze, + sensitive_account: { target_type: 'Account', action: 'sensitive' }.freeze, silence_account: { target_type: 'Account', action: 'silence' }.freeze, suspend_account: { target_type: 'Account', action: 'suspend' }.freeze, unassigned_report: { target_type: 'Report', action: 'unassigned' }.freeze, + unsensitive_account: { target_type: 'Account', action: 'unsensitive' }.freeze, unsilence_account: { target_type: 'Account', action: 'unsilence' }.freeze, unsuspend_account: { target_type: 'Account', action: 'unsuspend' }.freeze, update_announcement: { target_type: 'Announcement', action: 'update' }.freeze, diff --git a/app/models/announcement.rb b/app/models/announcement.rb index c493604c2..f8183aabc 100644 --- a/app/models/announcement.rb +++ b/app/models/announcement.rb @@ -22,6 +22,7 @@ class Announcement < ApplicationRecord scope :published, -> { where(published: true) } scope :without_muted, ->(account) { joins("LEFT OUTER JOIN announcement_mutes ON announcement_mutes.announcement_id = announcements.id AND announcement_mutes.account_id = #{account.id}").where('announcement_mutes.id IS NULL') } scope :chronological, -> { order(Arel.sql('COALESCE(announcements.starts_at, announcements.scheduled_at, announcements.published_at, announcements.created_at) ASC')) } + scope :reverse_chronological, -> { order(Arel.sql('COALESCE(announcements.starts_at, announcements.scheduled_at, announcements.published_at, announcements.created_at) DESC')) } has_many :announcement_mutes, dependent: :destroy has_many :announcement_reactions, dependent: :destroy diff --git a/app/models/form/account_batch.rb b/app/models/form/account_batch.rb index 7b9e40f68..882770d7c 100644 --- a/app/models/form/account_batch.rb +++ b/app/models/form/account_batch.rb @@ -9,6 +9,8 @@ class Form::AccountBatch def save case action + when 'follow' + follow! when 'unfollow' unfollow! when 'remove_from_followers' @@ -24,6 +26,12 @@ class Form::AccountBatch private + def follow! + accounts.find_each do |target_account| + FollowService.new.call(current_account, target_account) + end + end + def unfollow! accounts.find_each do |target_account| UnfollowService.new.call(current_account, target_account) diff --git a/app/models/tag.rb b/app/models/tag.rb index df2f86d95..bb93a52e2 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -126,7 +126,7 @@ class Tag < ApplicationRecord end def search_for(term, limit = 5, offset = 0, options = {}) - normalized_term = normalize(term.strip).mb_chars.downcase.to_s + normalized_term = normalize(term.strip) pattern = sanitize_sql_like(normalized_term) + '%' query = Tag.listable.where(arel_table[:name].lower.matches(pattern)) query = query.where(arel_table[:name].lower.eq(normalized_term).or(arel_table[:reviewed_at].not_eq(nil))) if options[:exclude_unreviewed] |