Skip to content

Commit 419ae2b

Browse files
author
Gabriel Monroy
committed
Merge pull request #332 from opdemand/331-cm-purge-user
Implemented missing chef.purge_user() and connected it to a signal.
2 parents 43b0086 + 8ce7fa0 commit 419ae2b

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

api/models.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from django.conf import settings
1616
from django.contrib.auth.models import User
1717
from django.db import models
18+
from django.db.models.signals import post_delete
1819
from django.db.models.signals import post_save
1920
from django.dispatch import receiver
2021
from django.dispatch.dispatcher import Signal
@@ -818,10 +819,15 @@ def _user_publish(self):
818819
CM.publish_user(self.flat(), self.calculate())
819820

820821

822+
def _user_purge(self):
823+
CM.purge_user(self.flat())
824+
825+
821826
# attach to built-in django user
822827
User.flat = _user_flat
823828
User.calculate = _user_calculate
824829
User.publish = _user_publish
830+
User.purge = _user_purge
825831

826832
# define update/delete callbacks for synchronizing
827833
# models with the configuration management backend
@@ -836,8 +842,14 @@ def _publish_user_to_cm(**kwargs):
836842
return
837843
kwargs['instance'].publish()
838844

845+
846+
def _purge_user_from_cm(**kwargs):
847+
kwargs['instance'].purge()
848+
849+
839850
# use django signals to synchronize database updates with
840851
# the configuration management backend
841852
post_save.connect(_publish_to_cm, sender=App, dispatch_uid='api.models')
842853
post_save.connect(_publish_to_cm, sender=Formation, dispatch_uid='api.models')
843854
post_save.connect(_publish_user_to_cm, sender=User, dispatch_uid='api.models')
855+
post_delete.connect(_purge_user_from_cm, sender=User, dispatch_uid='api.models')

cm/chef.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,17 @@ def publish_user(user, data):
236236
_publish('deis-users', user['username'], data)
237237

238238

239+
def purge_user(user):
240+
"""
241+
Purge a user from configuration management.
242+
243+
:param app: a dict containing the username of the user
244+
:returns: a tuple of (body, status) from the underlying HTTP response
245+
:raises: RuntimeError
246+
"""
247+
_purge('deis-users', user['username'])
248+
249+
239250
def publish_app(app, data):
240251
"""
241252
Publish an app to configuration management.

0 commit comments

Comments
 (0)