fix: fixed failed to update information when name duplicate (#1773)

* fix: fixed failed to update information when name duplicate

* fix: Use GetOwnerAndNameFromId and GetId functions instead of split

* Update organization.go

* Update role.go

---------

Co-authored-by: hsluoyz <hsluoyz@qq.com>
This commit is contained in:
OutOfEastGate
2023-04-22 21:15:06 +08:00
committed by GitHub
parent a6c7b95f97
commit 916a55b633
3 changed files with 28 additions and 38 deletions

View File

@ -16,7 +16,6 @@ package object
import (
"fmt"
"strings"
"github.com/casdoor/casdoor/cred"
"github.com/casdoor/casdoor/i18n"
@ -299,18 +298,16 @@ func organizationChangeTrigger(oldName string, newName string) error {
}
for i, u := range role.Users {
// u = organization/username
split := strings.Split(u, "/")
if split[0] == oldName {
split[0] = newName
role.Users[i] = split[0] + "/" + split[1]
owner, name := util.GetOwnerAndNameFromId(u)
if name == oldName {
role.Users[i] = util.GetId(owner, newName)
}
}
for i, u := range role.Roles {
// u = organization/username
split := strings.Split(u, "/")
if split[0] == oldName {
split[0] = newName
role.Roles[i] = split[0] + "/" + split[1]
owner, name := util.GetOwnerAndNameFromId(u)
if name == oldName {
role.Roles[i] = util.GetId(owner, newName)
}
}
role.Owner = newName
@ -326,18 +323,16 @@ func organizationChangeTrigger(oldName string, newName string) error {
}
for i, u := range permission.Users {
// u = organization/username
split := strings.Split(u, "/")
if split[0] == oldName {
split[0] = newName
permission.Users[i] = split[0] + "/" + split[1]
owner, name := util.GetOwnerAndNameFromId(u)
if name == oldName {
permission.Users[i] = util.GetId(owner, newName)
}
}
for i, u := range permission.Roles {
// u = organization/username
split := strings.Split(u, "/")
if split[0] == oldName {
split[0] = newName
permission.Roles[i] = split[0] + "/" + split[1]
owner, name := util.GetOwnerAndNameFromId(u)
if name == oldName {
permission.Roles[i] = util.GetId(owner, newName)
}
}
permission.Owner = newName