Merge remote-tracking branch 'parent/main' into upstream-20240618
This commit is contained in:
commit
aa2cdc898a
271 changed files with 1839 additions and 1397 deletions
|
@ -18,6 +18,8 @@
|
|||
class Appeal < ApplicationRecord
|
||||
MAX_STRIKE_AGE = 20.days
|
||||
|
||||
TEXT_LENGTH_LIMIT = 2_000
|
||||
|
||||
belongs_to :account
|
||||
belongs_to :strike, class_name: 'AccountWarning', foreign_key: 'account_warning_id', inverse_of: :appeal
|
||||
|
||||
|
@ -26,7 +28,7 @@ class Appeal < ApplicationRecord
|
|||
belongs_to :rejected_by_account
|
||||
end
|
||||
|
||||
validates :text, presence: true, length: { maximum: 2_000 }
|
||||
validates :text, presence: true, length: { maximum: TEXT_LENGTH_LIMIT }
|
||||
validates :account_warning_id, uniqueness: true
|
||||
|
||||
validate :validate_time_frame, on: :create
|
||||
|
|
|
@ -181,6 +181,7 @@ class Notification < ApplicationRecord
|
|||
.limit(1),
|
||||
query
|
||||
.joins('CROSS JOIN grouped_notifications')
|
||||
.where('array_length(grouped_notifications.groups, 1) < :limit', limit: limit)
|
||||
.where('notifications.id < grouped_notifications.id')
|
||||
.where.not("COALESCE(notifications.group_key, 'ungrouped-' || notifications.id) = ANY(grouped_notifications.groups)")
|
||||
.select('notifications.*', "array_append(grouped_notifications.groups, COALESCE(notifications.group_key, 'ungrouped-' || notifications.id))")
|
||||
|
@ -208,6 +209,7 @@ class Notification < ApplicationRecord
|
|||
.limit(1),
|
||||
query
|
||||
.joins('CROSS JOIN grouped_notifications')
|
||||
.where('array_length(grouped_notifications.groups, 1) < :limit', limit: limit)
|
||||
.where('notifications.id > grouped_notifications.id')
|
||||
.where.not("COALESCE(notifications.group_key, 'ungrouped-' || notifications.id) = ANY(grouped_notifications.groups)")
|
||||
.select('notifications.*', "array_append(grouped_notifications.groups, COALESCE(notifications.group_key, 'ungrouped-' || notifications.id))")
|
||||
|
|
|
@ -1,14 +1,17 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class NotificationGroup < ActiveModelSerializers::Model
|
||||
attributes :group_key, :sample_accounts, :notifications_count, :notification
|
||||
attributes :group_key, :sample_accounts, :notifications_count, :notification, :most_recent_notification_id
|
||||
|
||||
def self.from_notification(notification)
|
||||
if notification.group_key.present?
|
||||
# TODO: caching and preloading
|
||||
sample_accounts = notification.account.notifications.where(group_key: notification.group_key).order(id: :desc).limit(3).map(&:from_account)
|
||||
most_recent_notifications = notification.account.notifications.where(group_key: notification.group_key).order(id: :desc).take(3)
|
||||
most_recent_id = most_recent_notifications.first.id
|
||||
sample_accounts = most_recent_notifications.map(&:from_account)
|
||||
notifications_count = notification.account.notifications.where(group_key: notification.group_key).count
|
||||
else
|
||||
most_recent_id = notification.id
|
||||
sample_accounts = [notification.from_account]
|
||||
notifications_count = 1
|
||||
end
|
||||
|
@ -17,7 +20,8 @@ class NotificationGroup < ActiveModelSerializers::Model
|
|||
notification: notification,
|
||||
group_key: notification.group_key || "ungrouped-#{notification.id}",
|
||||
sample_accounts: sample_accounts,
|
||||
notifications_count: notifications_count
|
||||
notifications_count: notifications_count,
|
||||
most_recent_notification_id: most_recent_id
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ class Web::PushSubscription < ApplicationRecord
|
|||
|
||||
class << self
|
||||
def unsubscribe_for(application_id, resource_owner)
|
||||
access_token_ids = Doorkeeper::AccessToken.where(application_id: application_id, resource_owner_id: resource_owner.id, revoked_at: nil).pluck(:id)
|
||||
access_token_ids = Doorkeeper::AccessToken.where(application_id: application_id, resource_owner_id: resource_owner.id).not_revoked.pluck(:id)
|
||||
where(access_token_id: access_token_ids).delete_all
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,9 +15,11 @@
|
|||
#
|
||||
|
||||
class WebauthnCredential < ApplicationRecord
|
||||
SIGN_COUNT_LIMIT = (2**63)
|
||||
|
||||
validates :external_id, :public_key, :nickname, :sign_count, presence: true
|
||||
validates :external_id, uniqueness: true
|
||||
validates :nickname, uniqueness: { scope: :user_id }
|
||||
validates :sign_count,
|
||||
numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: (2**63) - 1 }
|
||||
numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: SIGN_COUNT_LIMIT - 1 }
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue