Merge pull request #786 from kmycode/upstream-20240731
Upstream 20240731
This commit is contained in:
commit
9e1c63aa2c
320 changed files with 3132 additions and 1643 deletions
|
@ -72,7 +72,7 @@ class Account < ApplicationRecord
|
|||
INSTANCE_ACTOR_ID = -99
|
||||
|
||||
USERNAME_RE = /[a-z0-9_]+([a-z0-9_.-]+[a-z0-9_]+)?/i
|
||||
MENTION_RE = %r{(?<![=/[:word:]])@((#{USERNAME_RE})(?:@[[:word:].-]+[[:word:]]+)?)}i
|
||||
MENTION_RE = %r{(?<![=/[:word:]])@((#{USERNAME_RE})(?:@[[:word:].-]+[[:word:]]+)?)}
|
||||
URL_PREFIX_RE = %r{\Ahttp(s?)://[^/]+}
|
||||
USERNAME_ONLY_RE = /\A#{USERNAME_RE}\z/i
|
||||
USERNAME_LENGTH_LIMIT = 30
|
||||
|
|
74
app/models/admin/tag_filter.rb
Normal file
74
app/models/admin/tag_filter.rb
Normal file
|
@ -0,0 +1,74 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Admin::TagFilter
|
||||
KEYS = %i(
|
||||
status
|
||||
name
|
||||
order
|
||||
).freeze
|
||||
|
||||
attr_reader :params
|
||||
|
||||
def initialize(params)
|
||||
@params = params.to_h.symbolize_keys
|
||||
end
|
||||
|
||||
def results
|
||||
scope = Tag.reorder(nil)
|
||||
|
||||
params.each do |key, value|
|
||||
next if key == :page
|
||||
|
||||
scope.merge!(scope_for(key, value)) if value.present?
|
||||
end
|
||||
|
||||
scope
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def scope_for(key, value)
|
||||
case key
|
||||
when :status
|
||||
status_scope(value)
|
||||
when :name
|
||||
Tag.search_for(value.to_s.strip, params[:limit], params[:offset], exclude_unlistable: false)
|
||||
when :order
|
||||
order_scope(value)
|
||||
else
|
||||
raise Mastodon::InvalidParameterError, "Unknown filter: #{key}"
|
||||
end
|
||||
end
|
||||
|
||||
def status_scope(value)
|
||||
case value.to_s
|
||||
when 'reviewed'
|
||||
Tag.reviewed
|
||||
when 'review_requested'
|
||||
Tag.pending_review
|
||||
when 'unreviewed'
|
||||
Tag.unreviewed
|
||||
when 'trendable'
|
||||
Tag.trendable
|
||||
when 'not_trendable'
|
||||
Tag.not_trendable
|
||||
when 'usable'
|
||||
Tag.usable
|
||||
when 'not_usable'
|
||||
Tag.not_usable
|
||||
else
|
||||
raise Mastodon::InvalidParameterError, "Unknown status: #{value}"
|
||||
end
|
||||
end
|
||||
|
||||
def order_scope(value)
|
||||
case value.to_s
|
||||
when 'newest'
|
||||
Tag.order(created_at: :desc)
|
||||
when 'oldest'
|
||||
Tag.order(created_at: :asc)
|
||||
else
|
||||
raise Mastodon::InvalidParameterError, "Unknown order: #{value}"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -39,7 +39,7 @@ class Tag < ApplicationRecord
|
|||
HASHTAG_LAST_SEQUENCE = '([[:word:]_]*[[:alpha:]][[:word:]_]*)'
|
||||
HASHTAG_NAME_PAT = "#{HASHTAG_FIRST_SEQUENCE}|#{HASHTAG_LAST_SEQUENCE}"
|
||||
|
||||
HASHTAG_RE = %r{(?<![=/)\p{Alnum}])#(#{HASHTAG_NAME_PAT})}i
|
||||
HASHTAG_RE = %r{(?<![=/)\p{Alnum}])#(#{HASHTAG_NAME_PAT})}
|
||||
HASHTAG_NAME_RE = /\A(#{HASHTAG_NAME_PAT})\z/i
|
||||
HASHTAG_INVALID_CHARS_RE = /[^[:alnum:]\u0E47-\u0E4E#{HASHTAG_SEPARATORS}]/
|
||||
|
||||
|
@ -54,6 +54,7 @@ class Tag < ApplicationRecord
|
|||
scope :unreviewed, -> { where(reviewed_at: nil) }
|
||||
scope :pending_review, -> { unreviewed.where.not(requested_review_at: nil) }
|
||||
scope :usable, -> { where(usable: [true, nil]) }
|
||||
scope :not_usable, -> { where(usable: false) }
|
||||
scope :listable, -> { where(listable: [true, nil]) }
|
||||
scope :trendable, -> { Setting.trendable_by_default ? where(trendable: [true, nil]) : where(trendable: true) }
|
||||
scope :not_trendable, -> { where(trendable: false) }
|
||||
|
@ -76,6 +77,10 @@ class Tag < ApplicationRecord
|
|||
attributes['display_name'] || name
|
||||
end
|
||||
|
||||
def formatted_name
|
||||
"##{display_name}"
|
||||
end
|
||||
|
||||
def usable
|
||||
boolean_with_default('usable', true)
|
||||
end
|
||||
|
@ -134,8 +139,10 @@ class Tag < ApplicationRecord
|
|||
|
||||
def search_for(term, limit = 5, offset = 0, options = {})
|
||||
stripped_term = term.strip
|
||||
options.reverse_merge!({ exclude_unlistable: true, exclude_unreviewed: false })
|
||||
|
||||
query = Tag.listable.matches_name(stripped_term)
|
||||
query = Tag.matches_name(stripped_term)
|
||||
query = query.merge(Tag.listable) if options[:exclude_unlistable]
|
||||
query = query.merge(matching_name(stripped_term).or(where.not(reviewed_at: nil))) if options[:exclude_unreviewed]
|
||||
|
||||
query.order(Arel.sql('length(name) ASC, name ASC'))
|
||||
|
|
|
@ -120,6 +120,7 @@ class User < ApplicationRecord
|
|||
scope :pending, -> { where(approved: false) }
|
||||
scope :approved, -> { where(approved: true) }
|
||||
scope :confirmed, -> { where.not(confirmed_at: nil) }
|
||||
scope :unconfirmed, -> { where(confirmed_at: nil) }
|
||||
scope :enabled, -> { where(disabled: false) }
|
||||
scope :disabled, -> { where(disabled: true) }
|
||||
scope :active, -> { confirmed.signed_in_recently.account_not_suspended }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue