Skip to content

Commit 97ca6dd

Browse files
authored
fix: lazy loaded permission callback (#234)
1 parent 4c49f08 commit 97ca6dd

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/unfold/sites.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,8 @@ def _get_is_active(link: str) -> bool:
233233
allowed_items = []
234234

235235
for item in group["items"]:
236-
# Permission callbacks
236+
# Skip item if permission check fails
237237
if not self._call_permission_callback(item.get("permission"), request):
238-
# Skip item if permission check fails
239238
continue
240239

241240
item["active"] = False
@@ -280,8 +279,8 @@ def get_tabs_list(self, request: HttpRequest) -> List[Dict[str, Any]]:
280279
allowed_items = []
281280

282281
for item in tab["items"]:
282+
# Skip item if permission check fails
283283
if not self._call_permission_callback(item.get("permission"), request):
284-
# Skip item if permission check fails
285284
continue
286285

287286
allowed_items.append(item)
@@ -306,14 +305,22 @@ def _get_mode_images(
306305

307306
def _call_permission_callback(
308307
self, callback: Union[str, Callable, None], request: HttpRequest
309-
):
308+
) -> bool:
310309
if callback is None:
311310
return True
312311

313312
if isinstance(callback, str):
314-
callback = import_string(callback)
313+
try:
314+
callback = import_string(callback)
315+
except ImportError:
316+
pass
317+
318+
if isinstance(callback, str) or isinstance(callback, Callable):
319+
# We are not able to use here "is" because type is lazy loaded function
320+
if lazy(callback)(request) == True: # noqa: E712
321+
return True
315322

316-
return callback(request)
323+
return False
317324

318325
def _get_value(
319326
self, instance: Union[str, Callable, None], *args: Any

0 commit comments

Comments
 (0)