Skip to content

Commit

Permalink
feat: add enum in login_methods field
Browse files Browse the repository at this point in the history
Refs: HP-2490
  • Loading branch information
danipran committed Jul 24, 2024
1 parent 78ce23a commit c714804
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
phones(offset: Int, before: String, after: String, first: Int, last: Int): PhoneNodeConnection
addresses(offset: Int, before: String, after: String, first: Int, last: Int): AddressNodeConnection
contactMethod: ContactMethod
loginMethods: [String]
loginMethods: [LoginMethodType]
sensitivedata: SensitiveDataNode
serviceConnections(offset: Int, before: String, after: String, first: Int, last: Int): ServiceConnectionTypeConnection
verifiedPersonalInformation: VerifiedPersonalInformationNode
Expand Down Expand Up @@ -216,6 +216,13 @@
SMS
}
enum LoginMethodType {
PASSWORD
OTP
SUOMI_FI
HELSINKIAD
}
type SensitiveDataNode implements Node {
id: ID!
ssn: String!
Expand Down
11 changes: 11 additions & 0 deletions profiles/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,14 @@ class Labels:
WORK = _("Work address")
HOME = _("Home address")
OTHER = _("Other address")


class LoginMethodType(Enum):
PASSWORD = "password"
OTP = "otp"
SUOMI_FI = "suomi_fi"

class Labels:
PASSWORD = _("Password")
OTP = _("One-time password")
SUOMI_FI = _("Suomi.fi")
6 changes: 4 additions & 2 deletions profiles/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
delete_connected_service_data,
download_connected_service_data,
)
from .enums import AddressType, EmailType, PhoneType
from .enums import AddressType, EmailType, LoginMethodType, PhoneType
from .keycloak_integration import delete_profile_from_keycloak, get_user_login_methods
from .models import (
Address,
Expand Down Expand Up @@ -581,7 +581,9 @@ class Meta:
filterset_class = ProfileFilter

login_methods = graphene.List(
graphene.String,
graphene.Enum.from_enum(
LoginMethodType, description=lambda e: e.label if e else ""
),
description="List of login methods that the profile has used to authenticate. "
"Only visible to the user themselves.",
)
Expand Down
7 changes: 5 additions & 2 deletions profiles/tests/test_gql_my_profile_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ def test_user_can_see_own_login_methods_with_correct_amr_claim(
user_gql_client, profile, group, service, monkeypatch, amr_claim_value
):
def mock_return(*_, **__):
return {"foo", "bar"}
return {"suomi_fi", "password"}

monkeypatch.setattr(
"profiles.keycloak_integration.get_user_identity_providers", mock_return
Expand All @@ -605,7 +605,10 @@ def mock_return(*_, **__):
query, auth_token_payload={"amr": amr_claim_value}, service=service
)
assert "errors" not in executed
assert set(executed["data"]["myProfile"]["loginMethods"]) == {"foo", "bar"}
assert set(executed["data"]["myProfile"]["loginMethods"]) == {
"SUOMI_FI",
"PASSWORD",
}


@pytest.mark.parametrize("amr_claim_value", [None, "helsinkiad"])
Expand Down

0 comments on commit c714804

Please sign in to comment.