Use delegate in web/push_subscription model for token value (#38313)
This commit is contained in:
parent
7aa696149f
commit
24d3c94f4a
@ -29,6 +29,7 @@ class Web::PushSubscription < ApplicationRecord
|
|||||||
validates_with WebPushKeyValidator
|
validates_with WebPushKeyValidator
|
||||||
|
|
||||||
delegate :locale, to: :user
|
delegate :locale, to: :user
|
||||||
|
delegate :token, to: :access_token, prefix: :associated_access
|
||||||
|
|
||||||
generates_token_for :unsubscribe, expires_in: Web::PushNotificationWorker::TTL
|
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)
|
policy_allows_notification?(notification) && alert_enabled_for_notification_type?(notification)
|
||||||
end
|
end
|
||||||
|
|
||||||
def associated_access_token
|
|
||||||
access_token.token
|
|
||||||
end
|
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def unsubscribe_for(application_id, resource_owner)
|
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)
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'Delegations' do
|
||||||
|
it { is_expected.to delegate_method(:token).to(:access_token).with_prefix(:associated_access) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user