sessions: Rename get_session_user to get_session_user_id.

The function returns a user id, not a user - we generally try to reflect
that in function names accurately.
This commit is contained in:
Mateusz Mandera 2022-03-27 20:47:48 +02:00 committed by Tim Abbott
parent 66d8c2ae15
commit 4e1befa209

View File

@ -28,12 +28,12 @@ def get_session_dict_user(session_dict: Mapping[str, int]) -> Optional[int]:
return None
def get_session_user(session: Session) -> Optional[int]:
def get_session_user_id(session: Session) -> Optional[int]:
return get_session_dict_user(session.get_decoded())
def user_sessions(user_profile: UserProfile) -> List[Session]:
return [s for s in Session.objects.all() if get_session_user(s) == user_profile.id]
return [s for s in Session.objects.all() if get_session_user_id(s) == user_profile.id]
def delete_session(session: Session) -> None:
@ -42,14 +42,14 @@ def delete_session(session: Session) -> None:
def delete_user_sessions(user_profile: UserProfile) -> None:
for session in Session.objects.all():
if get_session_user(session) == user_profile.id:
if get_session_user_id(session) == user_profile.id:
delete_session(session)
def delete_realm_user_sessions(realm: Realm) -> None:
realm_user_ids = list(UserProfile.objects.filter(realm=realm).values_list("id", flat=True))
for session in Session.objects.all():
if get_session_user(session) in realm_user_ids:
if get_session_user_id(session) in realm_user_ids:
delete_session(session)
@ -60,7 +60,7 @@ def delete_all_user_sessions() -> None:
def delete_all_deactivated_user_sessions() -> None:
for session in Session.objects.all():
user_profile_id = get_session_user(session)
user_profile_id = get_session_user_id(session)
if user_profile_id is None: # nocoverage # TODO: Investigate why we lost coverage on this
continue
user_profile = get_user_profile_by_id(user_profile_id)