mirror of
https://github.com/ansible/awx.git
synced 2024-11-02 09:51:09 +03:00
do not update modified_by for system fields
This commit is contained in:
parent
43aab10d18
commit
68975572f3
@ -256,6 +256,7 @@ class PrimordialModel(CreatedModifiedModel):
|
|||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
update_fields = kwargs.get('update_fields', [])
|
update_fields = kwargs.get('update_fields', [])
|
||||||
|
fields_are_specified = bool(update_fields)
|
||||||
user = get_current_user()
|
user = get_current_user()
|
||||||
if user and not user.id:
|
if user and not user.id:
|
||||||
user = None
|
user = None
|
||||||
@ -263,6 +264,11 @@ class PrimordialModel(CreatedModifiedModel):
|
|||||||
self.created_by = user
|
self.created_by = user
|
||||||
if 'created_by' not in update_fields:
|
if 'created_by' not in update_fields:
|
||||||
update_fields.append('created_by')
|
update_fields.append('created_by')
|
||||||
|
# Update modified_by if not called with update_fields, or if any
|
||||||
|
# editable fields are present in update_fields
|
||||||
|
if (
|
||||||
|
(not fields_are_specified) or
|
||||||
|
any(getattr(self._meta.get_field(name), 'editable', True) for name in update_fields)):
|
||||||
self.modified_by = user
|
self.modified_by = user
|
||||||
if 'modified_by' not in update_fields:
|
if 'modified_by' not in update_fields:
|
||||||
update_fields.append('modified_by')
|
update_fields.append('modified_by')
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from awx.main.models import JobTemplate, Job
|
from awx.main.models import JobTemplate, Job
|
||||||
|
from crum import impersonate
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
@ -49,3 +50,18 @@ def test_awx_custom_virtualenv_without_jt(project):
|
|||||||
|
|
||||||
job = Job.objects.get(pk=job.id)
|
job = Job.objects.get(pk=job.id)
|
||||||
assert job.ansible_virtualenv_path == '/venv/fancy-proj'
|
assert job.ansible_virtualenv_path == '/venv/fancy-proj'
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_update_parent_instance(job_template, alice):
|
||||||
|
# jobs are launched as a particular user, user not saved as modified_by
|
||||||
|
with impersonate(alice):
|
||||||
|
assert job_template.current_job is None
|
||||||
|
assert job_template.status == 'never updated'
|
||||||
|
assert job_template.modified_by is None
|
||||||
|
job = job_template.jobs.create(status='new')
|
||||||
|
job.status = 'pending'
|
||||||
|
job.save()
|
||||||
|
assert job_template.current_job == job
|
||||||
|
assert job_template.status == 'pending'
|
||||||
|
assert job_template.modified_by is None
|
||||||
|
Loading…
Reference in New Issue
Block a user