mirror of
https://github.com/glitch-soc/mastodon.git
synced 2026-03-29 03:00:33 +02:00
Use delegate in web/push_subscription model for token value (#38313)
This commit is contained in:
@@ -29,6 +29,7 @@ class Web::PushSubscription < ApplicationRecord
|
||||
validates_with WebPushKeyValidator
|
||||
|
||||
delegate :locale, to: :user
|
||||
delegate :token, to: :access_token, prefix: :associated_access
|
||||
|
||||
generates_token_for :unsubscribe, expires_in: Web::PushNotificationWorker::TTL
|
||||
|
||||
@@ -36,10 +37,6 @@ class Web::PushSubscription < ApplicationRecord
|
||||
policy_allows_notification?(notification) && alert_enabled_for_notification_type?(notification)
|
||||
end
|
||||
|
||||
def associated_access_token
|
||||
access_token.token
|
||||
end
|
||||
|
||||
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).not_revoked.pluck(:id)
|
||||
|
||||
@@ -93,4 +93,8 @@ RSpec.describe Web::PushSubscription do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Delegations' do
|
||||
it { is_expected.to delegate_method(:token).to(:access_token).with_prefix(:associated_access) }
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user