mirror of
https://github.com/rommapp/romm.git
synced 2026-10-12 02:21:58 +00:00
refactor(streaming): read the joinable filter from one place
The join walk and the joinable listing each spelled out what makes a session joinable, kept in step by a comment. Both now ask access.
This commit is contained in:
@@ -1103,16 +1103,13 @@ async def join_session(
|
||||
session = await get_live_session(candidate.key)
|
||||
if session is None:
|
||||
continue
|
||||
# Same filter the joinable listing applies, so the button and the
|
||||
# join agree on what is joinable. A member that fails it is not the
|
||||
# answer and must not mask a later one that is.
|
||||
if not session.get("multiplayer"):
|
||||
continue
|
||||
if not session_platform_matches(session, platform):
|
||||
continue
|
||||
if session.get("user_id") == request.user.id:
|
||||
continue
|
||||
if not access.session_rom_is_visible(request, session):
|
||||
# A member the caller cannot join is not the answer and must not
|
||||
# mask a later one that is.
|
||||
if not access.session_is_joinable(
|
||||
request, session, access.session_rom(session)
|
||||
):
|
||||
continue
|
||||
found = (candidate, session)
|
||||
break
|
||||
@@ -1510,19 +1507,10 @@ async def list_joinable_sessions(
|
||||
|
||||
sessions: list[dict[str, Any]] = []
|
||||
async for container_key, s in iter_live_sessions():
|
||||
if not s.get("multiplayer"):
|
||||
continue
|
||||
if s.get("user_id") == request.user.id:
|
||||
continue
|
||||
if rom_id is not None and s.get("rom_id") != rom_id:
|
||||
continue
|
||||
session_rom_id = s.get("rom_id")
|
||||
rom = (
|
||||
db_rom_handler.get_rom_simple(session_rom_id)
|
||||
if session_rom_id is not None
|
||||
else None
|
||||
)
|
||||
if not access.rom_is_visible(request, rom):
|
||||
rom = access.session_rom(s)
|
||||
if not access.session_is_joinable(request, s, rom):
|
||||
continue
|
||||
|
||||
user_id = s.get("user_id")
|
||||
@@ -1532,7 +1520,7 @@ async def list_joinable_sessions(
|
||||
"container": container_key,
|
||||
"label": _joinable_container_label(grouped, container_key),
|
||||
"platform": s.get("platform"),
|
||||
"rom_id": session_rom_id,
|
||||
"rom_id": s.get("rom_id"),
|
||||
"rom_name": s.get("rom_name"),
|
||||
"host_username": host.username if host else None,
|
||||
"claimed_at": s.get("claimed_at"),
|
||||
|
||||
@@ -54,12 +54,27 @@ def rom_is_visible(request: Request, rom: Rom | None) -> bool:
|
||||
return get_permissions(request).can_see_rom(rom.id, rom.platform_id)
|
||||
|
||||
|
||||
def session_rom(session: dict[str, Any]) -> Rom | None:
|
||||
"""The ROM a session is running, None for a desktop or a deleted entry."""
|
||||
rom_id = session.get("rom_id")
|
||||
return db_rom_handler.get_rom_simple(rom_id) if rom_id is not None else None
|
||||
|
||||
|
||||
def session_rom_is_visible(request: Request, session: dict[str, Any]) -> bool:
|
||||
"""Can the caller see the ROM a session is running?"""
|
||||
rom_id = session.get("rom_id")
|
||||
if rom_id is None:
|
||||
return True
|
||||
return rom_is_visible(request, db_rom_handler.get_rom_simple(rom_id))
|
||||
return rom_is_visible(request, session_rom(session))
|
||||
|
||||
|
||||
def session_is_joinable(
|
||||
request: Request, session: dict[str, Any], rom: Rom | None
|
||||
) -> bool:
|
||||
"""Whether a live session is one this caller may ask to join: its host opted
|
||||
into multiplayer, it is somebody else's, and its ROM is not hidden."""
|
||||
return (
|
||||
bool(session.get("multiplayer"))
|
||||
and session.get("user_id") != request.user.id
|
||||
and rom_is_visible(request, rom)
|
||||
)
|
||||
|
||||
|
||||
def assert_session_rom_visible(
|
||||
|
||||
Reference in New Issue
Block a user