Add audit logging to type editors

This commit is contained in:
rubenwardy 2023-05-12 01:03:21 +01:00
parent f03746f5ad
commit e88ead392b
3 changed files with 26 additions and 5 deletions

@ -16,13 +16,14 @@
from flask import redirect, render_template, abort, url_for, request, flash
from flask_login import current_user
from flask_wtf import FlaskForm
from wtforms import StringField, BooleanField, SubmitField, URLField
from wtforms.validators import InputRequired, Length, Optional
from app.utils import rank_required, nonEmptyOrNone
from app.utils import rank_required, nonEmptyOrNone, addAuditLog
from . import bp
from ...models import UserRank, License, db
from ...models import UserRank, License, db, AuditSeverity
@bp.route("/licenses/")
@ -56,9 +57,15 @@ def create_edit_license(name=None):
license = License(form.name.data)
db.session.add(license)
flash("Created license " + form.name.data, "success")
addAuditLog(AuditSeverity.MODERATION, current_user, f"Created license {license.name}",
url_for("admin.license_list"))
else:
flash("Updated license " + form.name.data, "success")
addAuditLog(AuditSeverity.MODERATION, current_user, f"Edited license {license.name}",
url_for("admin.license_list"))
form.populate_obj(license)
db.session.commit()
return redirect(url_for("admin.license_list"))

@ -22,7 +22,8 @@ from wtforms import StringField, TextAreaField, BooleanField, SubmitField
from wtforms.validators import InputRequired, Length, Optional, Regexp
from . import bp
from ...models import Permission, Tag, db
from ...models import Permission, Tag, db, AuditSeverity
from ...utils import addAuditLog
@bp.route("/tags/")
@ -69,9 +70,15 @@ def create_edit_tag(name=None):
tag.description = form.description.data
tag.is_protected = form.is_protected.data
db.session.add(tag)
addAuditLog(AuditSeverity.EDITOR, current_user, f"Created tag {tag.name}",
url_for("admin.create_edit_tag", name=tag.name))
else:
form.populate_obj(tag)
addAuditLog(AuditSeverity.EDITOR, current_user, f"Edited tag {tag.name}",
url_for("admin.create_edit_tag", name=tag.name))
db.session.commit()
if Permission.EDIT_TAGS.check(current_user):

@ -16,13 +16,14 @@
from flask import redirect, render_template, abort, url_for, request, flash
from flask_login import current_user
from flask_wtf import FlaskForm
from wtforms import StringField, IntegerField, SubmitField
from wtforms.validators import InputRequired, Length
from app.utils import rank_required
from app.utils import rank_required, addAuditLog
from . import bp
from ...models import UserRank, MinetestRelease, db
from ...models import UserRank, MinetestRelease, db, AuditSeverity
@bp.route("/versions/")
@ -53,9 +54,15 @@ def create_edit_version(name=None):
version = MinetestRelease(form.name.data)
db.session.add(version)
flash("Created version " + form.name.data, "success")
addAuditLog(AuditSeverity.MODERATION, current_user, f"Created version {version.name}",
url_for("admin.license_list"))
else:
flash("Updated version " + form.name.data, "success")
addAuditLog(AuditSeverity.MODERATION, current_user, f"Edited version {version.name}",
url_for("admin.version_list"))
form.populate_obj(version)
db.session.commit()
return redirect(url_for("admin.version_list"))