mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-11 12:46:49 +00:00
feat(operations): the Logs page's rows and expired sessions are removed
Nothing removed the Logs page's rows, which every action and every failed login adds, or the database sessions past their expiry. The job worker's housekeeping now deletes the rows older than Log Retention Days, a new setting under Lists and pages (1-3650, 365 by default), and the expired sessions.
This commit is contained in:
parent
93b420ae81
commit
b2deb042e8
10 changed files with 243 additions and 173 deletions
30
appsettings/migrations/0024_log_retention_setting.py
Normal file
30
appsettings/migrations/0024_log_retention_setting.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
from django.core.management.color import no_style
|
||||
from django.db import migrations
|
||||
from django.utils.translation import gettext_noop as _
|
||||
|
||||
|
||||
SETTING = (_("Log Retention Days"), "LOG_RETENTION_DAYS", "365", _("Days the Logs page keeps its rows (1-3650)"))
|
||||
|
||||
|
||||
def add_setting(apps, schema_editor):
|
||||
setting = apps.get_model("appsettings", "AppSettings")
|
||||
db_alias = schema_editor.connection.alias
|
||||
# see 0014: move a PostgreSQL id sequence past the fixed ids first
|
||||
with schema_editor.connection.cursor() as cursor:
|
||||
for sql in schema_editor.connection.ops.sequence_reset_sql(no_style(), [setting]):
|
||||
cursor.execute(sql)
|
||||
name, key, value, description = SETTING
|
||||
setting.objects.using(db_alias).get_or_create(
|
||||
key=key, defaults={"name": name, "value": value, "choices": "", "description": description}
|
||||
)
|
||||
|
||||
|
||||
def del_setting(apps, schema_editor):
|
||||
apps.get_model("appsettings", "AppSettings").objects.using(schema_editor.connection.alias).filter(
|
||||
key=SETTING[1]).delete()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [("appsettings", "0023_remove_bottom_bar")]
|
||||
|
||||
operations = [migrations.RunPython(add_setting, del_setting)]
|
||||
|
|
@ -55,7 +55,7 @@ class SnapshotFreeSpaceSettingsTestCase(TestCase):
|
|||
|
||||
class WorkerSettingsTestCase(TestCase):
|
||||
def test_the_rows_fit_their_columns(self):
|
||||
for key in ("WORKER_CONCURRENCY", "JOB_RETENTION_DAYS"):
|
||||
for key in ("WORKER_CONCURRENCY", "JOB_RETENTION_DAYS", "LOG_RETENTION_DAYS"):
|
||||
setting = AppSettings.objects.get(key=key)
|
||||
for field in ("name", "key", "value", "description"):
|
||||
limit = AppSettings._meta.get_field(field).max_length
|
||||
|
|
|
|||
|
|
@ -48,7 +48,8 @@ GROUPS = [
|
|||
(gettext_noop("Snapshots and jobs"), ["SNAPSHOT_FREE_SPACE_PERCENT", "SNAPSHOT_FREE_SPACE_MIN_GIB",
|
||||
"WORKER_CONCURRENCY", "JOB_RETENTION_DAYS"]),
|
||||
(gettext_noop("Login"), ["LOGIN_FAILURE_LIMIT", "LOGIN_LOCKOUT_MINUTES"]),
|
||||
(gettext_noop("Lists and pages"), ["VIEW_INSTANCES_LIST_STYLE", "VM_DRBD_STATUS", "LOGS_PER_PAGE"]),
|
||||
(gettext_noop("Lists and pages"), ["VIEW_INSTANCES_LIST_STYLE", "VM_DRBD_STATUS", "LOGS_PER_PAGE",
|
||||
"LOG_RETENTION_DAYS"]),
|
||||
]
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue