update user account across deployments when user record is updated
diff --git a/planetstack/observer/steps/sync_user_deployments.py b/planetstack/observer/steps/sync_user_deployments.py
index cbbcb17..7110a0b 100644
--- a/planetstack/observer/steps/sync_user_deployments.py
+++ b/planetstack/observer/steps/sync_user_deployments.py
@@ -29,7 +29,6 @@
for user_deployment in UserDeployments.objects.all():
user_deploy_lookup[user_deployment.user].append(user_deployment.deployment)
- user_deployments = []
all_deployments = Deployment.objects.filter()
for user in User.objects.all():
if user.is_admin:
@@ -45,13 +44,14 @@
expected_deployment not in user_deploy_lookup[user]:
# add new record
ud = UserDeployments(user=user, deployment=expected_deployment)
- user_deployments.append(ud)
+ ud.save()
+ #user_deployments.append(ud)
#else:
# # update existing record
# ud = UserDeployments.objects.get(user=user, deployment=expected_deployment)
# user_deployments.append(ud)
- return user_deployments
+ return UserDeployments.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
def sync_record(self, user_deployment):
logger.info("sync'ing user %s at deployment %s" % (user_deployment.user, user_deployment.deployment.name))
diff --git a/planetstack/observer/steps/sync_users.py b/planetstack/observer/steps/sync_users.py
index 2550104..71f9c0f 100644
--- a/planetstack/observer/steps/sync_users.py
+++ b/planetstack/observer/steps/sync_users.py
@@ -4,7 +4,7 @@
from django.db.models import F, Q
from planetstack.config import Config
from observer.openstacksyncstep import OpenStackSyncStep
-from core.models.user import User
+from core.models.user import User, UserDeployments
class SyncUsers(OpenStackSyncStep):
provides=[User]
@@ -14,5 +14,7 @@
return User.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
def sync_record(self, user):
- #user.save()
- pass
+ for user_deployment in UserDeployments.objects.filter(user=user):
+ # bump the 'updated' field so user account are updated across
+ # deployments.
+ user_deployment.save()