Skip to content

Commit

Permalink
Merge branch 'dedupe'
Browse files Browse the repository at this point in the history
  • Loading branch information
cwarden committed Mar 25, 2024
2 parents 185541e + 2cdfa53 commit a74c287
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions permissionset/tidy.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package permissionset

import (
"fmt"
"sort"
)

Expand Down Expand Up @@ -71,10 +72,25 @@ func (cp CustomSettingList) Tidy() {
})
}

func (fp FieldPermissionsList) Tidy() {
sort.Slice(fp, func(i, j int) bool {
return fp[i].Field < fp[j].Field
func (fp *FieldPermissionsList) Tidy() {
if len(*fp) == 0 {
return
}
sort.Slice(*fp, func(i, j int) bool {
return (*fp)[i].Field < (*fp)[j].Field
})
lastUniqueIndex := 0
for i := 1; i < len(*fp); i++ {
// If the current element is not a duplicate, move it to the next position after the last unique element
if (*fp)[i].Field != (*fp)[lastUniqueIndex].Field {
lastUniqueIndex++
(*fp)[lastUniqueIndex] = (*fp)[i]
} else {
fmt.Println("omitting duplicate permissions for", (*fp)[i].Field)
}
}
// Slice the original slice to the correct length of unique elements
*fp = (*fp)[:lastUniqueIndex+1]
}

func (up UserPermissionList) Tidy() {
Expand Down

0 comments on commit a74c287

Please sign in to comment.