-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to disable change log (history) for attributes (#298)
Make it possible to exclude attributes from change log updates. Some attributes, e.g. backup locking, are changed frequently but the change log of these irrelevant. They just bloat the change log. This commit makes it possible to configure such attributes so that the changes are not logged.
- Loading branch information
Showing
6 changed files
with
177 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
[ | ||
{ | ||
"model": "serverdb.servertype", | ||
"pk": "project", | ||
"fields": { | ||
"description": "Project information", | ||
"ip_addr_type": "null" | ||
} | ||
}, | ||
{ | ||
"model": "serverdb.attribute", | ||
"pk": "last_updated", | ||
"fields": { | ||
"type": "datetime", | ||
"multi": false, | ||
"hovertext": "", | ||
"group": "project", | ||
"help_link": null, | ||
"readonly": false, | ||
"target_servertype": null, | ||
"reversed_attribute": null, | ||
"clone": false, | ||
"history": false, | ||
"regexp": "\\A.*\\Z" | ||
} | ||
}, | ||
{ | ||
"model": "serverdb.attribute", | ||
"pk": "owner", | ||
"fields": { | ||
"type": "string", | ||
"multi": false, | ||
"hovertext": "", | ||
"group": "project", | ||
"help_link": null, | ||
"readonly": false, | ||
"target_servertype": null, | ||
"reversed_attribute": null, | ||
"clone": false, | ||
"history": true, | ||
"regexp": "\\A.*\\Z" | ||
} | ||
}, | ||
{ | ||
"model": "serverdb.servertypeattribute", | ||
"pk": 1, | ||
"fields": { | ||
"servertype": "project", | ||
"attribute": "owner", | ||
"related_via_attribute": null, | ||
"consistent_via_attribute": null, | ||
"required": false, | ||
"default_value": null, | ||
"default_visible": true | ||
} | ||
}, | ||
{ | ||
"model": "serverdb.servertypeattribute", | ||
"pk": 2, | ||
"fields": { | ||
"servertype": "project", | ||
"attribute": "last_updated", | ||
"related_via_attribute": null, | ||
"consistent_via_attribute": null, | ||
"required": false, | ||
"default_value": null, | ||
"default_visible": true | ||
} | ||
} | ||
] |
19 changes: 19 additions & 0 deletions
19
serveradmin/serverdb/migrations/0015_attribute_history_field.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Generated by Django 3.2.18 on 2023-03-02 09:12 | ||
|
||
from django.db import migrations, models | ||
import serveradmin.serverdb.models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('serverdb', '0014_delete_deprecated_change_models'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='attribute', | ||
name='history', | ||
field=models.BooleanField(default=True, help_text='Log changes to this attribute') | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from django.contrib.auth.models import User | ||
from django.test import TransactionTestCase | ||
from django.utils.timezone import now | ||
from faker import Faker | ||
from faker.providers import internet | ||
|
||
from serveradmin.dataset import Query | ||
from serveradmin.serverdb.models import Change | ||
|
||
|
||
class TestAttributeHistory(TransactionTestCase): | ||
fixtures = ['auth_user.json', 'attribute.json'] | ||
|
||
def setUp(self): | ||
super().setUp() | ||
self.faker = Faker() | ||
self.faker.add_provider(internet) | ||
|
||
def test_attribute_history_is_logged(self): | ||
project = Query().new_object('project') | ||
project['hostname'] = self.faker.hostname() | ||
project['owner'] = 'john.doe' # Attribute with history enabled | ||
project.commit(user=User.objects.first()) | ||
|
||
projects = Query({'hostname': project['hostname']}, ['owner']) | ||
projects.update(owner='max.mustermann') | ||
projects.commit(user=User.objects.first()) | ||
oid = projects.get()['object_id'] | ||
|
||
change = Change.objects.last() | ||
self.assertEqual(change.change_json, {"owner": {"new": "max.mustermann", "old": "john.doe", "action": "update"}, "object_id": oid}) | ||
|
||
def test_attribute_history_is_not_logged(self): | ||
project = Query().new_object('project') | ||
project['hostname'] = self.faker.hostname() | ||
project['last_updated'] = now() # Attribute with history disabled | ||
project.commit(user=User.objects.first()) | ||
|
||
projects = Query({'hostname': project['hostname']}, ['last_updated']) | ||
projects.update(last_updated=now()) | ||
projects.commit(user=User.objects.first()) | ||
oid = projects.get()['object_id'] | ||
|
||
self.assertEqual(Change.objects.filter(change_type=Change.Type.CHANGE, object_id=oid).count(), 0) | ||
|
||
def test_only_required_attribute_history_is_logged(self): | ||
project = Query().new_object('project') | ||
project['hostname'] = self.faker.hostname() | ||
project['owner'] = 'john.doe' # Attribute with history enabled | ||
project['last_updated'] = now() # Attribute with history disabled | ||
project.commit(user=User.objects.first()) | ||
|
||
projects = Query({'hostname': project['hostname']}, ['owner', 'last_updated']) | ||
projects.update(owner='max.mustermann', last_updated=now()) | ||
projects.commit(user=User.objects.first()) | ||
oid = projects.get()['object_id'] | ||
|
||
change = Change.objects.last() | ||
self.assertEqual(change.change_json, {"owner": {"new": "max.mustermann", "old": "john.doe", "action": "update"}, "object_id": oid}) |