Skip to content

Commit 3a723fe

Browse files
committed
Fix flake8 and simpler type ct calc
1 parent 193d9e7 commit 3a723fe

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

ansible_base/rbac/models/fields.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from django.db.models.sql import AND
1010
from django.db.models.sql.where import WhereNode
1111

12-
from ..remote import get_local_resource_prefix, get_remote_standin_class
12+
from ..remote import get_local_resource_prefix
1313
from .content_type import DABContentType
1414

1515

ansible_base/rbac/remote.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def get_ct_from_type(cls):
3434
if not hasattr(cls, '_meta'):
3535
raise ValueError('Generlized RemoteObject can not obtain content_type from its class')
3636
ct_model = apps.get_model('dab_rbac', 'DABContentType')
37-
return ct_model.objects.get_by_natural_key(cls._meta.service, cls._meta.app_label, cls._meta.model)
37+
return ct_model.objects.get_by_natural_key(cls._meta.service, cls._meta.app_label, cls._meta.model_name)
3838

3939

4040
def get_remote_base_class() -> Type[RemoteObject]:
@@ -118,7 +118,7 @@ def __init__(self, ct: models.Model):
118118
standin = type(
119119
name,
120120
(base,),
121-
{"_meta": StandinMeta(content_type), "type_data": (content_type.service, content_type.app_label, content_type.model)},
121+
{"_meta": StandinMeta(content_type)},
122122
)
123123
_REMOTE_STANDIN_CACHE[key] = standin
124124
return standin

ansible_base/rbac/validators.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,9 @@ def permissions_allowed_for_system_role() -> dict[Type[Model], list[str]]:
4646

4747
def permissions_allowed_for_remote_cls(cls: Type[RemoteObject]) -> dict[Union[Type[Model], Type[RemoteObject]], list[str]]:
4848
"Model is on remote server, return valid permissions via the content type definitions"
49-
from .models.content_type import DABContentType
50-
5149
permissions_by_model = defaultdict(list)
5250
# Add permissions for the current type
53-
cls_ct = DABContentType.objects.get_by_natural_key(*cls.type_data)
51+
cls_ct = cls.get_ct_from_type()
5452
for permission in cls_ct.dab_permissions.all():
5553
if not is_add_perm(permission.codename):
5654
permissions_by_model[cls].append(permission.codename)
@@ -120,7 +118,7 @@ def check_view_permission_criteria(codename_set: set[str], permissions_by_model:
120118
# if issubclass(cls, RemoteObject):
121119
# from .models.content_type import DABContentType
122120

123-
# cls_ct = DABContentType.objects.get_by_natural_key(*cls.type_data)
121+
# cls_ct = cls.get_ct_from_type()
124122
# if any(permission.codename.startswith('view') for permission in cls_ct.permissions.all()):
125123
if any('view' in codename for codename in valid_model_permissions):
126124
model_permissions = set(valid_model_permissions) & codename_set

0 commit comments

Comments
 (0)