Skip to content
Snippets Groups Projects
Commit b7f66df1 authored by Cornel Rautenbach's avatar Cornel Rautenbach
Browse files

Audit - GetChanges method

parent 58ab9602
No related branches found
No related tags found
No related merge requests found
...@@ -26,13 +26,13 @@ type FieldChange struct { ...@@ -26,13 +26,13 @@ type FieldChange struct {
To interface{} `json:"change_to"` To interface{} `json:"change_to"`
} }
func GetAuditEvent(original interface{}, new interface{}, username *string) (Event, error) { func GetChanges(original interface{}, new interface{}) (map[string]interface{}, error) {
changes := map[string]interface{}{}
changelog, err := diff.Diff(original, new) changelog, err := diff.Diff(original, new)
if err != nil { if err != nil {
return Event{}, err return changes, err
} }
changes := map[string]interface{}{}
for _, change := range changelog { for _, change := range changelog {
if len(change.Path) == 1 { if len(change.Path) == 1 {
...@@ -119,38 +119,7 @@ func GetAuditEvent(original interface{}, new interface{}, username *string) (Eve ...@@ -119,38 +119,7 @@ func GetAuditEvent(original interface{}, new interface{}, username *string) (Eve
} }
} }
objectID := getIntValue(original, "ID") return changes, nil
if objectID == 0 {
objectID = getIntValue(new, "ID")
}
objectIDString := string_utils.Int64ToString(objectID)
if objectIDString == "0" {
objectIDString = getStringValue(original, "Username")
}
if objectIDString == "" {
objectIDString = getStringValue(new, "Username")
}
providerID := getIntValue(original, "ProviderID")
if providerID == 0 {
providerID = getIntValue(new, "ProviderID")
}
auditEvent := Event{
ObjectID: objectIDString,
ProviderID: providerID,
Source: "SYSTEM",
Timestamp: time.Now(),
Change: changes,
}
if username != nil {
auditEvent.Source = *username
}
return auditEvent, nil
} }
var matchFirstCap = regexp.MustCompile("(.)([A-Z][a-z]+)") var matchFirstCap = regexp.MustCompile("(.)([A-Z][a-z]+)")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment