Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
django-sshkey
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
b56c4574
authored
Oct 09, 2014
by
Paul Kilgo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
delete underlying key when UserKey is deleted
parent
a2c39f38
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
1 deletions
+19
-1
django_sshkey/models.py
+5
-1
django_sshkey/tests.py
+14
-0
No files found.
django_sshkey/models.py
View file @
b56c4574
...
@@ -29,7 +29,7 @@
...
@@ -29,7 +29,7 @@
from
django.db
import
models
from
django.db
import
models
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
django.core.exceptions
import
ValidationError
from
django.core.exceptions
import
ValidationError
from
django.db.models.signals
import
pre_save
from
django.db.models.signals
import
pre_save
,
post_delete
from
django.dispatch
import
receiver
from
django.dispatch
import
receiver
try
:
try
:
from
django.utils.timezone
import
now
from
django.utils.timezone
import
now
...
@@ -178,6 +178,10 @@ class UserKey(NamedKey):
...
@@ -178,6 +178,10 @@ class UserKey(NamedKey):
message
=
'Cannot associate key with two users.'
message
=
'Cannot associate key with two users.'
raise
ValidationError
({
'basekey'
:
[
message
]})
raise
ValidationError
({
'basekey'
:
[
message
]})
@receiver
(
post_delete
,
sender
=
UserKey
)
def
delete_user_key
(
sender
,
instance
,
**
kwargs
):
instance
.
basekey
.
delete
()
@receiver
(
pre_save
,
sender
=
UserKey
)
@receiver
(
pre_save
,
sender
=
UserKey
)
def
send_email_add_key
(
sender
,
instance
,
**
kwargs
):
def
send_email_add_key
(
sender
,
instance
,
**
kwargs
):
if
not
settings
.
SSHKEY_EMAIL_ADD_KEY
or
instance
.
pk
:
if
not
settings
.
SSHKEY_EMAIL_ADD_KEY
or
instance
.
pk
:
...
...
django_sshkey/tests.py
View file @
b56c4574
...
@@ -310,6 +310,10 @@ class UserKeyTestCase(BaseTestCase):
...
@@ -310,6 +310,10 @@ class UserKeyTestCase(BaseTestCase):
cls
.
key2_path
=
os
.
path
.
join
(
cls
.
key_dir
,
'key2'
)
cls
.
key2_path
=
os
.
path
.
join
(
cls
.
key_dir
,
'key2'
)
ssh_keygen
(
comment
=
''
,
file
=
cls
.
key2_path
)
ssh_keygen
(
comment
=
''
,
file
=
cls
.
key2_path
)
# key3 is safe to delete
cls
.
key3_path
=
os
.
path
.
join
(
cls
.
key_dir
,
'key3'
)
ssh_keygen
(
comment
=
'comment'
,
file
=
cls
.
key3_path
)
# make the Key models
# make the Key models
cls
.
key1
=
Key
(
key
=
open
(
cls
.
key1_path
+
'.pub'
)
.
read
())
cls
.
key1
=
Key
(
key
=
open
(
cls
.
key1_path
+
'.pub'
)
.
read
())
cls
.
key1
.
full_clean
()
cls
.
key1
.
full_clean
()
...
@@ -385,7 +389,17 @@ class UserKeyTestCase(BaseTestCase):
...
@@ -385,7 +389,17 @@ class UserKeyTestCase(BaseTestCase):
)
)
self
.
assertRaises
(
ValidationError
,
key2
.
full_clean
)
self
.
assertRaises
(
ValidationError
,
key2
.
full_clean
)
def
test_delete
(
self
):
basekey
=
Key
(
key
=
open
(
self
.
key3_path
+
'.pub'
)
.
read
())
basekey
.
full_clean
()
basekey
.
save
()
pk
=
basekey
.
pk
key1
=
UserKey
(
basekey
=
basekey
,
user
=
self
.
user1
,
name
=
'name1'
)
key1
.
full_clean
()
key1
.
save
()
key1
.
delete
()
self
.
assertRaises
(
Key
.
DoesNotExist
,
Key
.
objects
.
get
,
pk
=
pk
)
class
RFC4716TestCase
(
BaseTestCase
):
class
RFC4716TestCase
(
BaseTestCase
):
@classmethod
@classmethod
...
...
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