mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-03 12:30:19 +08:00
fix: unable to get user if profile is private (#936)
This commit is contained in:
@ -100,7 +100,7 @@ func (c *ApiController) GetUser() {
|
|||||||
organization := object.GetOrganization(fmt.Sprintf("%s/%s", "admin", owner))
|
organization := object.GetOrganization(fmt.Sprintf("%s/%s", "admin", owner))
|
||||||
if !organization.IsProfilePublic {
|
if !organization.IsProfilePublic {
|
||||||
requestUserId := c.GetSessionUsername()
|
requestUserId := c.GetSessionUsername()
|
||||||
hasPermission, err := object.CheckUserPermission(requestUserId, id, false)
|
hasPermission, err := object.CheckUserPermission(requestUserId, id, owner, false)
|
||||||
if !hasPermission {
|
if !hasPermission {
|
||||||
c.ResponseError(err.Error())
|
c.ResponseError(err.Error())
|
||||||
return
|
return
|
||||||
@ -264,7 +264,7 @@ func (c *ApiController) SetPassword() {
|
|||||||
requestUserId := c.GetSessionUsername()
|
requestUserId := c.GetSessionUsername()
|
||||||
userId := fmt.Sprintf("%s/%s", userOwner, userName)
|
userId := fmt.Sprintf("%s/%s", userOwner, userName)
|
||||||
|
|
||||||
hasPermission, err := object.CheckUserPermission(requestUserId, userId, true)
|
hasPermission, err := object.CheckUserPermission(requestUserId, userId, userOwner, true)
|
||||||
if !hasPermission {
|
if !hasPermission {
|
||||||
c.ResponseError(err.Error())
|
c.ResponseError(err.Error())
|
||||||
return
|
return
|
||||||
|
@ -197,16 +197,20 @@ func filterField(field string) bool {
|
|||||||
return reFieldWhiteList.MatchString(field)
|
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 == "" {
|
if requestUserId == "" {
|
||||||
return false, fmt.Errorf("please login first")
|
return false, fmt.Errorf("please login first")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if userId != "" {
|
||||||
targetUser := GetUser(userId)
|
targetUser := GetUser(userId)
|
||||||
if targetUser == nil {
|
if targetUser == nil {
|
||||||
return false, fmt.Errorf("the user: %s doesn't exist", userId)
|
return false, fmt.Errorf("the user: %s doesn't exist", userId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
userOwner = targetUser.Owner
|
||||||
|
}
|
||||||
|
|
||||||
hasPermission := false
|
hasPermission := false
|
||||||
if strings.HasPrefix(requestUserId, "app/") {
|
if strings.HasPrefix(requestUserId, "app/") {
|
||||||
hasPermission = true
|
hasPermission = true
|
||||||
@ -219,7 +223,7 @@ func CheckUserPermission(requestUserId, userId string, strict bool) (bool, error
|
|||||||
hasPermission = true
|
hasPermission = true
|
||||||
} else if requestUserId == userId {
|
} else if requestUserId == userId {
|
||||||
hasPermission = true
|
hasPermission = true
|
||||||
} else if targetUser.Owner == requestUser.Owner {
|
} else if userOwner == requestUser.Owner {
|
||||||
if strict {
|
if strict {
|
||||||
hasPermission = requestUser.IsAdmin
|
hasPermission = requestUser.IsAdmin
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user