B: Adjust audit trail

This commit is contained in:
Preston Baxter 2023-11-16 19:21:40 -06:00
parent 5ea803b67f
commit 1ecc00a86e
1 changed files with 36 additions and 3 deletions

View File

@ -6,13 +6,17 @@ import (
"go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/bson/primitive"
) )
const EVENT_RECIEVED_TYPE = "audit_event_recieved" const (
EVENT_RECIEVED_TYPE = "audit_event_recieved"
ACTION_TAKEN_TYPE = "audit_action_taken"
)
// Event Recieved
type EventRecieved struct { type EventRecieved struct {
*CommonFields `bson:"obj_info"` *CommonFields `bson:"obj_info"`
Id primitive.ObjectID `bson:"_id,omitempty"` Id primitive.ObjectID `bson:"_id,omitempty"`
UserId primitive.ObjectID `bson:"user_id,omitempty"` UserId primitive.ObjectID `bson:"user_id,omitempty"` //what user is this associated too
Source primitive.ObjectID `bson:"source_id,omitempty"` VendorName string `bson:"vendor_name,omitempty"` //Vendor name of who sent us the event
} }
func (obj *EventRecieved) MongoId() primitive.ObjectID { func (obj *EventRecieved) MongoId() primitive.ObjectID {
@ -33,3 +37,32 @@ func (obj *EventRecieved) UpdateObjectInfo() {
} }
obj.UpdatedAt = now obj.UpdatedAt = now
} }
// Action Taken
type ActionTaken struct {
*CommonFields `bson:"obj_info"`
Id primitive.ObjectID `bson:"_id,omitempty"`
UserId primitive.ObjectID `bson:"user_id,omitempty"` //what user is this associated too
TriggeringEvent primitive.ObjectID `bson:"triggering_event,omitempty"` //what triggered this action to be taken
Result []primitive.ObjectID `bson:"result,omitempty"` //list of entities effected or created from action
VendorName string `bson:"vendor_name,omitempty"` //Vendor name that the action was taken against
}
func (obj *ActionTaken) MongoId() primitive.ObjectID {
if obj.Id.IsZero() {
now := time.Now()
obj.Id = primitive.NewObjectIDFromTimestamp(now)
}
return obj.Id
}
func (obj *ActionTaken) UpdateObjectInfo() {
now := time.Now()
if obj.CommonFields == nil {
obj.CommonFields = new(CommonFields)
obj.EntityType = EVENT_RECIEVED_TYPE
obj.CreatedAt = now
}
obj.UpdatedAt = now
}