mirror of
https://github.com/StarFleetCPTN/GoMFT.git
synced 2026-09-08 15:41:20 +02:00
- Upgraded `golang.org/x/crypto` to v0.36.0 and other indirect dependencies to their latest versions. - Added functionality to assign admin roles to users upon creation in the main application logic. - Introduced new templates for admin role management, including forms for creating and editing roles. - Removed deprecated admin tools template to streamline the admin interface. - Added audit logging for role changes to improve tracking and accountability.
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package db
|
|
|
|
import (
|
|
"database/sql/driver"
|
|
"encoding/json"
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// AuditLog represents an audit trail entry in the system
|
|
type AuditLog struct {
|
|
gorm.Model
|
|
Action string `gorm:"size:50;not null;index"`
|
|
EntityType string `gorm:"size:50;not null;index"`
|
|
EntityID uint `gorm:"not null;index"`
|
|
UserID uint `gorm:"not null;index"`
|
|
Details AuditLogDetails `gorm:"type:json"`
|
|
Timestamp time.Time `gorm:"not null;index;default:CURRENT_TIMESTAMP"`
|
|
}
|
|
|
|
// AuditLogDetails is a custom type for storing audit log details as JSON
|
|
type AuditLogDetails map[string]interface{}
|
|
|
|
// Scan implements the sql.Scanner interface
|
|
func (d *AuditLogDetails) Scan(value interface{}) error {
|
|
if value == nil {
|
|
*d = make(AuditLogDetails)
|
|
return nil
|
|
}
|
|
|
|
bytes, ok := value.([]byte)
|
|
if !ok {
|
|
return nil
|
|
}
|
|
|
|
return json.Unmarshal(bytes, d)
|
|
}
|
|
|
|
// Value implements the driver.Valuer interface
|
|
func (d AuditLogDetails) Value() (driver.Value, error) {
|
|
if d == nil {
|
|
return json.Marshal(make(map[string]interface{}))
|
|
}
|
|
return json.Marshal(d)
|
|
}
|