summaryrefslogtreecommitdiffstats
path: root/model/role.go
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2018-02-08 16:07:40 +0000
committerJesús Espino <jespinog@gmail.com>2018-02-08 17:07:40 +0100
commitfa5cba9cc79b3bdc48ad42f276652bc699795a39 (patch)
tree39549319db989cd3429d82ab41766e1b73c7dcb3 /model/role.go
parenta735725d116c3e8dca2b4d1cad3425bcd473311c (diff)
downloadchat-fa5cba9cc79b3bdc48ad42f276652bc699795a39.tar.gz
chat-fa5cba9cc79b3bdc48ad42f276652bc699795a39.tar.bz2
chat-fa5cba9cc79b3bdc48ad42f276652bc699795a39.zip
XYZ-76: Add license check to patchRoles endpoint. (#8224)
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