feat(access): Save changes to history for organization and teams
!9 closes #5
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
# Generated by Django 5.0.6 on 2024-05-23 03:08
|
||||
# Generated by Django 5.0.6 on 2024-05-23 03:59
|
||||
|
||||
import access.fields
|
||||
import django.db.models.deletion
|
||||
@ -10,7 +10,6 @@ from django.db import migrations, models
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('access', '0001_initial'),
|
||||
('core', '0002_remove_notes_serial_number_alter_notes_device_and_more'),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
@ -24,7 +23,6 @@ class Migration(migrations.Migration):
|
||||
migrations.CreateModel(
|
||||
name='History',
|
||||
fields=[
|
||||
('is_global', models.BooleanField(default=False)),
|
||||
('id', models.AutoField(primary_key=True, serialize=False, unique=True)),
|
||||
('created', access.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False)),
|
||||
('before', models.TextField(blank=True, default=None, help_text='JSON Object before Change', null=True)),
|
||||
@ -34,7 +32,6 @@ class Migration(migrations.Migration):
|
||||
('item_class', models.CharField(default=None, max_length=50, null=True)),
|
||||
('item_parent_pk', models.IntegerField(default=None, null=True)),
|
||||
('item_parent_class', models.CharField(default=None, max_length=50, null=True)),
|
||||
('organization', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='access.organization')),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={
|
||||
|
@ -115,6 +115,16 @@ class SaveHistory(models.Model):
|
||||
item_parent_pk = self.software.pk
|
||||
item_parent_class = self.software._meta.model_name
|
||||
|
||||
if self._meta.model_name == 'team':
|
||||
|
||||
item_parent_pk = self.organization.pk
|
||||
item_parent_class = self.organization._meta.model_name
|
||||
|
||||
if self._meta.model_name == 'teamusers':
|
||||
|
||||
item_parent_pk = self.team.pk
|
||||
item_parent_class = self.team._meta.model_name
|
||||
|
||||
|
||||
if not before:
|
||||
|
||||
@ -131,8 +141,6 @@ class SaveHistory(models.Model):
|
||||
|
||||
if before != after and after != '{}':
|
||||
entry = History.objects.create(
|
||||
organization = self.organization,
|
||||
is_global = False,
|
||||
before = before_json,
|
||||
after = after,
|
||||
user = get_request().user,
|
||||
|
@ -2,11 +2,9 @@ from django.contrib.auth.models import User
|
||||
from django.db import models
|
||||
|
||||
from access.fields import *
|
||||
from access.models import TenancyObject
|
||||
|
||||
|
||||
|
||||
class NotesCommonFields(models.Model):
|
||||
class HistoryCommonFields(models.Model):
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
@ -21,7 +19,7 @@ class NotesCommonFields(models.Model):
|
||||
|
||||
|
||||
|
||||
class History(TenancyObject, NotesCommonFields):
|
||||
class History(HistoryCommonFields):
|
||||
|
||||
|
||||
class Meta:
|
||||
|
@ -172,3 +172,81 @@ def test_history_software_version_delete():
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="to be written")
|
||||
def test_history_organization_create():
|
||||
""" History row must be added to history table on create """
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="to be written")
|
||||
def test_history_organization_update():
|
||||
""" History row must be added to history table on updatej """
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="to be written")
|
||||
def test_history_organization_delete():
|
||||
""" History row must be added to history table on delete """
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="to be written")
|
||||
def test_history_organization_team_create():
|
||||
""" History row must be added to history table on create """
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="to be written")
|
||||
def test_history_organization_team_update():
|
||||
""" History row must be added to history table on updatej """
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="to be written")
|
||||
def test_history_organization_team_delete():
|
||||
""" History row must be added to history table on delete """
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="to be written")
|
||||
def test_history_team_create():
|
||||
""" History row must be added to history table on create """
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="to be written")
|
||||
def test_history_team_update():
|
||||
""" History row must be added to history table on updatej """
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="to be written")
|
||||
def test_history_team_delete():
|
||||
""" History row must be added to history table on delete """
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="to be written")
|
||||
def test_history_team_users_create():
|
||||
""" History row must be added to history table on create """
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="to be written")
|
||||
def test_history_team_users_update():
|
||||
""" History row must be added to history table on updatej """
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="to be written")
|
||||
def test_history_team_users_delete():
|
||||
""" History row must be added to history table on delete """
|
||||
pass
|
||||
|
Reference in New Issue
Block a user