@@ -93,6 +93,8 @@ def _create_private_workspace_query(
9393 return (
9494 sql .select (
9595 * _FOLDER_DB_MODEL_COLS ,
96+ # NOTE: design INVARIANT:
97+ # a user in his private workspace owns his folders
9698 sql .func .json_build_object (
9799 "read" ,
98100 sa .text ("true" ),
@@ -130,6 +132,8 @@ def _create_shared_workspace_query(
130132 shared_workspace_query = (
131133 sql .select (
132134 * _FOLDER_DB_MODEL_COLS ,
135+ # NOTE: design INVARIANT:
136+ # a user access rights to a folder in a SHARED workspace is inherited from the workspace
133137 workspace_access_rights_subquery .c .my_access_rights ,
134138 )
135139 .select_from (
@@ -156,12 +160,12 @@ def _create_shared_workspace_query(
156160 return shared_workspace_query
157161
158162
159- def _to_expression ( order_by : OrderBy ):
163+ def _to_sql_expression ( table : sa . Table , order_by : OrderBy ):
160164 direction_func : Callable = {
161165 OrderDirection .ASC : sql .asc ,
162166 OrderDirection .DESC : sql .desc ,
163167 }[order_by .direction ]
164- return direction_func (folders_v2 .columns [order_by .field ])
168+ return direction_func (table .columns [order_by .field ])
165169
166170
167171async def list_ ( # pylint: disable=too-many-arguments,too-many-branches
@@ -245,7 +249,9 @@ async def list_( # pylint: disable=too-many-arguments,too-many-branches
245249
246250 # Ordering and pagination
247251 list_query = (
248- combined_query .order_by (_to_expression (order_by )).offset (offset ).limit (limit )
252+ combined_query .order_by (_to_sql_expression (folders_v2 , order_by ))
253+ .offset (offset )
254+ .limit (limit )
249255 )
250256
251257 async with pass_or_acquire_connection (get_asyncpg_engine (app ), connection ) as conn :
@@ -273,7 +279,6 @@ async def list_trashed_folders(
273279) -> tuple [int , list [FolderDB ]]:
274280 """
275281 NOTE: this is app-wide i.e. no product, user or workspace filtered
276- TODO: check with MD about workspaces
277282 """
278283 base_query = sql .select (* _FOLDER_DB_MODEL_COLS ).where (
279284 folders_v2 .c .trashed .is_not (None )
@@ -294,7 +299,7 @@ async def list_trashed_folders(
294299
295300 # Ordering and pagination
296301 list_query = (
297- base_query .order_by (_to_expression (order_by )).offset (offset ).limit (limit )
302+ base_query .order_by (_to_sql_expression (order_by )).offset (offset ).limit (limit )
298303 )
299304
300305 async with pass_or_acquire_connection (get_asyncpg_engine (app ), connection ) as conn :
0 commit comments