Skip to content

Commit

Permalink
feat: send welcome mail when user created through representative
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed-Hacene committed Sep 17, 2024
1 parent 34e1c69 commit c7a42c9
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions backend/tprm/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from core.serializer_fields import FieldsRelatedField
from core.serializers import BaseModelSerializer
from core.utils import RoleCodename, UserGroupCodename
from iam.models import Folder, Role, RoleAssignment, User, UserGroup
from iam.models import Folder, Role, RoleAssignment, UserGroup
from django.contrib.auth import get_user_model
from tprm.models import Entity, EntityAssessment, Representative, Solution
from django.utils.translation import gettext_lazy as _
from ciso_assistant.settings import EMAIL_HOST, EMAIL_HOST_RESCUE
Expand All @@ -13,6 +14,8 @@

logger = structlog.get_logger(__name__)

User = get_user_model()


class EntityReadSerializer(BaseModelSerializer):
folder = FieldsRelatedField()
Expand Down Expand Up @@ -174,12 +177,16 @@ class RepresentativeWriteSerializer(BaseModelSerializer):
def _create_or_update_user(self, instance, user):
if not user:
return
user, created = User.objects.get_or_create(
user = User.objects.filter(
email=instance.email,
)
user.first_name = instance.first_name
user.last_name = instance.last_name
user.is_third_party = True
).first()
if not user:
user = User.objects.create_user(
email=instance.email,
first_name=instance.first_name,
last_name=instance.last_name,
)
user.is_third_party = True
user.save()
instance.user = user
instance.save()
Expand Down

0 comments on commit c7a42c9

Please sign in to comment.