chore: remove old history model access from original UI and API V1

ref: #601 #605 closes #606
This commit is contained in:
2025-02-16 05:10:23 +09:30
parent 24e4c95928
commit 57060975b0
6 changed files with 46 additions and 236 deletions

View File

@ -95,6 +95,34 @@ clear; \
``` ```
## Tips / Handy info
- To obtain a list of models _(in in the same order as the file system)_ using the db shell `python3 manage.py dbshell` run the following sql command:
``` sql
SELECT model FROM django_content_type ORDER BY app_label ASC, model ASC;
```
# Old working docs # Old working docs

View File

@ -1,3 +1,20 @@
## Version 1.11.0
- History views removed from original Centurion interface.
- History views removed from API v1.
## Version 1.10.0
- Nothing significant to report
## Version 1.9.0
- Nothing significant to report
## Version 1.8.0 ## Version 1.8.0
- Prometheus exporter added. To enable metrics for the database you will have to update the database backend. see the [docs](https://nofusscomputing.com/projects/centurion_erp/administration/monitoring/#django-exporter-setup) for further information. - Prometheus exporter added. To enable metrics for the database you will have to update the database backend. see the [docs](https://nofusscomputing.com/projects/centurion_erp/administration/monitoring/#django-exporter-setup) for further information.

View File

@ -24,7 +24,7 @@ from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView
from .views import home from .views import home
from core.views import history, related_ticket, ticket_linked_item from core.views import related_ticket, ticket_linked_item
from settings.views import user_settings from settings.views import user_settings
@ -47,7 +47,6 @@ urlpatterns = [
path("itim/", include("itim.urls")), path("itim/", include("itim.urls")),
path("config_management/", include("config_management.urls")), path("config_management/", include("config_management.urls")),
path("history/<str:model_name>/<int:model_pk>", history.View.as_view(), name='_history'),
re_path(r'^static/(?P<path>.*)$', serve,{'document_root': settings.STATIC_ROOT}), re_path(r'^static/(?P<path>.*)$', serve,{'document_root': settings.STATIC_ROOT}),

View File

@ -1,60 +0,0 @@
{% extends 'base.html.j2' %}
{% load json %}
{% block content %}
<script>
$('.clicker').click(function(){
$(this).nextUntil('.clicker').slideToggle('normal');
});
</script>
<style>
.hidden {
/*display: none;*/
}
.down {
display: unset;
}
</style>
<table style="max-width: 100%;">
<thead>
<th style="width: 25%;">Created</th>
<th style="width: 25%;">Action</th>
<th style="width: 25%;">Item</th>
<th style="width: 25%;">User</th>
</thead>
{% for entry in history %}
<tr class="clicker">
<td>{{ entry.created }}</td>
<td>
{% if entry.action == 1 %}
Create
{% elif entry.action == 2 %}
Update
{% elif entry.action == 3 %}
Delete
{% else %}
fuck knows
{% endif %}
</td>
<td>
{{ entry.item_class}}
</td>
<td>{{ entry.user }}</td>
<tr class="hidden">
<th colspan="2">Before</th>
<th colspan="2">Changed</th>
</tr>
<tr class="hidden">
<td colspan="2"><pre style="text-align: left; max-width: 300px;">{{ entry.before | json_pretty }}</pre></td>
<td colspan="2"><pre style="text-align: left; max-width: 300px;">{{ entry.after | json_pretty }}</pre></td>
</tr>
</tr>
{% endfor %}
</table>
{% endblock %}

View File

@ -1,165 +0,0 @@
from django.db.models import Q
from django.http import HttpResponseRedirect
from django.shortcuts import redirect, render
from django.views import generic
from access.mixin import OrganizationPermission
from core.models.history import History
class View(OrganizationPermission, generic.View):
permission_required = [
'core.view_history'
]
template_name = 'history.html.j2'
def get_object(self):
""" Get the history entry model
function required to check permissions, in particular that the user is in the same organization.
Raises:
Exception: if the model can't be found.
Returns:
Model: Returns the model Object
"""
from access.models import Organization, Team
from itam.models.device import Device, DeviceSoftware, DeviceModel, DeviceType, DeviceOperatingSystem
from itam.models.operating_system import OperatingSystem
from itam.models.software import Software, SoftwareCategory
from core.models.manufacturer import Manufacturer
from config_management.models.groups import ConfigGroups
from settings.models.external_link import ExternalLink
from project_management.models.projects import Project
if not hasattr(self, 'model'):
match str(self.kwargs['model_name']).lower():
case 'cluster':
from itim.models.clusters import Cluster
self.model = Cluster
case 'clustertype':
from itim.models.clusters import ClusterType
self.model = ClusterType
case 'configgroups':
self.model = ConfigGroups
case 'device':
self.model = Device
case 'devicemodel':
self.model = DeviceModel
case 'devicetype':
self.model = DeviceType
case 'externallink':
self.model = ExternalLink
case 'knowledgebase':
from assistance.models.knowledge_base import KnowledgeBase
self.model = KnowledgeBase
case 'knowledgebasecategory':
from assistance.models.knowledge_base import KnowledgeBaseCategory
self.model = KnowledgeBaseCategory
case 'manufacturer':
self.model = Manufacturer
case 'projectstate':
from project_management.models.project_states import ProjectState
self.model = ProjectState
case 'software':
self.model = Software
case 'softwarecategory':
self.model = SoftwareCategory
case 'operatingsystem':
self.model = OperatingSystem
case 'organization':
self.model = Organization
case 'port':
from itim.models.services import Port
self.model = Port
case 'team':
self.model = Team
case 'service':
from itim.models.services import Service
self.model = Service
case 'project':
self.model = Project
case _:
raise Exception('Unable to determine history items model')
if not hasattr(self, 'obj'):
self.obj = self.model.objects.get(id=self.kwargs['model_pk'])
return self.obj
def get(self, request, model_name, model_pk):
if not request.user.is_authenticated and settings.LOGIN_REQUIRED:
return redirect(f"{settings.LOGIN_URL}?next={request.path}")
context = {}
context['history'] = History.objects.filter(
Q(item_pk = model_pk, item_class = model_name)
|
Q(item_parent_pk = model_pk, item_parent_class = model_name)
)
context['content_title'] = 'History'
return render(request, self.template_name, context)

View File

@ -102,15 +102,6 @@ section h2 span svg {
{% include 'icons/help.svg' %} {% include 'icons/help.svg' %}
</span> </span>
{% endif %} {% endif %}
{% if model_name and model_pk %}
{% block content_header_icon %}
<span title="View History" id="content_header_icon" onclick="window.location='{% url '_history' model_name=model_name model_pk=model_pk as history_url %}{{ history_url|lower}}';">
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px">
<path d="M480-120q-138 0-240.5-91.5T122-440h82q14 104 92.5 172T480-200q117 0 198.5-81.5T760-480q0-117-81.5-198.5T480-760q-69 0-129 32t-101 88h110v80H120v-240h80v94q51-64 124.5-99T480-840q75 0 140.5 28.5t114 77q48.5 48.5 77 114T840-480q0 75-28.5 140.5t-77 114q-48.5 48.5-114 77T480-120Zm112-192L440-464v-216h80v184l128 128-56 56Z"/>
</svg>
</span>
{% endblock content_header_icon %}
{% endif %}
</h2> </h2>
{% if user.is_authenticated %} {% if user.is_authenticated %}
{% if not user_default_organization %} {% if not user_default_organization %}