mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 09:27:36 -02:30
fix adhoc IG bug and prevent related inventory deletion
This commit is contained in:
@@ -613,6 +613,8 @@ class InventoryAccess(BaseAccess):
|
|||||||
for o in Job.objects.filter(inventory=obj, status__in=ACTIVE_STATES)])
|
for o in Job.objects.filter(inventory=obj, status__in=ACTIVE_STATES)])
|
||||||
active_jobs.extend([dict(type="inventory_update", id=o.id)
|
active_jobs.extend([dict(type="inventory_update", id=o.id)
|
||||||
for o in InventoryUpdate.objects.filter(inventory_source__inventory=obj, status__in=ACTIVE_STATES)])
|
for o in InventoryUpdate.objects.filter(inventory_source__inventory=obj, status__in=ACTIVE_STATES)])
|
||||||
|
active_jobs.extend([dict(type="ad_hoc_command", id=o.id)
|
||||||
|
for o in AdHocCommand.objects.filter(inventory=obj, status__in=ACTIVE_STATES)])
|
||||||
if len(active_jobs) > 0:
|
if len(active_jobs) > 0:
|
||||||
raise StateConflict({"conflict": _("Resource is being used by running jobs"),
|
raise StateConflict({"conflict": _("Resource is being used by running jobs"),
|
||||||
"active_jobs": active_jobs})
|
"active_jobs": active_jobs})
|
||||||
|
|||||||
@@ -218,6 +218,8 @@ class AdHocCommand(UnifiedJob, JobNotificationMixin):
|
|||||||
organization_groups = []
|
organization_groups = []
|
||||||
if self.inventory is not None:
|
if self.inventory is not None:
|
||||||
inventory_groups = [x for x in self.inventory.instance_groups.all()]
|
inventory_groups = [x for x in self.inventory.instance_groups.all()]
|
||||||
|
else:
|
||||||
|
inventory_groups = []
|
||||||
selected_groups = inventory_groups + organization_groups
|
selected_groups = inventory_groups + organization_groups
|
||||||
if not selected_groups:
|
if not selected_groups:
|
||||||
return self.global_instance_groups
|
return self.global_instance_groups
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ import pytest
|
|||||||
from awx.main.models import (
|
from awx.main.models import (
|
||||||
Host,
|
Host,
|
||||||
CustomInventoryScript,
|
CustomInventoryScript,
|
||||||
Schedule
|
Schedule,
|
||||||
|
AdHocCommand
|
||||||
)
|
)
|
||||||
from awx.main.access import (
|
from awx.main.access import (
|
||||||
InventoryAccess,
|
InventoryAccess,
|
||||||
@@ -11,10 +12,19 @@ from awx.main.access import (
|
|||||||
HostAccess,
|
HostAccess,
|
||||||
InventoryUpdateAccess,
|
InventoryUpdateAccess,
|
||||||
CustomInventoryScriptAccess,
|
CustomInventoryScriptAccess,
|
||||||
ScheduleAccess
|
ScheduleAccess,
|
||||||
|
StateConflict
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_running_job_protection(inventory, admin_user):
|
||||||
|
AdHocCommand.objects.create(inventory=inventory, status='running')
|
||||||
|
access = InventoryAccess(admin_user)
|
||||||
|
with pytest.raises(StateConflict):
|
||||||
|
access.can_delete(inventory)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_custom_inv_script_access(organization, user):
|
def test_custom_inv_script_access(organization, user):
|
||||||
u = user('user', False)
|
u = user('user', False)
|
||||||
|
|||||||
Reference in New Issue
Block a user