Merge commit '6268188543
' into kb_migration
This commit is contained in:
commit
850c4dfb3c
133 changed files with 1644 additions and 947 deletions
|
@ -117,7 +117,7 @@ class Account < ApplicationRecord
|
|||
scope :matches_username, ->(value) { where('lower((username)::text) ~ lower(?)', value.to_s) }
|
||||
scope :matches_display_name, ->(value) { where(arel_table[:display_name].matches_regexp(value.to_s)) }
|
||||
scope :matches_domain, ->(value) { where(arel_table[:domain].matches("%#{value}%")) }
|
||||
scope :without_unapproved, -> { left_outer_joins(:user).remote.or(left_outer_joins(:user).merge(User.approved.confirmed)) }
|
||||
scope :without_unapproved, -> { left_outer_joins(:user).merge(User.approved.confirmed).or(remote) }
|
||||
scope :searchable, -> { without_unapproved.without_suspended.where(moved_to_account_id: nil) }
|
||||
scope :discoverable, -> { searchable.without_silenced.where(discoverable: true).left_outer_joins(:account_stat) }
|
||||
scope :followable_by, ->(account) { joins(arel_table.join(Follow.arel_table, Arel::Nodes::OuterJoin).on(arel_table[:id].eq(Follow.arel_table[:target_account_id]).and(Follow.arel_table[:account_id].eq(account.id))).join_sources).where(Follow.arel_table[:id].eq(nil)).joins(arel_table.join(FollowRequest.arel_table, Arel::Nodes::OuterJoin).on(arel_table[:id].eq(FollowRequest.arel_table[:target_account_id]).and(FollowRequest.arel_table[:account_id].eq(account.id))).join_sources).where(FollowRequest.arel_table[:id].eq(nil)) }
|
||||
|
|
|
@ -106,6 +106,17 @@ module AccountSearch
|
|||
LIMIT :limit OFFSET :offset
|
||||
SQL
|
||||
|
||||
def searchable_text
|
||||
PlainTextFormatter.new(note, local?).to_s if discoverable?
|
||||
end
|
||||
|
||||
def searchable_properties
|
||||
[].tap do |properties|
|
||||
properties << 'bot' if bot?
|
||||
properties << 'verified' if fields.any?(&:verified?)
|
||||
end
|
||||
end
|
||||
|
||||
class_methods do
|
||||
def search_for(terms, limit: 10, offset: 0)
|
||||
tsquery = generate_query_for_search(terms)
|
||||
|
|
|
@ -24,6 +24,8 @@ class Webhook < ApplicationRecord
|
|||
status.updated
|
||||
).freeze
|
||||
|
||||
attr_writer :current_account
|
||||
|
||||
scope :enabled, -> { where(enabled: true) }
|
||||
|
||||
validates :url, presence: true, url: true
|
||||
|
@ -31,6 +33,7 @@ class Webhook < ApplicationRecord
|
|||
validates :events, presence: true
|
||||
|
||||
validate :validate_events
|
||||
validate :validate_permissions
|
||||
validate :validate_template
|
||||
|
||||
before_validation :strip_events
|
||||
|
@ -48,12 +51,31 @@ class Webhook < ApplicationRecord
|
|||
update!(enabled: false)
|
||||
end
|
||||
|
||||
def required_permissions
|
||||
events.map { |event| Webhook.permission_for_event(event) }
|
||||
end
|
||||
|
||||
def self.permission_for_event(event)
|
||||
case event
|
||||
when 'account.approved', 'account.created', 'account.updated'
|
||||
:manage_users
|
||||
when 'report.created'
|
||||
:manage_reports
|
||||
when 'status.created', 'status.updated'
|
||||
:view_devops
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def validate_events
|
||||
errors.add(:events, :invalid) if events.any? { |e| EVENTS.exclude?(e) }
|
||||
end
|
||||
|
||||
def validate_permissions
|
||||
errors.add(:events, :invalid_permissions) if defined?(@current_account) && required_permissions.any? { |permission| !@current_account.user_role.can?(permission) }
|
||||
end
|
||||
|
||||
def validate_template
|
||||
return if template.blank?
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue