1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-02 08:56:07 +00:00

fix(logs): blocking a blocked user writes no row; one upload submit path

Follow-ups from the review of the audit log layers:

- Blocking a user who is already blocked, or unblocking one who is
  not, changes nothing and now writes no row, like any other edit
  that changes nothing.
- write_chunk takes the request instead of the user and an optional
  request; the view always had one, so the branch only tests used
  is gone and every chunk 0 goes through the same audited submit.
- Tests: a busy clone creates no job and its row carries the page's
  message; a later chunk that fails writes no submit row; libvirt
  refusing a network or pool delete is a failed row.
This commit is contained in:
catborise 2026-10-23 14:09:26 +03:00
parent d5df187de4
commit b24746c1cb
7 changed files with 52 additions and 29 deletions

View file

@ -498,21 +498,19 @@ def end(op, state, error=""):
pass
def write_chunk(user, conn, compute, pool, upload_id, raw, chunk_index, chunk, request=None):
def write_chunk(request, conn, compute, pool, upload_id, raw, chunk_index, chunk):
"""Write chunk chunk_index of the upload upload_id (the job's submission
key) and commit it on the job; the last chunk renames the image."""
kind = jobs.get_kind("volume.upload")
raw = {**raw, "compute": compute.pk, "pool": pool}
if chunk_index == 0 and request is not None:
if chunk_index == 0:
name = os.path.basename(str(raw["name"])).strip()
with audit(request, compute, f"Storage pool {pool}", f"upload volume {name}") as entry:
op = jobs.submit(kind.name, user, raw, upload_id)
op = jobs.submit(kind.name, request.user, raw, upload_id)
entry.skip = True # the job writes its row when it ends
jobs.remember_job(request, op)
elif chunk_index == 0:
op = jobs.submit(kind.name, user, raw, upload_id)
else:
op = Operation.objects.filter(user=user, submission_key=upload_id).first()
op = Operation.objects.filter(user=request.user, submission_key=upload_id).first()
if op is None:
raise ValueError(_("Upload session not found or expired"))
if op.kind != kind.name or op.params != kind.normalize(raw):