Skip to content

Commit 541490c

Browse files
authored
Merge pull request #2178 from OpenEnergyPlatform/post-schema-resolve-cleanup
Post schema resolve cleanup
2 parents f12e612 + cad2e67 commit 541490c

File tree

47 files changed

+695
-1108
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+695
-1108
lines changed

api/actions.py

Lines changed: 226 additions & 333 deletions
Large diffs are not rendered by default.

api/helper.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,18 @@
4040
import login.permissions
4141
from api import parser, sessions
4242
from 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
)
5252
from api.encode import GeneratorJSONEncoder
5353
from api.error import APIError
54+
from api.utils import table_or_404_from_dict
5455
from dataedit.models import Embargo, Table, Tag
5556

5657
logger = logging.getLogger("oeplatform")
@@ -81,7 +82,7 @@ def __init__(self, dictionary: dict):
8182
def 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

241242
def 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

Comments
 (0)