-
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.
[#2638] Use Mixin to update klanten API when user is created
- Loading branch information
Showing
9 changed files
with
103 additions
and
115 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
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,22 @@ | ||
import logging | ||
|
||
from open_inwoner.openklant.clients import build_klanten_client | ||
from open_inwoner.openklant.wrap import get_fetch_parameters | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class KlantenAPIMixin: | ||
def update_klanten_api(self, update_data: dict): | ||
if update_data and (client := build_klanten_client()): | ||
klant = client.retrieve_klant(**get_fetch_parameters(self.request)) | ||
if not klant: | ||
logger.error("Failed to retrieve klant for user %s", self.request.user) | ||
return | ||
|
||
self.log_system_action("retrieved klant for user", user=self.request.user) | ||
client.partial_update_klant(klant, update_data) | ||
self.log_system_action( | ||
f"patched klant from user profile edit with fields: {', '.join(sorted(update_data.keys()))}", | ||
user=self.request.user, | ||
) |
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
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,26 @@ | ||
import logging | ||
|
||
from django.db.models.signals import post_save | ||
from django.dispatch import receiver | ||
|
||
from open_inwoner.accounts.models import User | ||
from open_inwoner.openklant.clients import build_klanten_client | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@receiver(post_save, sender=User) | ||
def create_klant_for_new_user( | ||
sender: type, instance: User, created: bool, **kwargs | ||
) -> None: | ||
if not created: | ||
return | ||
|
||
user = instance | ||
|
||
if (client := build_klanten_client()) and ( | ||
klant := client.create_klant(user_bsn=user.bsn) | ||
): | ||
logger.info("Created klant %s for new user %s", klant, user) | ||
else: | ||
logger.error("Failed to create klant for new user %s", user) |
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