diff options
author | George Goldberg <george@gberg.me> | 2018-02-08 16:07:40 +0000 |
---|---|---|
committer | Jesús Espino <jespinog@gmail.com> | 2018-02-08 17:07:40 +0100 |
commit | fa5cba9cc79b3bdc48ad42f276652bc699795a39 (patch) | |
tree | 39549319db989cd3429d82ab41766e1b73c7dcb3 /model | |
parent | a735725d116c3e8dca2b4d1cad3425bcd473311c (diff) | |
download | chat-fa5cba9cc79b3bdc48ad42f276652bc699795a39.tar.gz chat-fa5cba9cc79b3bdc48ad42f276652bc699795a39.tar.bz2 chat-fa5cba9cc79b3bdc48ad42f276652bc699795a39.zip |
XYZ-76: Add license check to patchRoles endpoint. (#8224)
Diffstat (limited to 'model')
-rw-r--r-- | model/role.go | 35 |
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 |