4040import login .permissions
4141from api import parser , sessions
4242from api .actions import (
43- _translate_fetched_cell ,
4443 assert_permission ,
4544 close_cursor ,
4645 close_raw_connection ,
4746 load_cursor_from_context ,
4847 load_session_from_context ,
4948 open_cursor ,
5049 open_raw_connection ,
50+ translate_fetched_cell ,
5151)
5252from api .encode import GeneratorJSONEncoder
5353from api .error import APIError
54+ from api .utils import table_or_404_from_dict
5455from dataedit .models import Embargo , Table , Tag
5556
5657logger = logging .getLogger ("oeplatform" )
@@ -81,7 +82,7 @@ def __init__(self, dictionary: dict):
8182def transform_results (cursor , triggers , trigger_args ):
8283 row = cursor .fetchone () if not cursor .closed else None
8384 while row is not None :
84- yield list (map (_translate_fetched_cell , row ))
85+ yield list (map (translate_fetched_cell , row ))
8586 row = cursor .fetchone ()
8687 for t , targs in zip (triggers , trigger_args ):
8788 t (* targs )
@@ -155,7 +156,7 @@ def wrapper(*args, **kwargs) -> dict:
155156 except psycopg2 .errors .InvalidCursorName as e :
156157 logger .error (str (e ))
157158 if first :
158- first = map (_translate_fetched_cell , first )
159+ first = map (translate_fetched_cell , first )
159160 if cursor .description :
160161 description = [
161162 [
@@ -240,8 +241,8 @@ def wrapper(*args, **kwargs):
240241
241242def permission_wrapper (permission : int , f : Callable ) -> Callable :
242243 def wrapper (caller , request : HttpRequest , * args , ** kwargs ):
243- table = kwargs . get ( "table" ) or kwargs . get ( "sequence" ) or ""
244- assert_permission (user = request .user , table = table , permission = permission )
244+ table_obj = table_or_404_from_dict ( kwargs )
245+ assert_permission (user = request .user , table = table_obj , permission = permission )
245246 return f (caller , request , * args , ** kwargs )
246247
247248 return wrapper
@@ -263,9 +264,8 @@ def conjunction(clauses) -> dict:
263264 return {"type" : "operator" , "operator" : "AND" , "operands" : clauses }
264265
265266
266- def check_embargo (schema : str , table : str ) -> bool :
267+ def check_embargo (table_obj : Table ) -> bool :
267268 try :
268- table_obj = Table .objects .get (name = table )
269269 embargo = Embargo .objects .filter (table = table_obj ).first ()
270270 if embargo and embargo .date_ended and embargo .date_ended > timezone .now ():
271271 return True
0 commit comments