Skip to content

Commit

Permalink
upgrade pydantic, fix beamline list
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanmcreynolds committed Sep 26, 2023
1 parent 4e92a0b commit 8aa80b4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
13 changes: 7 additions & 6 deletions alshub/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from splash_userservice.service import IDType, UserService, UserNotFound, CommunicationError

config = Config(".env")
ALSHUB_BASE = config.get("ALSHUB_BASE", cast=str, default="https://alsusweb.lbl.gov:1024")
ALSHUB_BASE = config.get("ALSHUB_BASE", cast=str, default="https://alsusweb.lbl.gov")

ALSHUB_PERSON = "ALSGetPerson"
ALSHUB_PROPOSAL = "ALSUserProposals"
Expand Down Expand Up @@ -105,6 +105,7 @@ async def get_user(self, id: str, id_type: IDType, fetch_groups=True) -> User:
user_lb_id)

# add staff beamlines to groups list
# if id_type == IDType.email:
beamlines = await get_staff_beamlines(alsusweb_client, id)
if beamlines:
groups.update(beamlines)
Expand Down Expand Up @@ -178,15 +179,15 @@ async def get_user_esafs(client, lbl_id):
return {esaf["ProposalFriendlyId"] for esaf in esafs}


async def get_staff_beamlines(ac: AsyncClient, email: str) -> List[str]:
response = await ac.get(f"{ALSHUB_PERSON_ROLES}/?em={email}")
async def get_staff_beamlines(ac: AsyncClient, orcid: str) -> List[str]:
response = await ac.get(f"{ALSHUB_PERSON_ROLES}/?or={orcid}")
# ADMINS are a list maintained in a python to add users to groups even if they're not maintained in
# ALSHub
beamlines = set()
if ADMINS:
beamlines.update(ADMINS[email])
beamlines.update(ADMINS[orcid])
if response.is_error:
info(f"error asking ALHub for staff roles {email}")
info(f"error asking ALHub for staff roles {orcid}")
return beamlines
if response.content:
alshub_beamlines = alshub_roles_to_beamline_groups(
Expand All @@ -195,7 +196,7 @@ async def get_staff_beamlines(ac: AsyncClient, email: str) -> List[str]:
beamlines |= set(alshub_beamlines)
return beamlines
else:
info(f"ALSHub returned no content for roles {email}. So no roles found")
info(f"ALSHub returned no content for roles {orcid}. So no roles found")
return beamlines


Expand Down
14 changes: 7 additions & 7 deletions splash_userservice/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ class UniqueId(BaseModel):

class User(BaseModel):
uid: str = Field(description="system unique identifier")
authenticators: Optional[List[UniqueId]] = Field(description="list of accounts that user can be known by")
given_name: Optional[str] = Field(description="user's given name", schema="https://schema.org/givenName")
family_name: Optional[str] = Field(description="user's family name")
current_institution: Optional[str] = Field(description="user's currently known institution")
current_email: Optional[str] = Field(description="user's currently known email")
groups: Optional[List[str]] = Field(description="list of groups a user belongs to")
authenticators: Optional[List[UniqueId]] = Field(None, description="list of accounts that user can be known by")
given_name: Optional[str] = Field(None, description="user's given name", schema="https://schema.org/givenName")
family_name: Optional[str] = Field(None, description="user's family name")
current_institution: Optional[str] = Field(None, description="user's currently known institution")
current_email: Optional[str] = Field(None, description="user's currently known email")
groups: Optional[List[str]] = Field(None, description="list of groups a user belongs to")
orcid: str = Field(description="user's ORCID")


class AccessGroup(BaseModel):
uid: str = Field(description="group's system unique identifier")
name: str = Field(description="group's name")
members: Optional[List[UniqueId]] = Field(description="list of users in the access group")
members: Optional[List[UniqueId]] = Field(None, description="list of users in the access group")


class MappedField(BaseModel):
Expand Down

0 comments on commit 8aa80b4

Please sign in to comment.