def check_user_in_group(cls, user: Union[str, int], group: Union[str, int]) -> sa.sql.Select: user_id = AopiUser.get_id(user) group_id = AopiGroup.get_id(group) return sa.select([ sa.exists( cls.select_query(cls.id).where( sa.and_(cls.group_id == group_id, cls.user_id == user_id))) ])
def create( cls, *, name: str, deletable: bool, user: Union[str, int] ) -> sa.sql.Insert: return cls.insert_query( name=name, deletable=deletable, created_by=AopiUser.get_id(user) )
def link(cls, user: Union[str, int], group: Union[str, int]) -> sa.sql.Insert: user_id = AopiUser.get_id(user) group_id = AopiGroup.get_id(group) return cls.insert_query(group_id=group_id, user_id=user_id)
def get_user_groups(cls, user: Union[str, int]) -> sa.sql.Select: user_id = AopiUser.get_id(user) return cls.select_query(cls.group_id).where(cls.user_id == user_id)