Files
mgu/server/api/helpers.py
T

35 lines
841 B
Python

import logging
import database
def user_in_thread(user_id: int, thread_id: int) -> bool:
forums = database.get_user_forums(user_id)
if not forums:
return False
for forum in forums:
if not forum.id:
logging.error(f'Forum {forum.name} has no id but user is in it?')
continue
threads = database.get_forum_threads(forum.id)
for thread in threads:
if not thread.id:
logging.error(f'Thread {thread.name} has no id?')
continue
if thread.id == thread_id:
return True
return False
def user_owns_forum(user_id: int, forum_id: int) -> bool:
forum_owner_ids: list[int] = database.get_forum_owners(forum_id)
if not forum_owner_ids:
return False
return user_id in forum_owner_ids