mirror of
https://github.com/ansible/awx.git
synced 2024-10-31 15:21:13 +03:00
Local path choices for projects now only returns unused project paths.
This commit is contained in:
parent
98af899b49
commit
089098dc3f
@ -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 []
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user