mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-22 18:25:47 +08:00
fix: fix GetResources() bug for app users
This commit is contained in:
parent
3527e070a0
commit
0d5f49e40a
@ -52,12 +52,12 @@ func (c *ApiController) GetResources() {
|
|||||||
sortField := c.Input().Get("sortField")
|
sortField := c.Input().Get("sortField")
|
||||||
sortOrder := c.Input().Get("sortOrder")
|
sortOrder := c.Input().Get("sortOrder")
|
||||||
|
|
||||||
userObj, ok := c.RequireSignedInUser()
|
isOrgAdmin, ok := c.IsOrgAdmin()
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if userObj != nil && userObj.IsAdmin {
|
if isOrgAdmin {
|
||||||
user = ""
|
user = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,12 +108,12 @@ func (c *ApiController) RequireSignedInUser() (*object.User, bool) {
|
|||||||
c.ResponseError(err.Error())
|
c.ResponseError(err.Error())
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
if user == nil {
|
if user == nil {
|
||||||
c.ClearUserSession()
|
c.ClearUserSession()
|
||||||
c.ResponseError(fmt.Sprintf(c.T("general:The user: %s doesn't exist"), userId))
|
c.ResponseError(fmt.Sprintf(c.T("general:The user: %s doesn't exist"), userId))
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
return user, true
|
return user, true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,6 +130,30 @@ func (c *ApiController) RequireAdmin() (string, bool) {
|
|||||||
return user.Owner, true
|
return user.Owner, true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *ApiController) IsOrgAdmin() (bool, bool) {
|
||||||
|
userId, ok := c.RequireSignedIn()
|
||||||
|
if !ok {
|
||||||
|
return false, true
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(userId, "app/") {
|
||||||
|
return true, true
|
||||||
|
}
|
||||||
|
|
||||||
|
user, err := object.GetUser(userId)
|
||||||
|
if err != nil {
|
||||||
|
c.ResponseError(err.Error())
|
||||||
|
return false, false
|
||||||
|
}
|
||||||
|
if user == nil {
|
||||||
|
c.ClearUserSession()
|
||||||
|
c.ResponseError(fmt.Sprintf(c.T("general:The user: %s doesn't exist"), userId))
|
||||||
|
return false, false
|
||||||
|
}
|
||||||
|
|
||||||
|
return user.IsAdmin, true
|
||||||
|
}
|
||||||
|
|
||||||
// IsMaskedEnabled ...
|
// IsMaskedEnabled ...
|
||||||
func (c *ApiController) IsMaskedEnabled() (bool, bool) {
|
func (c *ApiController) IsMaskedEnabled() (bool, bool) {
|
||||||
isMaskEnabled := true
|
isMaskEnabled := true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user