Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
feudal
feudalBackend
Commits
4b1ae74c
Commit
4b1ae74c
authored
Dec 08, 2017
by
Lukas Burgey
Browse files
Change deletion signal of ssh keys
parent
6be09f81
Changes
1
Hide whitespace changes
Inline
Side-by-side
django_backend/backend/models.py
View file @
4b1ae74c
...
...
@@ -3,7 +3,7 @@ from django.db import models
from
django.conf
import
settings
from
django.dispatch
import
receiver
,
Signal
from
rest_framework.authtoken.models
import
Token
from
django.db.models.signals
import
post_save
from
django.db.models.signals
import
post_save
,
m2m_changed
from
datetime
import
datetime
import
requests
...
...
@@ -186,9 +186,15 @@ class SSHPublicKey(models.Model):
editable
=
False
,
)
# does not directly delete the key, but merely starts the deletion process
# the receiver 'delete_old_ssh_key' does the actual deletion afterwards
# does not directly delete the key if the key is deployed or withdrawn
# somewhere
# the receiver 'delete_withdrawn_ssh_key' does the actual deletion
def
delete_key
(
self
):
if
(
not
self
.
deployments
.
exists
()
and
not
self
.
withdrawn_deployments
.
exists
()):
self
.
delete
()
return
self
.
deleted
=
True
self
.
save
()
...
...
@@ -201,11 +207,15 @@ class SSHPublicKey(models.Model):
return
self
.
name
@
receiver
(
post_save
,
sender
=
SSHPublicKey
)
def
delete_old_ssh_key
(
# 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
len
(
instance
.
deployments
.
all
())
==
0
:
if
(
instance
.
deleted
and
not
instance
.
deployments
.
exists
()
and
not
instance
.
withdrawn_deployments
.
exists
()):
instance
.
delete
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment