From 0d5acfc3fb806169c993ace3876409f06c2aba1d Mon Sep 17 00:00:00 2001 From: Fosco Marotto Date: Sun, 14 Feb 2021 14:10:25 -0500 Subject: [PATCH] Update push subscription writing role --- app/models/web/push_subscription.rb | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/app/models/web/push_subscription.rb b/app/models/web/push_subscription.rb index b57807d1..3e1f1e04 100644 --- a/app/models/web/push_subscription.rb +++ b/app/models/web/push_subscription.rb @@ -52,10 +52,12 @@ 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) + ActiveRecord::Base.connected_to(role: :writing) do + 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 @@ -89,12 +91,14 @@ class Web::PushSubscription < ApplicationRecord end def find_or_create_access_token - Doorkeeper::AccessToken.find_or_create_for( - Doorkeeper::Application.find_by(superapp: true), - session_activation.user_id, - Doorkeeper::OAuth::Scopes.from_string('read write follow push'), - Doorkeeper.configuration.access_token_expires_in, - Doorkeeper.configuration.refresh_token_enabled? - ) + ActiveRecord::Base.connected_to(role: :writing) do + Doorkeeper::AccessToken.find_or_create_for( + Doorkeeper::Application.find_by(superapp: true), + session_activation.user_id, + Doorkeeper::OAuth::Scopes.from_string('read write follow push'), + Doorkeeper.configuration.access_token_expires_in, + Doorkeeper.configuration.refresh_token_enabled? + ) + end end end