From 089098dc3f302a4d1dab9c792d9be42f86691bb8 Mon Sep 17 00:00:00 2001 From: Chris Church Date: Fri, 28 Jun 2013 21:44:26 -0400 Subject: [PATCH] Local path choices for projects now only returns unused project paths. --- awx/main/models/__init__.py | 9 ++++++--- awx/main/tests/projects.py | 12 ++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/awx/main/models/__init__.py b/awx/main/models/__init__.py index 719d3be86f..4d9c8617f2 100644 --- a/awx/main/models/__init__.py +++ b/awx/main/models/__init__.py @@ -475,9 +475,12 @@ class Project(CommonModel): @classmethod def get_local_path_choices(cls): if os.path.exists(settings.PROJECTS_ROOT): - return [x for x in os.listdir(settings.PROJECTS_ROOT) - if os.path.isdir(os.path.join(settings.PROJECTS_ROOT, x)) - and not x.startswith('.')] + paths = [x for x in os.listdir(settings.PROJECTS_ROOT) + if os.path.isdir(os.path.join(settings.PROJECTS_ROOT, x)) + and not x.startswith('.')] + qs = Project.objects.filter(active=True) + used_paths = qs.values_list('local_path', flat=True) + return [x for x in paths if x not in used_paths] else: return [] diff --git a/awx/main/tests/projects.py b/awx/main/tests/projects.py index ca34bddd05..4f61acb6e6 100644 --- a/awx/main/tests/projects.py +++ b/awx/main/tests/projects.py @@ -151,6 +151,18 @@ class ProjectsTest(BaseTest): self.assertEqual(set(response['project_local_paths']), set(Project.get_local_path_choices())) + # return local paths are only the ones not used by any active project. + qs = Project.objects.filter(active=True) + used_paths = qs.values_list('local_path', flat=True) + self.assertFalse(set(response['project_local_paths']) & set(used_paths)) + for project in self.projects: + local_path = project.local_path + response = self.get(url, expect=200, auth=self.get_super_credentials()) + self.assertTrue(local_path not in response['project_local_paths']) + project.mark_inactive() + response = self.get(url, expect=200, auth=self.get_super_credentials()) + self.assertTrue(local_path in response['project_local_paths']) + # org admin can read config and will get project fields. response = self.get(url, expect=200, auth=self.get_normal_credentials()) self.assertTrue('project_base_dir' in response)