Skip to content
Snippets Groups Projects
Commit a94d0f0e authored by Tore.Brede's avatar Tore.Brede
Browse files

GREG-110: Fixing linting error and indentation

parent 73962022
No related branches found
No related tags found
1 merge request!148GREG-110: Guest cannot change name under manual registration
Pipeline #100244 passed
...@@ -71,7 +71,7 @@ class GuestRegisterSerializer(serializers.ModelSerializer): ...@@ -71,7 +71,7 @@ class GuestRegisterSerializer(serializers.ModelSerializer):
def create_identity_or_update( def create_identity_or_update(
identity_type: Identity.IdentityType, value: str, person: Person identity_type: Identity.IdentityType, value: str, person: Person
): ):
existing_identity = person.identities.filter(type=identity_type).first() existing_identity = person.identities.filter(type=identity_type).first()
if not existing_identity: if not existing_identity:
......
...@@ -72,8 +72,8 @@ class InvitationView(CreateAPIView, DestroyAPIView): ...@@ -72,8 +72,8 @@ class InvitationView(CreateAPIView, DestroyAPIView):
person = serializer.save() person = serializer.save()
for invitationlink in InvitationLink.objects.filter( for invitationlink in InvitationLink.objects.filter(
invitation__role__person_id=person.id, invitation__role__person_id=person.id,
invitation__role__sponsor_id=sponsor_user.sponsor_id, invitation__role__sponsor_id=sponsor_user.sponsor_id,
): ):
send_invite_mail(invitationlink) send_invite_mail(invitationlink)
...@@ -143,7 +143,14 @@ class InvitedGuestView(GenericAPIView): ...@@ -143,7 +143,14 @@ class InvitedGuestView(GenericAPIView):
serializer_class = GuestRegisterSerializer serializer_class = GuestRegisterSerializer
# TODO Check these scenarios again. What should be allowed to be updated in the various coses # TODO Check these scenarios again. What should be allowed to be updated in the various coses
fields_allowed_to_update_if_invite = ["first_name", "last_name", "email", "fnr", "mobile_phone", "passport"] fields_allowed_to_update_if_invite = [
"first_name",
"last_name",
"email",
"fnr",
"mobile_phone",
"passport",
]
fields_allowed_to_update_if_feide = ["mobile_phone"] fields_allowed_to_update_if_feide = ["mobile_phone"]
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
...@@ -233,8 +240,12 @@ class InvitedGuestView(GenericAPIView): ...@@ -233,8 +240,12 @@ class InvitedGuestView(GenericAPIView):
# If there is a Feide ID registered with the guest, assume that the name is also coming from there # If there is a Feide ID registered with the guest, assume that the name is also coming from there
feide_id = self._get_identity_or_none(person, Identity.IdentityType.FEIDE_ID) feide_id = self._get_identity_or_none(person, Identity.IdentityType.FEIDE_ID)
if not self._only_allowed_fields_in_request(data, if not self._only_allowed_fields_in_request(
self.fields_allowed_to_update_if_invite if feide_id is None else self.fields_allowed_to_update_if_feide): data,
self.fields_allowed_to_update_if_invite
if feide_id is None
else self.fields_allowed_to_update_if_feide,
):
return Response(status=status.HTTP_400_BAD_REQUEST) return Response(status=status.HTTP_400_BAD_REQUEST)
if self._verified_fnr_already_exists(person) and "fnr" in data: if self._verified_fnr_already_exists(person) and "fnr" in data:
...@@ -283,7 +294,7 @@ class InvitedGuestView(GenericAPIView): ...@@ -283,7 +294,7 @@ class InvitedGuestView(GenericAPIView):
@staticmethod @staticmethod
def _get_identity_or_none( def _get_identity_or_none(
person: Person, identity_type: Identity.IdentityType person: Person, identity_type: Identity.IdentityType
) -> Optional[str]: ) -> Optional[str]:
try: try:
return person.identities.get(type=identity_type).value return person.identities.get(type=identity_type).value
......
...@@ -40,7 +40,7 @@ def test_get_invited_info_no_session(client, invitation_link): ...@@ -40,7 +40,7 @@ def test_get_invited_info_no_session(client, invitation_link):
@pytest.mark.django_db @pytest.mark.django_db
def test_get_invited_info_session_okay( def test_get_invited_info_session_okay(
client, invited_person, sponsor_foo_data, role_type_foo, unit_foo client, invited_person, sponsor_foo_data, role_type_foo, unit_foo
): ):
person, invitation_link = invited_person person, invitation_link = invited_person
# get a session # get a session
...@@ -75,7 +75,7 @@ def test_get_invited_info_session_okay( ...@@ -75,7 +75,7 @@ def test_get_invited_info_session_okay(
@pytest.mark.django_db @pytest.mark.django_db
def test_get_invited_info_expired_link( def test_get_invited_info_expired_link(
client, invitation_link, invitation_expired_date client, invitation_link, invitation_expired_date
): ):
# Get a session while link is valid # Get a session while link is valid
client.get(reverse("gregui-v1:invite-verify"), data={"uuid": invitation_link.uuid}) client.get(reverse("gregui-v1:invite-verify"), data={"uuid": invitation_link.uuid})
...@@ -118,7 +118,7 @@ def test_invited_guest_can_post_information(client: APIClient, invited_person): ...@@ -118,7 +118,7 @@ def test_invited_guest_can_post_information(client: APIClient, invited_person):
@pytest.mark.django_db @pytest.mark.django_db
def test_post_invited_info_expired_session( def test_post_invited_info_expired_session(
client, invitation_link, invitation_expired_date client, invitation_link, invitation_expired_date
): ):
# get a session # get a session
client.post(reverse("gregui-v1:invite-verify"), data={"uuid": invitation_link.uuid}) client.post(reverse("gregui-v1:invite-verify"), data={"uuid": invitation_link.uuid})
...@@ -230,10 +230,10 @@ def test_register_passport(client, invited_person): ...@@ -230,10 +230,10 @@ def test_register_passport(client, invited_person):
session.save() session.save()
assert ( assert (
Identity.objects.filter( Identity.objects.filter(
person__id=person.id, type=Identity.IdentityType.PASSPORT_NUMBER person__id=person.id, type=Identity.IdentityType.PASSPORT_NUMBER
).count() ).count()
== 0 == 0
) )
response = client.post(url, data, format="json") response = client.post(url, data, format="json")
...@@ -249,10 +249,17 @@ def test_register_passport(client, invited_person): ...@@ -249,10 +249,17 @@ def test_register_passport(client, invited_person):
@pytest.mark.django_db @pytest.mark.django_db
def test_name_update_not_allowed_if_feide_identity_is_present(client: APIClient, person_foo, sponsor_foo, unit_foo, def test_name_update_not_allowed_if_feide_identity_is_present(
role_type_foo, client: APIClient,
create_role, create_invitation, create_invitation_link, person_foo,
invitation_valid_date): sponsor_foo,
unit_foo,
role_type_foo,
create_role,
create_invitation,
create_invitation_link,
invitation_valid_date,
):
# This person has a Feide ID, so the name is assumed to come from there as well # This person has a Feide ID, so the name is assumed to come from there as well
# and the guest should not be allowed to update it # and the guest should not be allowed to update it
role = create_role( role = create_role(
...@@ -263,7 +270,13 @@ def test_name_update_not_allowed_if_feide_identity_is_present(client: APIClient, ...@@ -263,7 +270,13 @@ def test_name_update_not_allowed_if_feide_identity_is_present(client: APIClient,
client.post(reverse("gregui-v1:invite-verify"), data={"uuid": invitation_link.uuid}) client.post(reverse("gregui-v1:invite-verify"), data={"uuid": invitation_link.uuid})
person = invitation_link.invitation.role.person person = invitation_link.invitation.role.person
data = {"person": {"first_name": "Someone", "last_name": "Test", "mobile_phone": "+4797543992"}} data = {
"person": {
"first_name": "Someone",
"last_name": "Test",
"mobile_phone": "+4797543992",
}
}
# The update request should fail because it contains a name update # The update request should fail because it contains a name update
response = client.post( response = client.post(
...@@ -280,27 +293,36 @@ def test_name_update_not_allowed_if_feide_identity_is_present(client: APIClient, ...@@ -280,27 +293,36 @@ def test_name_update_not_allowed_if_feide_identity_is_present(client: APIClient,
@pytest.mark.django_db @pytest.mark.django_db
def test_name_update_allowed_if_feide_identity_is_not_present(client: APIClient, create_person, sponsor_foo, unit_foo, def test_name_update_allowed_if_feide_identity_is_not_present(
role_type_foo, client: APIClient,
create_role, create_invitation, create_invitation_link, create_person,
invitation_valid_date): sponsor_foo,
unit_foo,
role_type_foo,
create_role,
create_invitation,
create_invitation_link,
invitation_valid_date,
):
# This person does not have a Feide ID, so he will be viewed as someone whose name was entered manually # This person does not have a Feide ID, so he will be viewed as someone whose name was entered manually
# by the sponsor, and in it that case the guest can update it # by the sponsor, and in it that case the guest can update it
person = create_person( person = create_person(first_name="Foo", last_name="Bar", email="foo@bar.com")
first_name="Foo",
last_name="Bar",
email="foo@bar.com")
role = create_role( role = create_role(
person=person, sponsor=sponsor_foo, unit=unit_foo, role_type=role_type_foo person=person, sponsor=sponsor_foo, unit=unit_foo, role_type=role_type_foo
) )
invitation = create_invitation(role) invitation_link = create_invitation_link(
invitation_link = create_invitation_link(invitation, invitation_valid_date) create_invitation(role), invitation_valid_date
)
client.post(reverse("gregui-v1:invite-verify"), data={"uuid": invitation_link.uuid}) client.post(reverse("gregui-v1:invite-verify"), data={"uuid": invitation_link.uuid})
person = invitation_link.invitation.role.person person = invitation_link.invitation.role.person
first_name = "Someone" data = {
last_name = "Test" "person": {
data = {"person": {"first_name": first_name, "last_name": last_name, "mobile_phone": "+4797543992"}} "first_name": "Someone",
"last_name": "Test",
"mobile_phone": "+4797543992",
}
}
response = client.post( response = client.post(
reverse("gregui-v1:invited-info"), reverse("gregui-v1:invited-info"),
...@@ -312,5 +334,5 @@ def test_name_update_allowed_if_feide_identity_is_not_present(client: APIClient, ...@@ -312,5 +334,5 @@ def test_name_update_allowed_if_feide_identity_is_not_present(client: APIClient,
# Check that the name has been updated in the database # Check that the name has been updated in the database
assert Person.objects.count() == 1 assert Person.objects.count() == 1
person.refresh_from_db() person.refresh_from_db()
assert person.first_name == first_name assert person.first_name == "Someone"
assert person.last_name == last_name assert person.last_name == "Test"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment