-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from bossan/feature/site-user-created-signal
Added signal to create user cert when assigned to site
- Loading branch information
Showing
6 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,3 +154,4 @@ | |
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' | ||
|
||
SIGN_PROFILES = True | ||
GENERATE_CERT_ON_CREATE = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from .site_created import after_site_created | ||
from .site_user_created import after_site_user_created |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from django.conf import settings | ||
from django.db import models | ||
from django.dispatch import receiver | ||
|
||
from pki.models import SiteUser, CertificateAuthority | ||
|
||
import pki.services.certificate | ||
|
||
|
||
@receiver(models.signals.post_save, sender=SiteUser) | ||
def after_site_user_created(sender, instance: SiteUser, created: bool, *args, **kwargs): # noqa | ||
if not created or not getattr(settings, 'GENERATE_CERT_ON_CREATE', False): | ||
return | ||
|
||
ca = CertificateAuthority.objects.filter(site_id=instance.site_id).first() | ||
|
||
if ca: | ||
pki.services.certificate.generate_cert_for_user(user=instance.user, ca=ca) |