Skip to content

Commit 30b3a77

Browse files
committed
feat: update the endpoint details of the auth api
1 parent c4be557 commit 30b3a77

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

src/auth/crud.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import sqlalchemy
55
from sqlalchemy.ext.asyncio import AsyncSession
66

7-
from auth.models import SiteUserModel
87
from auth.tables import SiteUser, UserSession
98

109
_logger = logging.getLogger(__name__)

src/auth/models.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ class LoginBodyParams(BaseModel):
88
ticket: str = Field(description="Ticket return from SFU's CAS system")
99
redirect_url: str | None = Field(None, description="Optional redirect URL")
1010

11+
class UpdateUserParams(BaseModel):
12+
profile_picture_url: str
13+
1114
class UserSessionModel(BaseModel):
1215
computing_id: str
1316
issue_time: datetime
@@ -17,4 +20,4 @@ class SiteUserModel(BaseModel):
1720
computing_id: str
1821
first_logged_in: datetime
1922
last_logged_in: datetime
20-
profile_picture_url: str | None
23+
profile_picture_url: str | None = None

src/auth/urls.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import database
1212
from auth import crud
13-
from auth.models import LoginBodyParams, SiteUserModel
13+
from auth.models import LoginBodyParams, SiteUserModel, UpdateUserParams
1414
from constants import DOMAIN, IS_PROD, SAMESITE
1515
from utils.shared_models import DetailModel, MessageModel
1616

@@ -134,15 +134,16 @@ async def get_user(
134134
"""
135135
session_id = request.cookies.get("session_id", None)
136136
if session_id is None:
137-
raise HTTPException(status_code=401, detail="User must be authenticated to get their info")
137+
raise HTTPException(status_code=401, detail="user must be authenticated to get their info")
138138

139139
user_info = await crud.get_site_user(db_session, session_id)
140140
if user_info is None:
141-
raise HTTPException(status_code=401, detail="Could not find user with session_id, please log in")
141+
raise HTTPException(status_code=401, detail="could not find user with session_id, please log in")
142142

143143
return JSONResponse(user_info.serialize())
144144

145145

146+
# TODO: We should change this so that the admins can change people's pictures too, so they can remove offensive stuff
146147
@router.patch(
147148
"/user",
148149
operation_id="update_user",
@@ -153,18 +154,18 @@ async def get_user(
153154
},
154155
)
155156
async def update_user(
156-
profile_picture_url: str,
157+
body: UpdateUserParams,
157158
request: Request,
158159
db_session: database.DBSession,
159160
):
160161
"""
161162
Returns the info stored in the site_user table in the auth module, if the user is logged in.
162163
"""
163-
session_id = request.cookies.get("session_id", None)
164+
session_id = request.cookies.get("session_id")
164165
if session_id is None:
165-
raise HTTPException(status_code=401, detail="User must be authenticated to get their info")
166+
raise HTTPException(status_code=401, detail="user must be authenticated to get their info")
166167

167-
ok = await crud.update_site_user(db_session, session_id, profile_picture_url)
168+
ok = await crud.update_site_user(db_session, session_id, body.profile_picture_url)
168169
await db_session.commit()
169170
if not ok:
170-
raise HTTPException(status_code=401, detail="Could not find user with session_id, please log in")
171+
raise HTTPException(status_code=401, detail="could not find user with session_id, please log in")

0 commit comments

Comments
 (0)