diff --git a/src/unfold/sites.py b/src/unfold/sites.py index 4d22fe34..62471d32 100644 --- a/src/unfold/sites.py +++ b/src/unfold/sites.py @@ -233,9 +233,8 @@ def _get_is_active(link: str) -> bool: allowed_items = [] for item in group["items"]: - # Permission callbacks + # Skip item if permission check fails if not self._call_permission_callback(item.get("permission"), request): - # Skip item if permission check fails continue item["active"] = False @@ -280,8 +279,8 @@ def get_tabs_list(self, request: HttpRequest) -> List[Dict[str, Any]]: allowed_items = [] for item in tab["items"]: + # Skip item if permission check fails if not self._call_permission_callback(item.get("permission"), request): - # Skip item if permission check fails continue allowed_items.append(item) @@ -306,14 +305,22 @@ def _get_mode_images( def _call_permission_callback( self, callback: Union[str, Callable, None], request: HttpRequest - ): + ) -> bool: if callback is None: return True if isinstance(callback, str): - callback = import_string(callback) + try: + callback = import_string(callback) + except ImportError: + pass + + if isinstance(callback, str) or isinstance(callback, Callable): + # We are not able to use here "is" because type is lazy loaded function + if lazy(callback)(request) == True: # noqa: E712 + return True - return callback(request) + return False def _get_value( self, instance: Union[str, Callable, None], *args: Any