summaryrefslogtreecommitdiffstats
path: root/model/role.go
diff options
context:
space:
mode:
Diffstat (limited to 'model/role.go')
-rw-r--r--model/role.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/model/role.go b/model/role.go
index 254513ae0..eedf97d25 100644
--- a/model/role.go
+++ b/model/role.go
@@ -81,6 +81,41 @@ func (o *Role) Patch(patch *RolePatch) {
}
}
+// Returns an array of permissions that are in either role.Permissions
+// or patch.Permissions, but not both.
+func PermissionsChangedByPatch(role *Role, patch *RolePatch) []string {
+ var result []string
+
+ if patch.Permissions == nil {
+ return result
+ }
+
+ roleMap := make(map[string]bool)
+ patchMap := make(map[string]bool)
+
+ for _, permission := range role.Permissions {
+ roleMap[permission] = true
+ }
+
+ for _, permission := range *patch.Permissions {
+ patchMap[permission] = true
+ }
+
+ for _, permission := range role.Permissions {
+ if !patchMap[permission] {
+ result = append(result, permission)
+ }
+ }
+
+ for _, permission := range *patch.Permissions {
+ if !roleMap[permission] {
+ result = append(result, permission)
+ }
+ }
+
+ return result
+}
+
func (role *Role) IsValid() bool {
if len(role.Id) != 26 {
return false