Compare commits

...

2 commits

Author SHA1 Message Date
5e527ef10d Release 0.15.1 2023-07-23 11:24:46 +02:00
3b6d50a62a Remove stale disk usage stats 2023-07-23 11:24:10 +02:00
4 changed files with 22 additions and 6 deletions

View file

@ -1,6 +1,9 @@
Changelog Changelog
========= =========
* :release:`0.15.1 <2023-07-23>
* :bug:`-` remove stale disk usage stats older than 30 minutes
* :release:`0.15.0 <2023-07-23> * :release:`0.15.0 <2023-07-23>
* :feature:`10` add disk usage details for mail and web * :feature:`10` add disk usage details for mail and web

View file

@ -1,4 +1,4 @@
# import celery_app to initialize it # import celery_app to initialize it
from gnuviechadmin.celery import app as celery_app # NOQA from gnuviechadmin.celery import app as celery_app # NOQA
__version__ = "0.15.0" __version__ = "0.15.1"

View file

@ -6,6 +6,7 @@ from __future__ import absolute_import
import http import http
import logging import logging
from datetime import timedelta
from django.conf import settings from django.conf import settings
from django.contrib import messages from django.contrib import messages
@ -13,6 +14,7 @@ from django.contrib.auth import get_user_model
from django.contrib.auth.mixins import PermissionRequiredMixin, UserPassesTestMixin from django.contrib.auth.mixins import PermissionRequiredMixin, UserPassesTestMixin
from django.http import Http404 from django.http import Http404
from django.shortcuts import get_object_or_404, redirect from django.shortcuts import get_object_or_404, redirect
from django.utils import timezone
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
from django.views.generic import DetailView, ListView from django.views.generic import DetailView, ListView
from django.views.generic.edit import CreateView, FormView from django.views.generic.edit import CreateView, FormView
@ -292,12 +294,15 @@ class UploadCustomerPackageDiskUsage(APIView):
if request.content_type != "application/json": if request.content_type != "application/json":
return Response("Unacceptable", status=http.HTTPStatus.BAD_REQUEST) return Response("Unacceptable", status=http.HTTPStatus.BAD_REQUEST)
submitted_sources = set()
for row in request.data: for row in request.data:
user = row["user"] user = row["user"]
for key in row: for key in row:
if key == "user": if key == "user":
continue continue
else: else:
submitted_sources.add(key)
for item, size in row[key].items(): for item, size in row[key].items():
try: try:
package = CustomerHostingPackage.objects.get( package = CustomerHostingPackage.objects.get(
@ -315,7 +320,9 @@ class UploadCustomerPackageDiskUsage(APIView):
if key == "mail": if key == "mail":
try: try:
ma_mb = package.mailboxes.get(username=item).mailaddressmailbox_set.first() ma_mb = package.mailboxes.get(
username=item
).mailaddressmailbox_set.first()
if ma_mb: if ma_mb:
metric.email_address_id = ma_mb.mailaddress_id metric.email_address_id = ma_mb.mailaddress_id
except Mailbox.DoesNotExist: except Mailbox.DoesNotExist:
@ -327,6 +334,12 @@ class UploadCustomerPackageDiskUsage(APIView):
"hosting package for user %s does not exist", user "hosting package for user %s does not exist", user
) )
if submitted_sources:
CustomerPackageDiskUsage.objects.filter(
source__in=submitted_sources,
modified__lt=timezone.now() - timedelta(minutes=30),
).delete()
logger.info("usage data submitted by %s", request.user) logger.info("usage data submitted by %s", request.user)
return Response("Accepted", status=http.HTTPStatus.ACCEPTED) return Response("Accepted", status=http.HTTPStatus.ACCEPTED)

View file

@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "gva" name = "gva"
version = "0.15.0" version = "0.15.1"
description = "gnuviechadmin web interface" description = "gnuviechadmin web interface"
authors = ["Jan Dittberner <jan@dittberner.info>"] authors = ["Jan Dittberner <jan@dittberner.info>"]
license = "AGPL-3+" license = "AGPL-3+"