Generalize can_delete solution, use devel DAB (#15009)

* Generalize can_delete solution, use devel DAB

* Fix bug where model was used instead of model_name

* Linter fixes
This commit is contained in:
Alan Rominger
2024-03-19 13:29:34 -04:00
parent 733478ee19
commit 2f3c9122fd
4 changed files with 8 additions and 8 deletions

View File

@@ -23,6 +23,7 @@ from awx.main.models.oauth import OAuth2Application, OAuth2AccessToken
# django-ansible-base # django-ansible-base
from ansible_base.lib.utils.validation import to_python_boolean from ansible_base.lib.utils.validation import to_python_boolean
from ansible_base.rbac.models import RoleEvaluation from ansible_base.rbac.models import RoleEvaluation
from ansible_base.rbac import permission_registry
# AWX # AWX
from awx.main.utils import ( from awx.main.utils import (
@@ -264,7 +265,11 @@ class BaseAccess(object):
return self.can_change(obj, data) return self.can_change(obj, data)
def can_delete(self, obj): def can_delete(self, obj):
return self.user.has_obj_perm(obj, 'delete') if self.user.is_superuser:
return True
if obj._meta.model_name in [cls._meta.model_name for cls in permission_registry.all_registered_models]:
return self.user.has_obj_perm(obj, 'delete')
return False
def can_copy(self, obj): def can_copy(self, obj):
return self.can_add({'reference_obj': obj}) return self.can_add({'reference_obj': obj})
@@ -2940,9 +2945,6 @@ class WorkflowApprovalAccess(BaseAccess):
if (obj.workflow_job_template and self.user in obj.workflow_job_template.approval_role) or self.user.is_superuser: if (obj.workflow_job_template and self.user in obj.workflow_job_template.approval_role) or self.user.is_superuser:
return True return True
def can_delete(self, obj):
return self.user.is_superuser # Not really supposed to be done
class WorkflowApprovalTemplateAccess(BaseAccess): class WorkflowApprovalTemplateAccess(BaseAccess):
""" """

View File

@@ -1,7 +1,6 @@
# Generated by Django 4.2.6 on 2023-11-13 20:10 # Generated by Django 4.2.6 on 2023-11-13 20:10
from django.db import migrations, models from django.db import migrations
import django.db.models.deletion
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@@ -7,7 +7,6 @@ from django.conf import settings
from django.db import models from django.db import models
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.contrib.sessions.models import Session from django.contrib.sessions.models import Session
from django.contrib.contenttypes.models import ContentType
from django.utils.timezone import now as tz_now from django.utils.timezone import now as tz_now
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _

View File

@@ -5,4 +5,4 @@ git+https://github.com/ansible/ansible-runner.git@devel#egg=ansible-runner
# specifically need https://github.com/robgolding/django-radius/pull/27 # specifically need https://github.com/robgolding/django-radius/pull/27
git+https://github.com/ansible/django-radius.git@develop#egg=django-radius git+https://github.com/ansible/django-radius.git@develop#egg=django-radius
git+https://github.com/ansible/python3-saml.git@devel#egg=python3-saml git+https://github.com/ansible/python3-saml.git@devel#egg=python3-saml
django-ansible-base @ git+https://github.com/alancoding/django-ansible-base@django_permissions#egg=django-ansible-base[rest_filters,jwt_consumer,resource_registry,rbac] django-ansible-base @ git+https://github.com/ansible/django-ansible-base@devel#egg=django-ansible-base[rest_filters,jwt_consumer,resource_registry,rbac]