Merge commit 'f378f10404
' into kb_migration
This commit is contained in:
commit
edb2a5dcf3
153 changed files with 1225 additions and 1025 deletions
|
@ -66,9 +66,9 @@ class Account < ApplicationRecord
|
|||
trust_level
|
||||
)
|
||||
|
||||
USERNAME_RE = /[a-z0-9_]+([a-z0-9_\.-]+[a-z0-9_]+)?/i
|
||||
MENTION_RE = /(?<=^|[^\/[:word:]])@((#{USERNAME_RE})(?:@[[:word:]\.\-]+[[:word:]]+)?)/i
|
||||
URL_PREFIX_RE = /\Ahttp(s?):\/\/[^\/]+/
|
||||
USERNAME_RE = /[a-z0-9_]+([a-z0-9_.-]+[a-z0-9_]+)?/i
|
||||
MENTION_RE = %r{(?<=^|[^/[:word:]])@((#{USERNAME_RE})(?:@[[:word:].-]+[[:word:]]+)?)}i
|
||||
URL_PREFIX_RE = %r{\Ahttp(s?)://[^/]+}
|
||||
USERNAME_ONLY_RE = /\A#{USERNAME_RE}\z/i
|
||||
|
||||
include Attachmentable
|
||||
|
|
|
@ -35,7 +35,7 @@ class DomainAllow < ApplicationRecord
|
|||
def rule_for(domain)
|
||||
return if domain.blank?
|
||||
|
||||
uri = Addressable::URI.new.tap { |u| u.host = domain.gsub(/[\/]/, '') }
|
||||
uri = Addressable::URI.new.tap { |u| u.host = domain.delete('/') }
|
||||
|
||||
find_by(domain: uri.normalized_host)
|
||||
end
|
||||
|
|
|
@ -119,7 +119,7 @@ class DomainBlock < ApplicationRecord
|
|||
def rule_for(domain)
|
||||
return if domain.blank?
|
||||
|
||||
uri = Addressable::URI.new.tap { |u| u.host = domain.strip.gsub(/[\/]/, '') }
|
||||
uri = Addressable::URI.new.tap { |u| u.host = domain.strip.delete('/') }
|
||||
segments = uri.normalized_host.split('.')
|
||||
variants = segments.map.with_index { |_, i| segments[i..-1].join('.') }
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ class Report < ApplicationRecord
|
|||
enum category: {
|
||||
other: 0,
|
||||
spam: 1_000,
|
||||
legal: 1_500,
|
||||
violation: 2_000,
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ class SiteUpload < ApplicationRecord
|
|||
|
||||
has_attached_file :file, styles: ->(file) { STYLES[file.instance.var.to_sym] }, convert_options: { all: '-coalesce +profile "!icc,*" +set modify-date +set create-date' }, processors: [:lazy_thumbnail, :blurhash_transcoder, :type_corrector]
|
||||
|
||||
validates_attachment_content_type :file, content_type: /\Aimage\/.*\z/
|
||||
validates_attachment_content_type :file, content_type: %r{\Aimage/.*\z}
|
||||
validates :file, presence: true
|
||||
validates :var, presence: true, uniqueness: true
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ class Tag < ApplicationRecord
|
|||
HASHTAG_LAST_SEQUENCE = '([[:word:]_]*[[:alpha:]][[:word:]_]*)'
|
||||
HASHTAG_NAME_PAT = "#{HASHTAG_FIRST_SEQUENCE}|#{HASHTAG_LAST_SEQUENCE}"
|
||||
|
||||
HASHTAG_RE = /(?:^|[^\/\)\w])#(#{HASHTAG_NAME_PAT})/i
|
||||
HASHTAG_RE = %r{(?:^|[^/)\w])#(#{HASHTAG_NAME_PAT})}i
|
||||
HASHTAG_NAME_RE = /\A(#{HASHTAG_NAME_PAT})\z/i
|
||||
HASHTAG_INVALID_CHARS_RE = /[^[:alnum:]#{HASHTAG_SEPARATORS}]/
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
# enabled :boolean default(TRUE), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# template :text
|
||||
#
|
||||
|
||||
class Webhook < ApplicationRecord
|
||||
|
@ -30,6 +31,7 @@ class Webhook < ApplicationRecord
|
|||
validates :events, presence: true
|
||||
|
||||
validate :validate_events
|
||||
validate :validate_template
|
||||
|
||||
before_validation :strip_events
|
||||
before_validation :generate_secret
|
||||
|
@ -49,7 +51,18 @@ class Webhook < ApplicationRecord
|
|||
private
|
||||
|
||||
def validate_events
|
||||
errors.add(:events, :invalid) if events.any? { |e| !EVENTS.include?(e) }
|
||||
errors.add(:events, :invalid) if events.any? { |e| EVENTS.exclude?(e) }
|
||||
end
|
||||
|
||||
def validate_template
|
||||
return if template.blank?
|
||||
|
||||
begin
|
||||
parser = Webhooks::PayloadRenderer::TemplateParser.new
|
||||
parser.parse(template)
|
||||
rescue Parslet::ParseFailed
|
||||
errors.add(:template, :invalid)
|
||||
end
|
||||
end
|
||||
|
||||
def strip_events
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue