Skip to content

Commit

Permalink
Fix lookup by username
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartcampbell committed Oct 16, 2023
1 parent 4aa200d commit d874ce0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
6 changes: 4 additions & 2 deletions nsls2api/api/models/person_model.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
from typing import Optional, List

import pydantic
Expand Down Expand Up @@ -64,11 +65,12 @@ class Person(pydantic.BaseModel):
email: str
username: str
bnl_id: Optional[str]
institution: str
institution: Optional[str] = None
orcid: Optional[str] = None
globus_username: Optional[str] = None
pass_unique_id: Optional[str] = None
account_locked: bool
account_locked: Optional[bool] = None
cyber_agreement_signed: Optional[datetime.datetime] = None


class PersonSummary(pydantic.BaseModel):
Expand Down
23 changes: 15 additions & 8 deletions nsls2api/api/v1/user_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,20 @@
async def get_person_from_username(username: str):
bnl_person = await bnlpeople_service.get_person_by_username(username)
print(bnl_person)
if len(bnl_person) == 1:
if bnl_person:
person = Person(
firstname=bnl_person[0]["FirstName"],
lastname=bnl_person[0]["LastName"],
email=bnl_person[0]["BNLEmail"],
bnl_id=bnl_person[0]["EmployeeNumber"],
firstname=bnl_person.FirstName,
lastname=bnl_person.LastName,
email=bnl_person.BNLEmail,
bnl_id=bnl_person.EmployeeNumber,
institution=bnl_person.Institution,
username=bnl_person.ActiveDirectoryName,
cyber_agreement_signed=bnl_person.CyberAgreementSigned,
)
return person
else:
return fastapi.responses.JSONResponse(
{"error": f"Multiple people with username {username} found."},
{"error": f"No people with username {username} found."},
status_code=404,
)

Expand All @@ -40,11 +43,15 @@ async def get_person_from_email(username: str):


@router.get("/person/me", response_model=str)
async def get_myself(current_user: Annotated[Person, Depends(get_current_user)]):
async def get_myself(
current_user: Annotated[Person, Depends(get_current_user)]
):
return current_user


@router.get("/data-session/{username}", response_model=DataSessionAccess, tags=["data"])
@router.get(
"/data-session/{username}", response_model=DataSessionAccess, tags=["data"]
)
@router.get(
"/data_session/{username}",
response_model=DataSessionAccess,
Expand Down

0 comments on commit d874ce0

Please sign in to comment.