move audit reference info from a database table to an embedded YAML file
This commit is contained in:
+42
-1
@@ -11,13 +11,53 @@ package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.erbosoft.com/amy/amsterdam/config"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
// AuditRefRecord stores the reference data for an audit message.
|
||||
type AuditRefRecord struct {
|
||||
Code int `yaml:"code"`
|
||||
Text string `yaml:"text"`
|
||||
}
|
||||
|
||||
// AuditReference stores the audit reference data.
|
||||
type AuditReference struct {
|
||||
Ref []AuditRefRecord `yaml:"auditReference"`
|
||||
table map[int]*AuditRefRecord
|
||||
}
|
||||
|
||||
//go:embed auditref.yaml
|
||||
var initAuditData []byte
|
||||
|
||||
// auditref is the master audit data reference.
|
||||
var auditRef AuditReference
|
||||
|
||||
// init loads the audit data.
|
||||
func init() {
|
||||
if err := yaml.Unmarshal(initAuditData, &auditRef); err != nil {
|
||||
panic(err) // can't happen
|
||||
}
|
||||
auditRef.table = make(map[int]*AuditRefRecord)
|
||||
for i := range auditRef.Ref {
|
||||
auditRef.table[auditRef.Ref[i].Code] = &(auditRef.Ref[i])
|
||||
}
|
||||
}
|
||||
|
||||
// AmAuditText gets the text of an audit from its code.
|
||||
func AmAuditText(code int) string {
|
||||
rec, ok := auditRef.table[code]
|
||||
if ok {
|
||||
return rec.Text
|
||||
}
|
||||
return fmt.Sprintf("[audit code:%d]", code)
|
||||
}
|
||||
|
||||
// AuditRecord holds an audit record instance.
|
||||
type AuditRecord struct {
|
||||
Record int64 `db:"record"` // audit record ID
|
||||
@@ -32,7 +72,8 @@ type AuditRecord struct {
|
||||
Data4 *string `db:"data4"` // fourth data parameter
|
||||
}
|
||||
|
||||
// These are the audit record types.
|
||||
// These are the audit record types. N.B.: Keep these synchronized with the definitions in database/auditref.yaml
|
||||
// at all times!
|
||||
const (
|
||||
AuditPublishToFrontPage = 1
|
||||
AuditLoginOK = 101
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
#
|
||||
# Amsterdam Web Communities System
|
||||
# Copyright (c) 2025-2026 Erbosoft Metaverse Design Solutions, All Rights Reserved
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# ----------------------------------------------------------------------------
|
||||
# N.B.: Keep this synchronized with the constant definitions in
|
||||
# database/audit.go at all times!
|
||||
auditReference:
|
||||
- code: 1
|
||||
text: "Publish Message to Front Page"
|
||||
- code: 101
|
||||
text: "Login OK"
|
||||
- code: 102
|
||||
text: "Login Failure"
|
||||
- code: 103
|
||||
text: "Account Created"
|
||||
- code: 104
|
||||
text: "Verify Email OK"
|
||||
- code: 105
|
||||
text: "Verify Email Failure"
|
||||
- code: 106
|
||||
text: "Set User Contact Info"
|
||||
- code: 107
|
||||
text: "Resend Email Confirmation"
|
||||
- code: 108
|
||||
text: "Password Change"
|
||||
- code: 109
|
||||
text: "Admin Set User Contact Info"
|
||||
- code: 110
|
||||
text: "Admin Change User Password"
|
||||
- code: 111
|
||||
text: "Admin Change User Account"
|
||||
- code: 112
|
||||
text: "Admin Set Account Security"
|
||||
- code: 113
|
||||
text: "Admin Lock/Unlock Account"
|
||||
- code: 201
|
||||
text: "Create New Community"
|
||||
- code: 202
|
||||
text: "Set Community Membership"
|
||||
- code: 203
|
||||
text: "Set Community Contact Info"
|
||||
- code: 204
|
||||
text: "Set Community Services"
|
||||
- code: 205
|
||||
text: "Set Community Name"
|
||||
- code: 206
|
||||
text: "Set Community Alias"
|
||||
- code: 207
|
||||
text: "Set Community Category"
|
||||
- code: 208
|
||||
text: "Set Community Hiding Information"
|
||||
- code: 209
|
||||
text: "Set Community Members-Only Flag"
|
||||
- code: 210
|
||||
text: "Set Community Join Key"
|
||||
- code: 211
|
||||
text: "Set Community Security Levels"
|
||||
- code: 212
|
||||
text: "Delete Community"
|
||||
- code: 301
|
||||
text: "Create New Conference"
|
||||
- code: 302
|
||||
text: "Set Conference Security Levels"
|
||||
- code: 303
|
||||
text: "Set Conference Name"
|
||||
- code: 304
|
||||
text: "Change Conference Aliases"
|
||||
- code: 305
|
||||
text: "Change Conference Membership"
|
||||
- code: 306
|
||||
text: "Create New Topic"
|
||||
- code: 307
|
||||
text: "Delete Topic"
|
||||
- code: 308
|
||||
text: "Set Topic Frozen"
|
||||
- code: 309
|
||||
text: "Set Topic Archive"
|
||||
- code: 310
|
||||
text: "Post Message"
|
||||
- code: 311
|
||||
text: "Hide Message"
|
||||
- code: 312
|
||||
text: "Scribble Message"
|
||||
- code: 313
|
||||
text: "Nuke Message"
|
||||
- code: 314
|
||||
text: "Upload Message Attachment"
|
||||
- code: 315
|
||||
text: "Delete Conference"
|
||||
- code: 316
|
||||
text: "Move Message"
|
||||
- code: 317
|
||||
text: "Set Topic Sticky"
|
||||
- code: 318
|
||||
text: "Prune Message Attachment"
|
||||
Reference in New Issue
Block a user