From 33fee98309cf841dcc697230a854c66ee6419fbf Mon Sep 17 00:00:00 2001 From: nate Date: Thu, 22 Feb 2018 16:38:10 -0800 Subject: [PATCH] handle pubkey post save more gracefully --- ttadmin/users/models.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ttadmin/users/models.py b/ttadmin/users/models.py index 182b513..bcfdf50 100644 --- a/ttadmin/users/models.py +++ b/ttadmin/users/models.py @@ -165,7 +165,17 @@ class Pubkey(Model): @receiver(post_save, sender=Pubkey) def on_pubkey_post_save(sender, instance, **kwargs): - instance.townie.write_authorized_keys() + # Ensure we're checking the townie as it exists at the point of pubkey + # save. If a user is being reviewed, we'll write their key file in the + # townie pre save. + townie = Townie.objects.filter(username=instance.townie.username) + if not townie: + return + + townie = townie[0] + + if townie.reviewed: + townie.write_authorized_keys() @receiver(pre_save, sender=Townie)