diff --git a/controllers/user.go b/controllers/user.go index a9e45fc9..a31b62e0 100644 --- a/controllers/user.go +++ b/controllers/user.go @@ -100,7 +100,7 @@ func (c *ApiController) GetUser() { organization := object.GetOrganization(fmt.Sprintf("%s/%s", "admin", owner)) if !organization.IsProfilePublic { requestUserId := c.GetSessionUsername() - hasPermission, err := object.CheckUserPermission(requestUserId, id, false) + hasPermission, err := object.CheckUserPermission(requestUserId, id, owner, false) if !hasPermission { c.ResponseError(err.Error()) return @@ -264,7 +264,7 @@ func (c *ApiController) SetPassword() { requestUserId := c.GetSessionUsername() userId := fmt.Sprintf("%s/%s", userOwner, userName) - hasPermission, err := object.CheckUserPermission(requestUserId, userId, true) + hasPermission, err := object.CheckUserPermission(requestUserId, userId, userOwner, true) if !hasPermission { c.ResponseError(err.Error()) return diff --git a/object/check.go b/object/check.go index ad0be2af..f1694e3c 100644 --- a/object/check.go +++ b/object/check.go @@ -197,14 +197,18 @@ func filterField(field string) bool { return reFieldWhiteList.MatchString(field) } -func CheckUserPermission(requestUserId, userId string, strict bool) (bool, error) { +func CheckUserPermission(requestUserId, userId, userOwner string, strict bool) (bool, error) { if requestUserId == "" { return false, fmt.Errorf("please login first") } - targetUser := GetUser(userId) - if targetUser == nil { - return false, fmt.Errorf("the user: %s doesn't exist", userId) + if userId != "" { + targetUser := GetUser(userId) + if targetUser == nil { + return false, fmt.Errorf("the user: %s doesn't exist", userId) + } + + userOwner = targetUser.Owner } hasPermission := false @@ -219,7 +223,7 @@ func CheckUserPermission(requestUserId, userId string, strict bool) (bool, error hasPermission = true } else if requestUserId == userId { hasPermission = true - } else if targetUser.Owner == requestUser.Owner { + } else if userOwner == requestUser.Owner { if strict { hasPermission = requestUser.IsAdmin } else {