Add object.IsAppUser()

This commit is contained in:
Yang Luo 2024-04-24 01:10:38 +08:00
parent 90d502ab2b
commit af2d26daf2
7 changed files with 15 additions and 8 deletions

View File

@ -73,7 +73,7 @@ func (c *ApiController) IsAdminOrSelf(user2 *object.User) bool {
func (c *ApiController) isGlobalAdmin() (bool, *object.User) { func (c *ApiController) isGlobalAdmin() (bool, *object.User) {
username := c.GetSessionUsername() username := c.GetSessionUsername()
if strings.HasPrefix(username, "app/") { if object.IsAppUser(username) {
// e.g., "app/app-casnode" // e.g., "app/app-casnode"
return true, nil return true, nil
} }

View File

@ -120,7 +120,7 @@ func (c *ApiController) SendEmail() {
// "You have requested a verification code at Casdoor. Here is your code: %s, please enter in 5 minutes." // "You have requested a verification code at Casdoor. Here is your code: %s, please enter in 5 minutes."
content = strings.Replace(content, "%s", code, 1) content = strings.Replace(content, "%s", code, 1)
userString := "Hi" userString := "Hi"
if !strings.HasPrefix(userId, "app/") { if !object.IsAppUser(userId) {
var user *object.User var user *object.User
user, err = object.GetUser(userId) user, err = object.GetUser(userId)
if err != nil { if err != nil {

View File

@ -96,7 +96,7 @@ func (c *ApiController) RequireSignedInUser() (*object.User, bool) {
return nil, false return nil, false
} }
if strings.HasPrefix(userId, "app/") { if object.IsAppUser(userId) {
tmpUserId := c.Input().Get("userId") tmpUserId := c.Input().Get("userId")
if tmpUserId != "" { if tmpUserId != "" {
userId = tmpUserId userId = tmpUserId
@ -142,7 +142,7 @@ func (c *ApiController) IsOrgAdmin() (bool, bool) {
return false, true return false, true
} }
if strings.HasPrefix(userId, "app/") { if object.IsAppUser(userId) {
return true, true return true, true
} }

View File

@ -405,8 +405,8 @@ func GetApplicationByUser(user *User) (*Application, error) {
} }
func GetApplicationByUserId(userId string) (application *Application, err error) { func GetApplicationByUserId(userId string) (application *Application, err error) {
owner, name := util.GetOwnerAndNameFromId(userId) _, name := util.GetOwnerAndNameFromId(userId)
if owner == "app" { if IsAppUser(userId) {
application, err = getApplication("admin", name) application, err = getApplication("admin", name)
return return
} }

View File

@ -410,7 +410,7 @@ func CheckUserPermission(requestUserId, userId string, strict bool, lang string)
} }
hasPermission := false hasPermission := false
if strings.HasPrefix(requestUserId, "app/") { if IsAppUser(requestUserId) {
hasPermission = true hasPermission = true
} else { } else {
requestUser, err := GetUser(requestUserId) requestUser, err := GetUser(requestUserId)

View File

@ -1003,7 +1003,7 @@ func (user *User) GetFriendlyName() string {
} }
func isUserIdGlobalAdmin(userId string) bool { func isUserIdGlobalAdmin(userId string) bool {
return strings.HasPrefix(userId, "built-in/") || strings.HasPrefix(userId, "app/") return strings.HasPrefix(userId, "built-in/") || IsAppUser(userId)
} }
func ExtendUserWithRolesAndPermissions(user *User) (err error) { func ExtendUserWithRolesAndPermissions(user *User) (err error) {

View File

@ -464,3 +464,10 @@ func (user *User) IsAdminUser() bool {
return user.IsAdmin || user.IsGlobalAdmin() return user.IsAdmin || user.IsGlobalAdmin()
} }
func IsAppUser(userId string) bool {
if strings.HasPrefix(userId, "app/") {
return true
}
return false
}