mirror of
https://github.com/ansible/awx.git
synced 2026-03-13 15:09:32 -02:30
Fixed projects creation api endpoints to take organization
This commit is contained in:
@@ -915,7 +915,7 @@ class ProjectSerializer(UnifiedJobTemplateSerializer, ProjectOptionsSerializer):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Project
|
model = Project
|
||||||
fields = ('*', 'scm_delete_on_next_update', 'scm_update_on_launch',
|
fields = ('*', 'organization', 'scm_delete_on_next_update', 'scm_update_on_launch',
|
||||||
'scm_update_cache_timeout') + \
|
'scm_update_cache_timeout') + \
|
||||||
('last_update_failed', 'last_updated') # Backwards compatibility
|
('last_update_failed', 'last_updated') # Backwards compatibility
|
||||||
read_only_fields = ('scm_delete_on_next_update',)
|
read_only_fields = ('scm_delete_on_next_update',)
|
||||||
|
|||||||
@@ -669,6 +669,7 @@ class OrganizationProjectsList(SubListCreateAPIView):
|
|||||||
serializer_class = ProjectSerializer
|
serializer_class = ProjectSerializer
|
||||||
parent_model = Organization
|
parent_model = Organization
|
||||||
relationship = 'projects'
|
relationship = 'projects'
|
||||||
|
parent_key = 'organization'
|
||||||
|
|
||||||
class OrganizationTeamsList(SubListCreateAttachDetachAPIView):
|
class OrganizationTeamsList(SubListCreateAttachDetachAPIView):
|
||||||
|
|
||||||
|
|||||||
@@ -167,6 +167,24 @@ def alice(user):
|
|||||||
def bob(user):
|
def bob(user):
|
||||||
return user('bob', False)
|
return user('bob', False)
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def rando(user):
|
||||||
|
"Rando, the random user that doesn't have access to anything"
|
||||||
|
return user('rando', False)
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def org_admin(user, organization):
|
||||||
|
ret = user('org-admin', False)
|
||||||
|
organization.admin_role.members.add(ret)
|
||||||
|
organization.member_role.members.add(ret)
|
||||||
|
return ret
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def org_member(user, organization):
|
||||||
|
ret = user('org-member', False)
|
||||||
|
organization.member_role.members.add(ret)
|
||||||
|
return ret
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def organizations(instance):
|
def organizations(instance):
|
||||||
def rf(organization_count=1):
|
def rf(organization_count=1):
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import mock # noqa
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
|
from awx.main.models import Project
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -95,3 +96,38 @@ def test_team_project_list(get, project_factory, team_factory, admin, alice, bob
|
|||||||
# alice should see all projects they can see when viewing an admin
|
# alice should see all projects they can see when viewing an admin
|
||||||
assert get(reverse('api:user_projects_list', args=(admin.pk,)), alice).data['count'] == 2
|
assert get(reverse('api:user_projects_list', args=(admin.pk,)), alice).data['count'] == 2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_create_project(post, organization, org_admin, org_member, admin, rando):
|
||||||
|
test_list = [rando, org_member, org_admin, admin]
|
||||||
|
expected_status_codes = [403, 403, 201, 201]
|
||||||
|
|
||||||
|
for i, u in enumerate(test_list):
|
||||||
|
result = post(reverse('api:project_list'), {
|
||||||
|
'name': 'Project %d' % i,
|
||||||
|
'organization': organization.id,
|
||||||
|
}, u)
|
||||||
|
assert result.status_code == expected_status_codes[i]
|
||||||
|
if expected_status_codes[i] == 201:
|
||||||
|
assert Project.objects.filter(name='Project %d' % i, organization=organization).exists()
|
||||||
|
else:
|
||||||
|
assert not Project.objects.filter(name='Project %d' % i, organization=organization).exists()
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_create_project_through_org_link(post, organization, org_admin, org_member, admin, rando):
|
||||||
|
test_list = [rando, org_member, org_admin, admin]
|
||||||
|
expected_status_codes = [403, 403, 201, 201]
|
||||||
|
|
||||||
|
for i, u in enumerate(test_list):
|
||||||
|
result = post(reverse('api:organization_projects_list', args=(organization.id,)), {
|
||||||
|
'name': 'Project %d' % i,
|
||||||
|
}, u)
|
||||||
|
assert result.status_code == expected_status_codes[i]
|
||||||
|
if expected_status_codes[i] == 201:
|
||||||
|
prj = Project.objects.get(name='Project %d' % i)
|
||||||
|
print(prj.organization)
|
||||||
|
Project.objects.get(name='Project %d' % i, organization=organization)
|
||||||
|
assert Project.objects.filter(name='Project %d' % i, organization=organization).exists()
|
||||||
|
else:
|
||||||
|
assert not Project.objects.filter(name='Project %d' % i, organization=organization).exists()
|
||||||
|
|||||||
Reference in New Issue
Block a user