Skip to content

Commit ea063c1

Browse files
committed
Fix type checking is_registered
1 parent 26d95eb commit ea063c1

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

ansible_base/rbac/permission_registry.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import inspect
12
import logging
23
from typing import Optional, Type, Union
34

@@ -10,6 +11,8 @@
1011

1112
from ansible_base.rbac.managed import ManagedRoleConstructor, get_managed_role_constructors
1213

14+
from .remote import RemoteObject
15+
1316
"""
1417
This will record the models that the RBAC system in this app will follow
1518
Other apps should register models with this pattern
@@ -205,8 +208,10 @@ def team_permission(self):
205208
def all_registered_models(self):
206209
return list(self._registry)
207210

208-
def is_registered(self, obj: Union[ModelBase, Model]) -> bool:
211+
def is_registered(self, obj: Union[ModelBase, Model, RemoteObject, Type[RemoteObject]]) -> bool:
209212
"""Tells if the given object or class is a type tracked by DAB RBAC"""
213+
if isinstance(obj, RemoteObject) or (inspect.isclass(obj) and issubclass(obj, RemoteObject)):
214+
return True # Pretty much the only way we can create these is via a registered type
210215
return any((obj._meta.model_name == cls._meta.model_name and obj._meta.app_label == cls._meta.app_label) for cls in self._registry)
211216

212217
def get_model_by_name(self, model_name: str) -> Optional[Type[Model]]:

0 commit comments

Comments
 (0)