Files
gochat/internal/model/audit.go
T
2026-06-04 15:44:48 +08:00

32 lines
1.8 KiB
Go

package model
import (
"encoding/json"
"time"
)
// Audit represents an audit log entry for enterprise compliance.
// Reference: Chatwoot enterprise Audit model + P2B M11 spec
type Audit struct {
ID uint `gorm:"primaryKey" json:"id"`
AccountID *uint `gorm:"index" json:"account_id,omitempty"`
UserID *uint `gorm:"index" json:"user_id,omitempty"`
AuditableType string `gorm:"size:100;not null;index" json:"auditable_type"` // Conversation/Message/Contact/User/Inbox/Account
AuditableID uint `gorm:"not null;index" json:"auditable_id"`
Action string `gorm:"size:100;not null;index" json:"action"` // create/update/delete/assign/unassign/...
AuditedChanges json.RawMessage `gorm:"type:jsonb;column:audited_changes" json:"audited_changes"`
AssociatedType string `gorm:"size:100" json:"associated_type,omitempty"` // typically Account
AssociatedID *uint `gorm:"index" json:"associated_id,omitempty"`
Username string `gorm:"size:255" json:"username,omitempty"` // operator email, auto-filled
RemoteAddress string `gorm:"size:50" json:"remote_address,omitempty"` // IP address
RequestUUID string `gorm:"size:50" json:"request_uuid,omitempty"` // request unique identifier
Version *int `json:"version,omitempty"`
Comment string `gorm:"size:500" json:"comment,omitempty"`
UserType string `gorm:"size:50" json:"user_type,omitempty"`
CreatedAt time.Time `gorm:"autoCreateTime;index" json:"created_at"`
Account *Account `gorm:"foreignKey:AccountID" json:"account,omitempty"`
User *User `gorm:"foreignKey:UserID" json:"user,omitempty"`
}
func (Audit) TableName() string { return "audits" }