2016-08-10 10:54:23 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2016-11-28 13:01:06 +01:00
|
|
|
import logging
|
|
|
|
from flask import current_app
|
2016-08-10 18:27:27 +02:00
|
|
|
from pillar import cli
|
2016-12-01 11:39:31 +01:00
|
|
|
from pillar.cli import manager_maintenance
|
2016-08-10 18:27:27 +02:00
|
|
|
from cloud import app
|
2016-08-10 10:54:23 +02:00
|
|
|
|
2016-11-28 13:01:06 +01:00
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2016-12-01 11:39:31 +01:00
|
|
|
@manager_maintenance.command
|
2016-11-28 13:01:06 +01:00
|
|
|
def reconcile_subscribers():
|
|
|
|
"""For every user, check their subscription status with the store."""
|
|
|
|
from pillar.auth.subscriptions import fetch_user
|
|
|
|
|
|
|
|
users_coll = current_app.data.driver.db['users']
|
|
|
|
unsubscribed_users = []
|
2016-11-28 14:37:53 +01:00
|
|
|
for user in users_coll.find({'roles': 'subscriber'}):
|
2016-11-28 13:01:06 +01:00
|
|
|
print('Processing %s' % user['email'])
|
2016-11-28 14:37:53 +01:00
|
|
|
print(' Checking subscription')
|
|
|
|
user_store = fetch_user(user['email'])
|
|
|
|
if user_store['cloud_access'] == 0:
|
|
|
|
print(' Removing subscriber role')
|
|
|
|
users_coll.update(
|
|
|
|
{'_id': user['_id']},
|
|
|
|
{'$pull': {'roles': 'subscriber'}})
|
|
|
|
unsubscribed_users.append(user['email'])
|
2016-11-28 13:01:06 +01:00
|
|
|
|
|
|
|
if not unsubscribed_users:
|
|
|
|
return
|
|
|
|
|
|
|
|
print('The following users have been unsubscribed')
|
|
|
|
for user in unsubscribed_users:
|
|
|
|
print(user)
|
|
|
|
|
2016-08-10 18:27:27 +02:00
|
|
|
cli.manager.app = app
|
|
|
|
cli.manager.run()
|