From 4daee9300d00ed46bdb22018983e319b32882418 Mon Sep 17 00:00:00 2001 From: Tore Brede <Tore.Brede@uib.no> Date: Wed, 12 Jan 2022 13:16:22 +0100 Subject: [PATCH] GREG-165: Handling illegal fields --- gregui/api/views/invitation.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/gregui/api/views/invitation.py b/gregui/api/views/invitation.py index eaa9dd80..5da4eef6 100644 --- a/gregui/api/views/invitation.py +++ b/gregui/api/views/invitation.py @@ -323,7 +323,7 @@ class InvitedGuestView(GenericAPIView): # It is not certain that all fields required will come from Feide, like the national ID number, so # allow updates to empty fields to handle the case where the information is missing from Feide # and the user has to enter it manually - illegal_fields = self._illegal_fields( + illegal_fields = self._illegal_updates( data, self.fields_allowed_to_update_if_invite if feide_id is None @@ -340,13 +340,18 @@ class InvitedGuestView(GenericAPIView): ) @staticmethod - def _illegal_fields(request_data, changeable_fields, person) -> List[str]: + def _illegal_updates(request_data, changeable_fields, person) -> List[str]: person_data = request_data.get("person", {}) changed_fields = person_data.keys() - result = [] + illegal_field_updates = [] for changed_field in changed_fields: - attribute = getattr(person, changed_field) + try: + attribute = getattr(person, changed_field) + except AttributeError: + # The property does not exist on person + illegal_field_updates.append(changed_field) + continue if changed_field not in changeable_fields: # It is still allowed to update fields where there is no existing value even if @@ -357,9 +362,9 @@ class InvitedGuestView(GenericAPIView): else: if attribute != person_data[changed_field]: # There is an existing value - result.append(changed_field) + illegal_field_updates.append(changed_field) - return result + return illegal_field_updates @staticmethod def _get_identity_or_none( -- GitLab