Skip to content

Commit

Permalink
Move HUser h_username and h_userid generation to helper functions
Browse files Browse the repository at this point in the history
This avoids the need to create a HUser (which we only create from an
LTIUser) when we need to generate IDs for H.
  • Loading branch information
marcospri committed Aug 27, 2024
1 parent e9976f3 commit 832b276
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lms/models/h_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
from lms.models._hashed_id import hashed_id


def get_h_username(guid: str, lms_user_id: str):
return hashed_id(guid, lms_user_id)[:30]


def get_h_userid(authority: str, h_username: str):
return f"acct:{h_username}@{authority}"


class HUser(NamedTuple):
"""
An 'h' user.
Expand All @@ -29,15 +37,15 @@ class HUser(NamedTuple):
"""The "provider_unique_id" string to pass to the h API for this user."""

def userid(self, authority):
return f"acct:{self.username}@{authority}"
return get_h_userid(authority, self.username)

@classmethod
def from_lti_user(cls, lti_user):
provider = lti_user.tool_consumer_instance_guid
provider_unique_id = lti_user.user_id

return cls(
username=hashed_id(provider, provider_unique_id)[:30],
username=get_h_username(provider, provider_unique_id),
display_name=lti_user.display_name,
provider=provider,
provider_unique_id=provider_unique_id,
Expand Down

0 comments on commit 832b276

Please sign in to comment.