Commit eb982786 authored by Lukas Burgey's avatar Lukas Burgey
Browse files

Changed message sending

parent 4facb1c4
......@@ -211,6 +211,14 @@ class SSHPublicKey(models.Model):
for deployment in self.deployments.all():
deployment.withdraw_key(self)
# when a key is withdrawn by a client we try to finally delete it
def try_final_deletion(self):
if (self.deleted
and not self.deployments.exists()
and not self.withdrawn_deployments.exists()):
self.delete()
return
def __str__(self):
if self.deleted:
return "DELETED: {}".format(self.name)
......@@ -219,14 +227,15 @@ class SSHPublicKey(models.Model):
# finally delete the key if all the deployments are withdrawn
# and the withdrawal was seen by all clients
@receiver(m2m_changed, sender=SSHPublicKey)
def delete_withdrawn_ssh_key(
sender, instance=None, created=False, **kwargs):
if (instance.deleted
and not instance.deployments.exists()
and not instance.withdrawn_deployments.exists()):
instance.delete()
# @receiver(m2m_changed, sender=SSHPublicKey)
# def delete_withdrawn_ssh_key(
# sender, instance=None, created=False, **kwargs):
#
# if (instance.deleted
# and not instance.deployments.exists()
# and not instance.withdrawn_deployments.exists()):
# # TODO this does not work (see the m2m_changed signal doc)
# instance.delete()
class Deployment(models.Model):
......@@ -279,20 +288,22 @@ class Deployment(models.Model):
self.save()
self.send_change()
def client_got_deployment(self):
def client_updated(self):
withdrawn_keys = list(self.ssh_keys_to_withdraw.all())
# the client has withdrawn the keys so we can empty the list
self.ssh_keys_to_withdraw.clear()
# TODO: does the deletion of the ssh_keys actually occur?
for key in withdrawn_keys:
key.try_final_deletion()
self.save()
def send_change(self):
deployment_change.send(sender=self.__class__, instance=self)
def __str__(self):
return '{}@{}'.format(self.user, self.service)
@receiver(post_save, sender=Deployment)
def publish_deployment_creation(
sender, instance=None, created=False, **kwargs):
instance.send_change()
# @receiver(post_save, sender=Deployment)
# def publish_deployment_creation(
# sender, instance=None, created=False, **kwargs):
# instance.send_change()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment