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

Conflicts:
- `app/controllers/settings/preferences_controller.rb`:
  Upstream dropping `digest` from notifications emails while we have more
  notification emails settings.
  Removed `digest` from our list while keeping our extra settings.
- `app/javascript/packs/admin.js`:
  Conflicts caused by glitch-soc's theming system.
  Applied the changes to `app/javascript/core/admin.js`.
- `app/views/settings/preferences/other/show.html.haml`:
  Upstream removed a setting close to a glitch-soc-only setting.
  Applied upstream's change.
This commit is contained in:
Claire
2022-08-28 11:26:27 +02:00
72 changed files with 1796 additions and 830 deletions

View File

@@ -364,6 +364,10 @@ class Account < ApplicationRecord
username
end
def to_log_human_identifier
acct
end
def excluded_from_timeline_account_ids
Rails.cache.fetch("exclude_account_ids_for:#{id}") { block_relationships.pluck(:target_account_id) + blocked_by_relationships.pluck(:account_id) + mute_relationships.pluck(:target_account_id) }
end

View File

@@ -43,4 +43,8 @@ class AccountWarning < ApplicationRecord
def overruled?
overruled_at.present?
end
def to_log_human_identifier
target_account.acct
end
end

View File

@@ -9,38 +9,42 @@
# action :string default(""), not null
# target_type :string
# target_id :bigint(8)
# recorded_changes :text default(""), not null
# created_at :datetime not null
# updated_at :datetime not null
# human_identifier :string
# route_param :string
# permalink :string
#
class Admin::ActionLog < ApplicationRecord
serialize :recorded_changes
self.ignored_columns = %w(
recorded_changes
)
belongs_to :account
belongs_to :target, polymorphic: true, optional: true
default_scope -> { order('id desc') }
before_validation :set_human_identifier
before_validation :set_route_param
before_validation :set_permalink
def action
super.to_sym
end
before_validation :set_changes
private
def set_changes
case action
when :destroy, :create
self.recorded_changes = target.attributes
when :update, :promote, :demote
self.recorded_changes = target.previous_changes
when :change_email
self.recorded_changes = ActiveSupport::HashWithIndifferentAccess.new(
email: [target.email, nil],
unconfirmed_email: [nil, target.unconfirmed_email]
)
end
def set_human_identifier
self.human_identifier = target.to_log_human_identifier if target.respond_to?(:to_log_human_identifier)
end
def set_route_param
self.route_param = target.to_log_route_param if target.respond_to?(:to_log_route_param)
end
def set_permalink
self.permalink = target.to_log_permalink if target.respond_to?(:to_log_permalink)
end
end

View File

@@ -12,6 +12,7 @@ class Admin::ActionLogFilter
reject_appeal: { target_type: 'Appeal', action: 'reject' }.freeze,
assigned_to_self_report: { target_type: 'Report', action: 'assigned_to_self' }.freeze,
change_email_user: { target_type: 'User', action: 'change_email' }.freeze,
change_role_user: { target_type: 'User', action: 'change_role' }.freeze,
confirm_user: { target_type: 'User', action: 'confirm' }.freeze,
approve_user: { target_type: 'User', action: 'approve' }.freeze,
reject_user: { target_type: 'User', action: 'reject' }.freeze,
@@ -21,16 +22,22 @@ class Admin::ActionLogFilter
create_domain_allow: { target_type: 'DomainAllow', action: 'create' }.freeze,
create_domain_block: { target_type: 'DomainBlock', action: 'create' }.freeze,
create_email_domain_block: { target_type: 'EmailDomainBlock', action: 'create' }.freeze,
create_ip_block: { target_type: 'IpBlock', action: 'create' }.freeze,
create_unavailable_domain: { target_type: 'UnavailableDomain', action: 'create' }.freeze,
create_user_role: { target_type: 'UserRole', action: 'create' }.freeze,
create_canonical_email_block: { target_type: 'CanonicalEmailBlock', action: 'create' }.freeze,
demote_user: { target_type: 'User', action: 'demote' }.freeze,
destroy_announcement: { target_type: 'Announcement', action: 'destroy' }.freeze,
destroy_custom_emoji: { target_type: 'CustomEmoji', action: 'destroy' }.freeze,
destroy_domain_allow: { target_type: 'DomainAllow', action: 'destroy' }.freeze,
destroy_domain_block: { target_type: 'DomainBlock', action: 'destroy' }.freeze,
destroy_ip_block: { target_type: 'IpBlock', action: 'destroy' }.freeze,
destroy_email_domain_block: { target_type: 'EmailDomainBlock', action: 'destroy' }.freeze,
destroy_instance: { target_type: 'Instance', action: 'destroy' }.freeze,
destroy_unavailable_domain: { target_type: 'UnavailableDomain', action: 'destroy' }.freeze,
destroy_status: { target_type: 'Status', action: 'destroy' }.freeze,
destroy_user_role: { target_type: 'UserRole', action: 'destroy' }.freeze,
destroy_canonical_email_block: { target_type: 'CanonicalEmailBlock', action: 'destroy' }.freeze,
disable_2fa_user: { target_type: 'User', action: 'disable' }.freeze,
disable_custom_emoji: { target_type: 'CustomEmoji', action: 'disable' }.freeze,
disable_user: { target_type: 'User', action: 'disable' }.freeze,
@@ -52,6 +59,8 @@ class Admin::ActionLogFilter
update_announcement: { target_type: 'Announcement', action: 'update' }.freeze,
update_custom_emoji: { target_type: 'CustomEmoji', action: 'update' }.freeze,
update_status: { target_type: 'Status', action: 'update' }.freeze,
update_user_role: { target_type: 'UserRole', action: 'update' }.freeze,
update_ip_block: { target_type: 'IpBlock', action: 'update' }.freeze,
unblock_email_account: { target_type: 'Account', action: 'unblock_email' }.freeze,
}.freeze

View File

@@ -34,6 +34,10 @@ class Announcement < ApplicationRecord
before_validation :set_all_day
before_validation :set_published, on: :create
def to_log_human_identifier
text
end
def publish!
update!(published: true, published_at: Time.now.utc, scheduled_at: nil)
end

View File

@@ -52,6 +52,14 @@ class Appeal < ApplicationRecord
update!(rejected_at: Time.now.utc, rejected_by_account: current_account)
end
def to_log_human_identifier
account.acct
end
def to_log_route_param
account_warning_id
end
private
def validate_time_frame

View File

@@ -5,27 +5,30 @@
#
# id :bigint(8) not null, primary key
# canonical_email_hash :string default(""), not null
# reference_account_id :bigint(8) not null
# reference_account_id :bigint(8)
# created_at :datetime not null
# updated_at :datetime not null
#
class CanonicalEmailBlock < ApplicationRecord
include EmailHelper
include Paginable
belongs_to :reference_account, class_name: 'Account'
belongs_to :reference_account, class_name: 'Account', optional: true
validates :canonical_email_hash, presence: true, uniqueness: true
scope :matching_email, ->(email) { where(canonical_email_hash: email_to_canonical_email_hash(email)) }
def to_log_human_identifier
canonical_email_hash
end
def email=(email)
self.canonical_email_hash = email_to_canonical_email_hash(email)
end
def self.block?(email)
where(canonical_email_hash: email_to_canonical_email_hash(email)).exists?
end
def self.find_blocks(email)
where(canonical_email_hash: email_to_canonical_email_hash(email))
matching_email(email).exists?
end
end

View File

@@ -49,7 +49,7 @@ class CustomEmoji < ApplicationRecord
scope :local, -> { where(domain: nil) }
scope :remote, -> { where.not(domain: nil) }
scope :alphabetic, -> { order(domain: :asc, shortcode: :asc) }
scope :by_domain_and_subdomains, ->(domain) { where(domain: domain).or(where(arel_table[:domain].matches('%.' + domain))) }
scope :by_domain_and_subdomains, ->(domain) { where(domain: domain).or(where(arel_table[:domain].matches("%.#{domain}"))) }
scope :listed, -> { local.where(disabled: false).where(visible_in_picker: true) }
remotable_attachment :image, LIMIT
@@ -70,6 +70,10 @@ class CustomEmoji < ApplicationRecord
copy.tap(&:save!)
end
def to_log_human_identifier
shortcode
end
class << self
def from_text(text, domain = nil)
return [] if text.blank?

View File

@@ -5,7 +5,7 @@
#
# id :bigint(8) not null, primary key
# custom_filter_id :bigint(8) not null
# status_id :bigint(8) default(""), not null
# status_id :bigint(8) not null
# created_at :datetime not null
# updated_at :datetime not null
#

View File

@@ -19,6 +19,10 @@ class DomainAllow < ApplicationRecord
scope :matches_domain, ->(value) { where(arel_table[:domain].matches("%#{value}%")) }
def to_log_human_identifier
domain
end
class << self
def allowed?(domain)
!rule_for(domain).nil?

View File

@@ -31,6 +31,10 @@ class DomainBlock < ApplicationRecord
scope :with_user_facing_limitations, -> { where(severity: [:silence, :suspend]).or(where(reject_media: true)) }
scope :by_severity, -> { order(Arel.sql('(CASE severity WHEN 0 THEN 1 WHEN 1 THEN 2 WHEN 2 THEN 0 END), reject_media, domain')) }
def to_log_human_identifier
domain
end
def policies
if suspend?
[:suspend]

View File

@@ -17,6 +17,7 @@ class EmailDomainBlock < ApplicationRecord
)
include DomainNormalizable
include Paginable
belongs_to :parent, class_name: 'EmailDomainBlock', optional: true
has_many :children, class_name: 'EmailDomainBlock', foreign_key: :parent_id, inverse_of: :parent, dependent: :destroy
@@ -26,6 +27,10 @@ class EmailDomainBlock < ApplicationRecord
# Used for adding multiple blocks at once
attr_accessor :other_domains
def to_log_human_identifier
domain
end
def history
@history ||= Trends::History.new('email_domain_blocks', id)
end

View File

@@ -6,7 +6,8 @@ class Form::AccountBatch
include AccountableConcern
include Payloadable
attr_accessor :account_ids, :action, :current_account
attr_accessor :account_ids, :action, :current_account,
:select_all_matching, :query
def save
case action
@@ -60,7 +61,11 @@ class Form::AccountBatch
end
def accounts
Account.where(id: account_ids)
if select_all_matching?
query
else
Account.where(id: account_ids)
end
end
def approve!
@@ -101,7 +106,7 @@ class Form::AccountBatch
def reject_account(account)
authorize(account.user, :reject?)
log_action(:reject, account.user, username: account.username)
log_action(:reject, account.user)
account.suspend!(origin: :local)
AccountDeletionWorker.perform_async(account.id, { 'reserve_username' => false })
end
@@ -118,4 +123,8 @@ class Form::AccountBatch
log_action(:approve, account.user)
account.user.approve!
end
def select_all_matching?
select_all_matching == '1'
end
end

View File

@@ -48,6 +48,8 @@ class Instance < ApplicationRecord
domain
end
alias to_log_human_identifier to_param
delegate :exhausted_deliveries_days, to: :delivery_failure_tracker
def availability_over_days(num_days, end_date = Time.now.utc.to_date)

View File

@@ -16,6 +16,7 @@ class IpBlock < ApplicationRecord
CACHE_KEY = 'blocked_ips'
include Expireable
include Paginable
enum severity: {
sign_up_requires_approval: 5000,
@@ -27,6 +28,10 @@ class IpBlock < ApplicationRecord
after_commit :reset_cache
def to_log_human_identifier
"#{ip}/#{ip.prefix}"
end
class << self
def blocked?(remote_ip)
blocked_ips_map = Rails.cache.fetch(CACHE_KEY) { FastIpMap.new(IpBlock.where(severity: :no_access).pluck(:ip)) }

View File

@@ -115,6 +115,10 @@ class Report < ApplicationRecord
Report.where.not(id: id).where(target_account_id: target_account_id).unresolved.exists?
end
def to_log_human_identifier
id
end
def history
subquery = [
Admin::ActionLog.where(
@@ -136,6 +140,8 @@ class Report < ApplicationRecord
Admin::ActionLog.from(Arel::Nodes::As.new(subquery, Admin::ActionLog.arel_table))
end
private
def set_uri
self.uri = ActivityPub::TagManager.instance.generate_uri_for(self) if uri.nil? && account.local?
end

View File

@@ -171,6 +171,14 @@ class Status < ApplicationRecord
].compact.join("\n\n")
end
def to_log_human_identifier
account.acct
end
def to_log_permalink
ActivityPub::TagManager.instance.uri_for(self)
end
def reply?
!in_reply_to_id.nil? || attributes['reply']
end

View File

@@ -16,6 +16,10 @@ class UnavailableDomain < ApplicationRecord
after_commit :reset_cache!
def to_log_human_identifier
domain
end
private
def reset_cache!

View File

@@ -181,6 +181,14 @@ class User < ApplicationRecord
update!(disabled: false)
end
def to_log_human_identifier
account.acct
end
def to_log_route_param
account_id
end
def confirm
new_user = !confirmed?
self.approved = true if open_registrations? && !sign_up_from_ip_requires_approval?
@@ -281,10 +289,6 @@ class User < ApplicationRecord
settings.default_privacy || (account.locked? ? 'private' : 'public')
end
def allows_digest_emails?
settings.notification_emails['digest']
end
def allows_report_emails?
settings.notification_emails['report']
end

View File

@@ -155,6 +155,10 @@ class UserRole < ApplicationRecord
end
end
def to_log_human_identifier
name
end
private
def in_permissions?(privilege)