Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bobgroup-go-utils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bob Public Utils
bobgroup-go-utils
Commits
eec1a136
Commit
eec1a136
authored
2 years ago
by
Jano Hendriks
Browse files
Options
Downloads
Patches
Plain Diff
Fixed bug with audit events for arrays and added object index to array events
parent
e36510e4
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
audit/audit.go
+19
-2
19 additions, 2 deletions
audit/audit.go
with
19 additions
and
2 deletions
audit/audit.go
+
19
−
2
View file @
eec1a136
...
@@ -63,9 +63,10 @@ func GetChanges(original interface{}, new interface{}) (map[string]interface{},
...
@@ -63,9 +63,10 @@ func GetChanges(original interface{}, new interface{}) (map[string]interface{},
arrayObject
,
present
:=
changes
[
objectKey
]
arrayObject
,
present
:=
changes
[
objectKey
]
if
present
{
if
present
{
if
arrayOfObjects
,
ok
:=
arrayObject
.
([]
map
[
string
]
interface
{});
ok
{
if
arrayOfObjects
,
ok
:=
arrayObject
.
([]
map
[
string
]
interface
{});
ok
{
if
len
(
arrayOfObjects
)
>
int
(
index
)
{
arrayIndex
:=
ArrayIndexForObjectIndex
(
arrayOfObjects
,
index
)
if
arrayIndex
!=
-
1
{
// Add field to existing object in array
// Add field to existing object in array
object
:=
arrayOfObjects
[
i
ndex
]
object
:=
arrayOfObjects
[
arrayI
ndex
]
object
[
field
]
=
FieldChange
{
object
[
field
]
=
FieldChange
{
From
:
change
.
From
,
From
:
change
.
From
,
To
:
change
.
To
,
To
:
change
.
To
,
...
@@ -73,6 +74,7 @@ func GetChanges(original interface{}, new interface{}) (map[string]interface{},
...
@@ -73,6 +74,7 @@ func GetChanges(original interface{}, new interface{}) (map[string]interface{},
}
else
{
}
else
{
// new object, append to existing array
// new object, append to existing array
fieldChange
:=
map
[
string
]
interface
{}{
fieldChange
:=
map
[
string
]
interface
{}{
"index"
:
index
,
field
:
FieldChange
{
field
:
FieldChange
{
From
:
change
.
From
,
From
:
change
.
From
,
To
:
change
.
To
,
To
:
change
.
To
,
...
@@ -85,6 +87,7 @@ func GetChanges(original interface{}, new interface{}) (map[string]interface{},
...
@@ -85,6 +87,7 @@ func GetChanges(original interface{}, new interface{}) (map[string]interface{},
}
else
{
}
else
{
// Create array of objects
// Create array of objects
fieldChange
:=
map
[
string
]
interface
{}{
fieldChange
:=
map
[
string
]
interface
{}{
"index"
:
index
,
field
:
FieldChange
{
field
:
FieldChange
{
From
:
change
.
From
,
From
:
change
.
From
,
To
:
change
.
To
,
To
:
change
.
To
,
...
@@ -124,6 +127,20 @@ func ChildObjectChanges(changes map[string]interface{}, objectPath string, field
...
@@ -124,6 +127,20 @@ func ChildObjectChanges(changes map[string]interface{}, objectPath string, field
}
}
}
}
// ArrayIndexForObjectIndex gets the index of arrayOfObjects where the object's index field is equal to objectIndex.
func
ArrayIndexForObjectIndex
(
arrayOfObjects
[]
map
[
string
]
interface
{},
objectIndex
int64
)
int
{
for
arrayIndex
,
object
:=
range
arrayOfObjects
{
index
,
present
:=
object
[
"index"
]
if
present
{
if
index
==
objectIndex
{
return
arrayIndex
}
}
}
return
-
1
}
// GetAllChanges Returns the diff, structured in json, recursively
// GetAllChanges Returns the diff, structured in json, recursively
// Be warned, here be dragons. Debug this first to understand how it works
// Be warned, here be dragons. Debug this first to understand how it works
func
GetAllChanges
(
original
interface
{},
new
interface
{})
(
map
[
string
]
interface
{},
error
)
{
func
GetAllChanges
(
original
interface
{},
new
interface
{})
(
map
[
string
]
interface
{},
error
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment