mirror of
https://github.com/ansible/awx.git
synced 2026-05-12 03:47:36 -02:30
Check survey license enabled when creating, updating, and starting job
templates with surveys enabled
This commit is contained in:
@@ -1700,6 +1700,7 @@ class JobTemplateDetail(RetrieveUpdateDestroyAPIView):
|
|||||||
|
|
||||||
model = JobTemplate
|
model = JobTemplate
|
||||||
serializer_class = JobTemplateSerializer
|
serializer_class = JobTemplateSerializer
|
||||||
|
always_allow_superuser = False
|
||||||
|
|
||||||
def destroy(self, request, *args, **kwargs):
|
def destroy(self, request, *args, **kwargs):
|
||||||
obj = self.get_object()
|
obj = self.get_object()
|
||||||
|
|||||||
@@ -925,6 +925,9 @@ class JobTemplateAccess(BaseAccess):
|
|||||||
if 'job_type' in data and data['job_type'] == PERM_INVENTORY_SCAN:
|
if 'job_type' in data and data['job_type'] == PERM_INVENTORY_SCAN:
|
||||||
self.check_license(feature='system_tracking')
|
self.check_license(feature='system_tracking')
|
||||||
|
|
||||||
|
if 'survey_enabled' in data and data['survey_enabled']:
|
||||||
|
self.check_license(feature='surveys')
|
||||||
|
|
||||||
if self.user.is_superuser:
|
if self.user.is_superuser:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -997,11 +1000,11 @@ class JobTemplateAccess(BaseAccess):
|
|||||||
def can_start(self, obj, validate_license=True):
|
def can_start(self, obj, validate_license=True):
|
||||||
# Check license.
|
# Check license.
|
||||||
if validate_license:
|
if validate_license:
|
||||||
k = {}
|
self.check_license()
|
||||||
if obj.job_type == PERM_INVENTORY_SCAN:
|
if obj.job_type == PERM_INVENTORY_SCAN:
|
||||||
print("In perm inv scan test")
|
self.check_license(feature='system_tracking')
|
||||||
k = dict(feature='system_tracking')
|
if obj.survey_enabled:
|
||||||
self.check_license(**k)
|
self.check_license(feature='surveys')
|
||||||
|
|
||||||
# Super users can start any job
|
# Super users can start any job
|
||||||
if self.user.is_superuser:
|
if self.user.is_superuser:
|
||||||
|
|||||||
@@ -1038,6 +1038,27 @@ class JobTemplateSurveyTest(BaseJobTestMixin, django.test.TestCase):
|
|||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
super(JobTemplateSurveyTest, self).tearDown()
|
super(JobTemplateSurveyTest, self).tearDown()
|
||||||
|
|
||||||
|
def test_post_patch_job_template_survey_wrong_license(self):
|
||||||
|
url = reverse('api:job_template_list')
|
||||||
|
data = dict(
|
||||||
|
name = 'launched job template',
|
||||||
|
job_type = PERM_INVENTORY_DEPLOY,
|
||||||
|
inventory = self.inv_eng.pk,
|
||||||
|
project = self.proj_dev.pk,
|
||||||
|
playbook = self.proj_dev.playbooks[0],
|
||||||
|
credential = self.cred_sue.pk,
|
||||||
|
survey_enabled = True,
|
||||||
|
)
|
||||||
|
self.create_test_license_file(features=dict(surveys=False))
|
||||||
|
with self.current_user(self.user_sue):
|
||||||
|
self.post(url, data, expect=402)
|
||||||
|
data['survey_enabled'] = False
|
||||||
|
with self.current_user(self.user_sue):
|
||||||
|
response = self.post(url, data, expect=201)
|
||||||
|
jt_url = reverse('api:job_template_detail', args=(response['id'],))
|
||||||
|
with self.current_user(self.user_sue):
|
||||||
|
self.patch(jt_url, dict(survey_enabled=True), expect=402)
|
||||||
|
|
||||||
def test_post_job_template_survey(self):
|
def test_post_job_template_survey(self):
|
||||||
url = reverse('api:job_template_list')
|
url = reverse('api:job_template_list')
|
||||||
data = dict(
|
data = dict(
|
||||||
|
|||||||
Reference in New Issue
Block a user