Skip to content

Commit

Permalink
feat: add login_methods field in ProfileNode
Browse files Browse the repository at this point in the history
Refs: HP-2490
  • Loading branch information
danipran committed Jul 18, 2024
1 parent 7dc1a82 commit 9f23447
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion profiles/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
download_connected_service_data,
)
from .enums import AddressType, EmailType, PhoneType
from .keycloak_integration import delete_profile_from_keycloak
from .keycloak_integration import delete_profile_from_keycloak, get_user_login_methods
from .models import (
Address,
ClaimToken,
Expand Down Expand Up @@ -514,6 +514,10 @@ def validate_ssn(value, info, **input):


class RestrictedProfileNode(DjangoObjectType):
"""
Profile node with a restricted set of data. This does not contain any sensitive data.
"""

class Meta:
model = Profile
fields = ("first_name", "last_name", "nickname", "language")
Expand Down Expand Up @@ -575,6 +579,10 @@ class Meta:
connection_class = ProfilesConnection
filterset_class = ProfileFilter

login_methods = graphene.List(
graphene.String,
description="List of login methods that the profile has used to authenticate.",
)
sensitivedata = graphene.Field(
SensitiveDataNode,
description="Data that is consider to be sensitive e.g. social security number",
Expand All @@ -589,6 +597,12 @@ class Meta:
"privileges to access this information.",
)

def resolve_login_methods(self: Profile, info, **kwargs):
amr = set(info.context.user_auth.data.get("amr", []))
if amr.intersection({"password", "otp", "suomi_fi"}):
return get_user_login_methods(self.user.uuid)
return []

def resolve_service_connections(self: Profile, info, **kwargs):
return self.effective_service_connections_qs()

Expand Down

0 comments on commit 9f23447

Please sign in to comment.