From 64a65491cc50eabc3566f45fd8ff5420bb88b443 Mon Sep 17 00:00:00 2001 From: Helge Jung <hej@c3pb.de> Date: Tue, 26 Dec 2023 12:22:29 +0100 Subject: [PATCH] PlatformUser: allow .from_dict() for non-SPEAKER users, too In that case, don't update the description/bio unless the user is added to the Conference for the first time (i.e. don't overwrite bio for regular users). Additionally, remove unused code in the function - currently we require an existing PlatformUser object already so there is no need for uuid/pk magic (only complicates debugging). --- src/core/models/users.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/core/models/users.py b/src/core/models/users.py index 1fdc66f97..178bab197 100644 --- a/src/core/models/users.py +++ b/src/core/models/users.py @@ -2,7 +2,7 @@ import logging import re from pathlib import Path from typing import TYPE_CHECKING, Any -from uuid import UUID, uuid4 +from uuid import uuid4 from timezone_field import TimeZoneField @@ -364,20 +364,14 @@ class PlatformUser(AbstractUser): assert isinstance(data, dict), 'Data must be a dictionary.' if not existing: raise NotImplementedError('Creating a PlatformUser with .from_dict() is not supported.') - if existing.user_type != PlatformUser.Type.SPEAKER: - raise NotImplementedError('Updating a PlatformUser which is not a SPEAKER is not supported (yet).') - given_uuid = UUID(data.pop('guid')) if 'guid' in data else None - if existing: - obj = existing - else: - obj = cls() - if given_uuid is not None: - obj.pk = given_uuid + obj = existing # join the new user into the conference - cm, _ = conference.users.get_or_create(user=obj) - cm.description = data.get('biography', '') + cm, created = conference.users.get_or_create(user=obj) + if existing.user_type == cls.Type.SPEAKER or created: + # only set the description/bio upon creation for real users (imported speakers are updated every time) + cm.description = data.get('biography', '') cm.save() # add all known addresses as (unverified and non-public) communication channels -- GitLab