-
Notifications
You must be signed in to change notification settings - Fork 6
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 #952 from maykinmedia/fix/2014-retrieve-rsin
🐛 [#2014] Fix retrieval of RSIN for KVK after login
- Loading branch information
Showing
3 changed files
with
37 additions
and
40 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 |
---|---|---|
@@ -1,36 +1,36 @@ | ||
import logging | ||
|
||
from django.db.models.signals import pre_save | ||
from django.contrib.auth.signals import user_logged_in | ||
from django.dispatch import receiver | ||
from django.utils.translation import gettext as _ | ||
|
||
from open_inwoner.accounts.choices import LoginTypeChoices | ||
from open_inwoner.accounts.models import User | ||
from open_inwoner.utils.logentry import system_action | ||
|
||
from .client import KvKClient | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@receiver(pre_save, sender=User) | ||
def on_kvk_change(instance, **kwargs): | ||
@receiver(user_logged_in) | ||
def on_kvk_change(sender, user, request, *args, **kwargs): | ||
if ( | ||
instance.kvk | ||
and instance.is_prepopulated is False | ||
and instance.login_type == LoginTypeChoices.eherkenning | ||
and not instance.rsin | ||
user.kvk | ||
and user.is_prepopulated is False | ||
and user.login_type == LoginTypeChoices.eherkenning | ||
and not user.rsin | ||
): | ||
system_action( | ||
_("Retrieving data from KvK API based on KVK number"), | ||
content_object=instance, | ||
content_object=user, | ||
) | ||
|
||
client = KvKClient() | ||
rsin = client.retrieve_rsin_with_kvk(instance.kvk) | ||
rsin = client.retrieve_rsin_with_kvk(user.kvk) | ||
|
||
if rsin: | ||
system_action(_("data was retrieved from KvK API"), content_object=instance) | ||
system_action(_("data was retrieved from KvK API"), content_object=user) | ||
|
||
instance.rsin = rsin | ||
instance.is_prepopulated = True | ||
user.rsin = rsin | ||
user.is_prepopulated = True | ||
user.save() |
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