mirror of
https://github.com/ansible/awx.git
synced 2026-03-20 02:17:37 -02:30
Local path choices for projects now only returns unused project paths.
This commit is contained in:
@@ -475,9 +475,12 @@ class Project(CommonModel):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def get_local_path_choices(cls):
|
def get_local_path_choices(cls):
|
||||||
if os.path.exists(settings.PROJECTS_ROOT):
|
if os.path.exists(settings.PROJECTS_ROOT):
|
||||||
return [x for x in os.listdir(settings.PROJECTS_ROOT)
|
paths = [x for x in os.listdir(settings.PROJECTS_ROOT)
|
||||||
if os.path.isdir(os.path.join(settings.PROJECTS_ROOT, x))
|
if os.path.isdir(os.path.join(settings.PROJECTS_ROOT, x))
|
||||||
and not x.startswith('.')]
|
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:
|
else:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|||||||
@@ -151,6 +151,18 @@ class ProjectsTest(BaseTest):
|
|||||||
self.assertEqual(set(response['project_local_paths']),
|
self.assertEqual(set(response['project_local_paths']),
|
||||||
set(Project.get_local_path_choices()))
|
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.
|
# org admin can read config and will get project fields.
|
||||||
response = self.get(url, expect=200, auth=self.get_normal_credentials())
|
response = self.get(url, expect=200, auth=self.get_normal_credentials())
|
||||||
self.assertTrue('project_base_dir' in response)
|
self.assertTrue('project_base_dir' in response)
|
||||||
|
|||||||
Reference in New Issue
Block a user