mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-11 04:36:48 +00:00
feat(logs): changes to users, groups, owners, flavors and settings are logged
The Logs page now records the panel's own records too: users (add, change with the changed fields, delete, block, unblock, an admin's password set, a user's own password change including the first-login one, own profile edits), groups with their members and permissions, VM owners from the accounts pages and from the VM page, OTP QR code mails, flavors from web and API, app settings and the theme, removed-VM records and SSH keys. No row carries a password or a key. - A user is created in one transaction: when a VM named in NEW_USER_DEFAULT_INSTANCES is missing, no half-made user stays. - The OTP mail checks the email address before it creates a device; without one it writes a failed row and makes no device. - The VM page's owner rows read "VM web-1 owner bob: add" and "...: remove" instead of "Add owner: bob" and "Delete owner: 17"; a second owner refused by the single-owner setting is a failed row. Owner rows keep the VM's host and name, so the VM's log tab shows them. - A setting or theme posted with its current value is no change and writes no row; the old free-text setting rows are gone. Host-side objects (networks, storage, interfaces, secrets, filters) follow in the next layer.
This commit is contained in:
parent
8c0fbff8f7
commit
e04adec87b
10 changed files with 468 additions and 46 deletions
|
|
@ -16,6 +16,7 @@ from instances.views import (
|
|||
suspend,
|
||||
)
|
||||
from drf_spectacular.utils import extend_schema
|
||||
from logs.audit import audit, changed_fields, snapshot
|
||||
from operations import jobs
|
||||
from operations.api.serializers import OperationSerializer
|
||||
from rest_framework import permissions, status, viewsets
|
||||
|
|
@ -210,6 +211,23 @@ class FlavorViewSet(viewsets.ModelViewSet):
|
|||
return [permissions.IsAuthenticated()]
|
||||
return [IsSuperUser()]
|
||||
|
||||
def perform_create(self, serializer):
|
||||
with audit(self.request, None, f"Flavor {serializer.validated_data['label']}", "add"):
|
||||
serializer.save()
|
||||
|
||||
def perform_update(self, serializer):
|
||||
flavor = serializer.instance
|
||||
subject, before = f"Flavor {flavor.label}", snapshot(flavor)
|
||||
with audit(self.request, None, subject, "change") as entry:
|
||||
serializer.save()
|
||||
fields = changed_fields(before, snapshot(flavor))
|
||||
entry.action = "change " + ", ".join(fields)
|
||||
entry.skip = not fields
|
||||
|
||||
def perform_destroy(self, instance):
|
||||
with audit(self.request, None, f"Flavor {instance.label}", "delete"):
|
||||
instance.delete()
|
||||
|
||||
|
||||
class CreateInstanceViewSet(viewsets.ViewSet):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue