Send a Blinker signal when someone's subscription status changes
This is very close to the 'roles changed' signal, with the difference that it is sent only once for multiple role changes.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import logging
|
||||
import typing
|
||||
|
||||
import blinker
|
||||
from flask import Blueprint, Response
|
||||
import requests
|
||||
from requests.adapters import HTTPAdapter
|
||||
@@ -21,6 +22,10 @@ ROLES_BID_TO_PILLAR = {
|
||||
'cloud_has_subscription': 'has_subscription',
|
||||
}
|
||||
|
||||
user_subscription_updated = blinker.NamedSignal(
|
||||
'user_subscription_updated',
|
||||
'The sender is a UserClass instance, kwargs includes "revoke_roles" and "grant_roles".')
|
||||
|
||||
|
||||
@blueprint.route('/update-subscription')
|
||||
@authorization.require_login()
|
||||
@@ -157,6 +162,14 @@ def do_update_subscription(local_user: auth.UserClass, bid_user: dict):
|
||||
user_id, email, ', '.join(sorted(revoke_roles)))
|
||||
service.do_badger('revoke', roles=revoke_roles, user_id=user_id)
|
||||
|
||||
# Let the world know this user's subscription was updated.
|
||||
final_roles = (plr_roles - revoke_roles).union(grant_roles)
|
||||
local_user.roles = list(final_roles)
|
||||
local_user.collect_capabilities()
|
||||
user_subscription_updated.send(local_user,
|
||||
grant_roles=grant_roles,
|
||||
revoke_roles=revoke_roles)
|
||||
|
||||
# Re-index the user in the search database.
|
||||
from pillar.api.users import hooks
|
||||
hooks.push_updated_user_to_algolia({'_id': user_id}, {})
|
||||
|
Reference in New Issue
Block a user