feat: fix checkPermissionForUpdateUser() logic (#1454)

* fix: fix `checkPermissionForUpdateUser()` logic

* fix: fix `checkPermissionForUpdateUser()` logic
This commit is contained in:
imp2002 2023-01-06 00:03:40 +08:00 committed by GitHub
parent dcf148fb7f
commit 4ab2ca7a25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,7 +17,6 @@ package controllers
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"reflect"
"strings" "strings"
"github.com/beego/beego/utils/pagination" "github.com/beego/beego/utils/pagination"
@ -200,18 +199,28 @@ func checkPermissionForUpdateUser(id string, newUser object.User, c *ApiControll
item := object.GetAccountItemByName("Signup application", org) item := object.GetAccountItemByName("Signup application", org)
itemsChanged = append(itemsChanged, item) itemsChanged = append(itemsChanged, item)
} }
if reflect.DeepEqual(oldUser.Roles, newUser.Roles) {
oldUserRolesJson, _ := json.Marshal(oldUser.Roles)
newUserRolesJson, _ := json.Marshal(newUser.Roles)
if string(oldUserRolesJson) != string(newUserRolesJson) {
item := object.GetAccountItemByName("Roles", org) item := object.GetAccountItemByName("Roles", org)
itemsChanged = append(itemsChanged, item) itemsChanged = append(itemsChanged, item)
} }
if reflect.DeepEqual(oldUser.Permissions, newUser.Permissions) {
oldUserPermissionJson, _ := json.Marshal(oldUser.Permissions)
newUserPermissionJson, _ := json.Marshal(newUser.Permissions)
if string(oldUserPermissionJson) != string(newUserPermissionJson) {
item := object.GetAccountItemByName("Permissions", org) item := object.GetAccountItemByName("Permissions", org)
itemsChanged = append(itemsChanged, item) itemsChanged = append(itemsChanged, item)
} }
if reflect.DeepEqual(oldUser.Properties, newUser.Properties) {
oldUserPropertiesJson, _ := json.Marshal(oldUser.Properties)
newUserPropertiesJson, _ := json.Marshal(newUser.Properties)
if string(oldUserPropertiesJson) != string(newUserPropertiesJson) {
item := object.GetAccountItemByName("Properties", org) item := object.GetAccountItemByName("Properties", org)
itemsChanged = append(itemsChanged, item) itemsChanged = append(itemsChanged, item)
} }
if oldUser.IsAdmin != newUser.IsAdmin { if oldUser.IsAdmin != newUser.IsAdmin {
item := object.GetAccountItemByName("Is admin", org) item := object.GetAccountItemByName("Is admin", org)
itemsChanged = append(itemsChanged, item) itemsChanged = append(itemsChanged, item)