CLI reconcile_subscribers uses do_badger & re-grants the subscriber role
This ensures that subscriber-linked roles like flamenco-user are synced along with the subscriber status, and that Algolia picks up on those changes as well.
This commit is contained in:
24
cloud/cli.py
24
cloud/cli.py
@@ -36,26 +36,36 @@ def create_groups():
|
|||||||
@manager_cloud.command
|
@manager_cloud.command
|
||||||
def reconcile_subscribers():
|
def reconcile_subscribers():
|
||||||
"""For every user, check their subscription status with the store."""
|
"""For every user, check their subscription status with the store."""
|
||||||
|
|
||||||
from pillar.api.blender_cloud.subscription import fetch_subscription_info
|
from pillar.api.blender_cloud.subscription import fetch_subscription_info
|
||||||
|
|
||||||
|
service.fetch_role_to_group_id_map()
|
||||||
|
|
||||||
users_coll = current_app.data.driver.db['users']
|
users_coll = current_app.data.driver.db['users']
|
||||||
unsubscribed_users = []
|
unsubscribed_users = []
|
||||||
for user in users_coll.find({'roles': 'subscriber'}):
|
for user in users_coll.find({'roles': 'subscriber'}):
|
||||||
print('Processing %s' % user['email'])
|
log.info('Processing %s' % user['email'])
|
||||||
print(' Checking subscription')
|
|
||||||
user_store = fetch_subscription_info(user['email'])
|
user_store = fetch_subscription_info(user['email'])
|
||||||
if user_store['cloud_access'] == 0:
|
if not user_store:
|
||||||
print(' Removing subscriber role')
|
log.error('Unable to reach store, aborting')
|
||||||
users_coll.update(
|
break
|
||||||
{'_id': user['_id']},
|
|
||||||
{'$pull': {'roles': 'subscriber'}})
|
if not user_store or user_store['cloud_access'] == 0:
|
||||||
|
action = 'revoke'
|
||||||
unsubscribed_users.append(user['email'])
|
unsubscribed_users.append(user['email'])
|
||||||
|
else:
|
||||||
|
action = 'grant'
|
||||||
|
|
||||||
|
service.do_badger(action, 'subscriber', user_id=user['_id'])
|
||||||
|
|
||||||
if not unsubscribed_users:
|
if not unsubscribed_users:
|
||||||
|
log.info('No unsubscribed users')
|
||||||
return
|
return
|
||||||
|
|
||||||
print('The following users have been unsubscribed')
|
print('The following users have been unsubscribed')
|
||||||
for user in unsubscribed_users:
|
for user in unsubscribed_users:
|
||||||
print(user)
|
print(user)
|
||||||
|
|
||||||
|
|
||||||
manager.add_command("cloud", manager_cloud)
|
manager.add_command("cloud", manager_cloud)
|
||||||
|
Reference in New Issue
Block a user