Merge commit 'fe2667bb0d3487a32b9da5250402a90482a85fe2' into glitch-soc/merge-upstream
Conflicts: - `app/lib/content_security_policy.rb`: Conflict caused by glitch-soc's support for the extra `EXTRA_DATA_HOSTS` environment variable. Ported upstream's changes while keeping support for `EXTRA_DATA_HOSTS`.
This commit is contained in:
commit
0b2c7cdb02
116 files changed
+873
-518
No files matched your search
@@ -11,11 +11,12 @@ module Attachmentable
|
||||
# For some file extensions, there exist different content
|
||||
# type variants, and browsers often send the wrong one,
|
||||
# for example, sending an audio .ogg file as video/ogg,
|
||||
# likewise, MimeMagic also misreports them as such. For
|
||||
# likewise, kt-paperclip also misreports them as such. For
|
||||
# those files, it is necessary to use the output of the
|
||||
# `file` utility instead
|
||||
INCORRECT_CONTENT_TYPES = %w(
|
||||
audio/vorbis
|
||||
audio/opus
|
||||
video/ogg
|
||||
video/webm
|
||||
).freeze
|
||||
|
||||
@@ -17,23 +17,8 @@
|
||||
class CustomFilter < ApplicationRecord
|
||||
self.ignored_columns += %w(whole_word irreversible)
|
||||
|
||||
# NOTE: We previously used `alias_attribute` but this does not play nicely
|
||||
# with cache
|
||||
def title
|
||||
phrase
|
||||
end
|
||||
|
||||
def title=(value)
|
||||
self.phrase = value
|
||||
end
|
||||
|
||||
def filter_action
|
||||
action
|
||||
end
|
||||
|
||||
def filter_action=(value)
|
||||
self.action = value
|
||||
end
|
||||
alias_attribute :title, :phrase
|
||||
alias_attribute :filter_action, :action
|
||||
|
||||
VALID_CONTEXTS = %w(
|
||||
home
|
||||
@@ -143,6 +128,10 @@ class CustomFilter < ApplicationRecord
|
||||
end
|
||||
|
||||
def context_must_be_valid
|
||||
errors.add(:context, I18n.t('filters.errors.invalid_context')) if context.empty? || context.any? { |c| !VALID_CONTEXTS.include?(c) }
|
||||
errors.add(:context, I18n.t('filters.errors.invalid_context')) if invalid_context_value?
|
||||
end
|
||||
|
||||
def invalid_context_value?
|
||||
context.blank? || context.difference(VALID_CONTEXTS).any?
|
||||
end
|
||||
end
|
||||
@@ -17,15 +17,7 @@ class CustomFilterKeyword < ApplicationRecord
|
||||
|
||||
validates :keyword, presence: true
|
||||
|
||||
# NOTE: We previously used `alias_attribute` but this does not play nicely
|
||||
# with cache
|
||||
def phrase
|
||||
keyword
|
||||
end
|
||||
|
||||
def phrase=(value)
|
||||
self.keyword = value
|
||||
end
|
||||
alias_attribute :phrase, :keyword
|
||||
|
||||
before_save :prepare_cache_invalidation!
|
||||
before_destroy :prepare_cache_invalidation!
|
||||
|
||||
@@ -4,11 +4,12 @@
|
||||
#
|
||||
# Table name: email_domain_blocks
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# domain :string default(""), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# parent_id :bigint(8)
|
||||
# id :bigint(8) not null, primary key
|
||||
# domain :string default(""), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# parent_id :bigint(8)
|
||||
# allow_with_approval :boolean default(FALSE), not null
|
||||
#
|
||||
|
||||
class EmailDomainBlock < ApplicationRecord
|
||||
@@ -42,8 +43,8 @@ class EmailDomainBlock < ApplicationRecord
|
||||
@attempt_ip = attempt_ip
|
||||
end
|
||||
|
||||
def match?
|
||||
blocking? || invalid_uri?
|
||||
def match?(...)
|
||||
blocking?(...) || invalid_uri?
|
||||
end
|
||||
|
||||
private
|
||||
@@ -52,8 +53,8 @@ class EmailDomainBlock < ApplicationRecord
|
||||
@uris.any?(&:nil?)
|
||||
end
|
||||
|
||||
def blocking?
|
||||
blocks = EmailDomainBlock.where(domain: domains_with_variants).order(Arel.sql('char_length(domain) desc'))
|
||||
def blocking?(allow_with_approval: false)
|
||||
blocks = EmailDomainBlock.where(domain: domains_with_variants, allow_with_approval: allow_with_approval).order(Arel.sql('char_length(domain) desc'))
|
||||
blocks.each { |block| block.history.add(@attempt_ip) } if @attempt_ip.present?
|
||||
blocks.any?
|
||||
end
|
||||
@@ -86,4 +87,8 @@ class EmailDomainBlock < ApplicationRecord
|
||||
def self.block?(domain_or_domains, attempt_ip: nil)
|
||||
Matcher.new(domain_or_domains, attempt_ip: attempt_ip).match?
|
||||
end
|
||||
|
||||
def self.requires_approval?(domain_or_domains, attempt_ip: nil)
|
||||
Matcher.new(domain_or_domains, attempt_ip: attempt_ip).match?(allow_with_approval: true)
|
||||
end
|
||||
end
|
||||
+7
-1
@@ -418,7 +418,7 @@ class User < ApplicationRecord
|
||||
|
||||
def set_approved
|
||||
self.approved = begin
|
||||
if sign_up_from_ip_requires_approval?
|
||||
if sign_up_from_ip_requires_approval? || sign_up_email_requires_approval?
|
||||
false
|
||||
else
|
||||
open_registrations? || valid_invitation? || external?
|
||||
@@ -430,6 +430,12 @@ class User < ApplicationRecord
|
||||
!sign_up_ip.nil? && IpBlock.where(severity: :sign_up_requires_approval).where('ip >>= ?', sign_up_ip.to_s).exists?
|
||||
end
|
||||
|
||||
def sign_up_email_requires_approval?
|
||||
return false unless email.present? || unconfirmed_email.present?
|
||||
|
||||
EmailDomainBlock.requires_approval?(email.presence || unconfirmed_email, attempt_ip: sign_up_ip)
|
||||
end
|
||||
|
||||
def open_registrations?
|
||||
Setting.registrations_mode == 'open'
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user