Update push subscription writing role

This commit is contained in:
Fosco Marotto 2021-02-14 14:10:25 -05:00
parent 09ba5c9be8
commit 0d5acfc3fb
1 changed files with 14 additions and 10 deletions

View File

@ -52,10 +52,12 @@ class Web::PushSubscription < ApplicationRecord
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, revoked_at: nil) ActiveRecord::Base.connected_to(role: :writing) do
.pluck(:id) access_token_ids = Doorkeeper::AccessToken.where(application_id: application_id, resource_owner_id: resource_owner.id, revoked_at: nil)
.pluck(:id)
where(access_token_id: access_token_ids).delete_all where(access_token_id: access_token_ids).delete_all
end
end end
end end
@ -89,12 +91,14 @@ class Web::PushSubscription < ApplicationRecord
end end
def find_or_create_access_token def find_or_create_access_token
Doorkeeper::AccessToken.find_or_create_for( ActiveRecord::Base.connected_to(role: :writing) do
Doorkeeper::Application.find_by(superapp: true), Doorkeeper::AccessToken.find_or_create_for(
session_activation.user_id, Doorkeeper::Application.find_by(superapp: true),
Doorkeeper::OAuth::Scopes.from_string('read write follow push'), session_activation.user_id,
Doorkeeper.configuration.access_token_expires_in, Doorkeeper::OAuth::Scopes.from_string('read write follow push'),
Doorkeeper.configuration.refresh_token_enabled? Doorkeeper.configuration.access_token_expires_in,
) Doorkeeper.configuration.refresh_token_enabled?
)
end
end end
end end