From 8378b72ebacc51e5e090faa527462b801e4c2803 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sat, 19 May 2018 21:05:08 +0200 Subject: Ensure push subscription is immediately removed when application is revoked (#7548) * Ensure push subscription is immediately removed when application is revoked * When token is revoked from app, unsubscribe too --- app/models/web/push_subscription.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'app/models/web') diff --git a/app/models/web/push_subscription.rb b/app/models/web/push_subscription.rb index 7da3428fe..867bc9519 100644 --- a/app/models/web/push_subscription.rb +++ b/app/models/web/push_subscription.rb @@ -50,6 +50,15 @@ class Web::PushSubscription < ApplicationRecord end 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, revoked_at: nil) + .pluck(:id) + + where(access_token_id: access_token_ids).delete_all + end + end + private def push_payload(message, ttl = 5.minutes.seconds) -- cgit