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): ...@@ -211,6 +211,14 @@ class SSHPublicKey(models.Model):
for deployment in self.deployments.all(): for deployment in self.deployments.all():
deployment.withdraw_key(self) 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): def __str__(self):
if self.deleted: if self.deleted:
return "DELETED: {}".format(self.name) return "DELETED: {}".format(self.name)
...@@ -219,14 +227,15 @@ class SSHPublicKey(models.Model): ...@@ -219,14 +227,15 @@ class SSHPublicKey(models.Model):
# finally delete the key if all the deployments are withdrawn # finally delete the key if all the deployments are withdrawn
# and the withdrawal was seen by all clients # and the withdrawal was seen by all clients
@receiver(m2m_changed, sender=SSHPublicKey) # @receiver(m2m_changed, sender=SSHPublicKey)
def delete_withdrawn_ssh_key( # def delete_withdrawn_ssh_key(
sender, instance=None, created=False, **kwargs): # sender, instance=None, created=False, **kwargs):
#
if (instance.deleted # if (instance.deleted
and not instance.deployments.exists() # and not instance.deployments.exists()
and not instance.withdrawn_deployments.exists()): # and not instance.withdrawn_deployments.exists()):
instance.delete() # # TODO this does not work (see the m2m_changed signal doc)
# instance.delete()
class Deployment(models.Model): class Deployment(models.Model):
...@@ -279,20 +288,22 @@ class Deployment(models.Model): ...@@ -279,20 +288,22 @@ class Deployment(models.Model):
self.save() self.save()
self.send_change() 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 # the client has withdrawn the keys so we can empty the list
self.ssh_keys_to_withdraw.clear() 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() self.save()
def send_change(self): def send_change(self):
deployment_change.send(sender=self.__class__, instance=self) deployment_change.send(sender=self.__class__, instance=self)
def __str__(self):
return '{}@{}'.format(self.user, self.service)
@receiver(post_save, sender=Deployment) # @receiver(post_save, sender=Deployment)
def publish_deployment_creation( # def publish_deployment_creation(
sender, instance=None, created=False, **kwargs): # sender, instance=None, created=False, **kwargs):
instance.send_change() # 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