mirror of
https://github.com/ansible/awx.git
synced 2026-02-22 21:46:00 -03:30
make CustomInvetoryScript a resource.
This commit is contained in:
@@ -141,6 +141,21 @@ class Migration(migrations.Migration):
|
|||||||
name='updater_role',
|
name='updater_role',
|
||||||
field=awx.main.fields.ImplicitRoleField(related_name='+', to='main.Role', null=b'True'),
|
field=awx.main.fields.ImplicitRoleField(related_name='+', to='main.Role', null=b'True'),
|
||||||
),
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='custominventoryscript',
|
||||||
|
name='admin_role',
|
||||||
|
field=awx.main.fields.ImplicitRoleField(related_name='+', to='main.Role', null=b'True'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='custominventoryscript',
|
||||||
|
name='auditor_role',
|
||||||
|
field=awx.main.fields.ImplicitRoleField(related_name='+', to='main.Role', null=b'True'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='custominventoryscript',
|
||||||
|
name='member_role',
|
||||||
|
field=awx.main.fields.ImplicitRoleField(related_name='+', to='main.Role', null=b'True'),
|
||||||
|
),
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='jobtemplate',
|
model_name='jobtemplate',
|
||||||
name='admin_role',
|
name='admin_role',
|
||||||
|
|||||||
@@ -1264,7 +1264,7 @@ class InventoryUpdate(UnifiedJob, InventorySourceOptions):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class CustomInventoryScript(CommonModelNameNotUnique):
|
class CustomInventoryScript(CommonModelNameNotUnique, ResourceMixin):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
app_label = 'main'
|
app_label = 'main'
|
||||||
@@ -1285,6 +1285,27 @@ class CustomInventoryScript(CommonModelNameNotUnique):
|
|||||||
on_delete=models.SET_NULL,
|
on_delete=models.SET_NULL,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
admin_role = ImplicitRoleField(
|
||||||
|
role_name='CustomInventory Administrator',
|
||||||
|
role_description='May manage this inventory',
|
||||||
|
parent_role='organization.admin_role',
|
||||||
|
permissions = {'all': True}
|
||||||
|
)
|
||||||
|
|
||||||
|
member_role = ImplicitRoleField(
|
||||||
|
role_name='CustomInventory Member',
|
||||||
|
role_description='May view but not modify this inventory',
|
||||||
|
parent_role='organization.member_role',
|
||||||
|
permissions = {'read': True}
|
||||||
|
)
|
||||||
|
|
||||||
|
auditor_role = ImplicitRoleField(
|
||||||
|
role_name='CustomInventory Auditor',
|
||||||
|
role_description='May view but not modify this inventory',
|
||||||
|
parent_role='organization.auditor_role',
|
||||||
|
permissions = {'read': True}
|
||||||
|
)
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return reverse('api:inventory_script_detail', args=(self.pk,))
|
return reverse('api:inventory_script_detail', args=(self.pk,))
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,25 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from awx.main.migrations import _rbac as rbac
|
from awx.main.migrations import _rbac as rbac
|
||||||
from awx.main.models import Permission, Host
|
from awx.main.models import (
|
||||||
|
Permission,
|
||||||
|
Host,
|
||||||
|
CustomInventoryScript,
|
||||||
|
)
|
||||||
from awx.main.access import InventoryAccess
|
from awx.main.access import InventoryAccess
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_custom_inv_script_access(organization, user):
|
||||||
|
u = user('user', False)
|
||||||
|
|
||||||
|
custom_inv = CustomInventoryScript.objects.create(name='test', script='test', description='test')
|
||||||
|
custom_inv.organization = organization
|
||||||
|
assert not custom_inv.accessible_by(u, {'read':True})
|
||||||
|
|
||||||
|
organization.member_role.members.add(u)
|
||||||
|
assert custom_inv.accessible_by(u, {'read':True})
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_inventory_admin_user(inventory, permissions, user):
|
def test_inventory_admin_user(inventory, permissions, user):
|
||||||
u = user('admin', False)
|
u = user('admin', False)
|
||||||
|
|||||||
Reference in New Issue
Block a user