diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2018-05-19 21:05:08 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-19 21:05:08 +0200 |
commit | 8378b72ebacc51e5e090faa527462b801e4c2803 (patch) | |
tree | 92deefbf0e199119a486055ac18774d5a5b410f0 /app/models/web | |
parent | 5910eb9b61da6eacf6b534d831da6e2f698e2703 (diff) |
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
Diffstat (limited to 'app/models/web')
-rw-r--r-- | app/models/web/push_subscription.rb | 9 |
1 files changed, 9 insertions, 0 deletions
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) |