Files
StarFleetCPTN 49a586db53 feat: Update dependencies and enhance admin role management
- 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.
2025-03-22 16:55:36 -07:00

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)
}