feat: add GetAllowedApplications() in user's app homepage

This commit is contained in:
Yang Luo
2023-11-08 09:48:31 +08:00
parent a389842f59
commit 498cd02d49
2 changed files with 35 additions and 0 deletions

View File

@ -173,6 +173,12 @@ func (c *ApiController) GetOrganizationApplications() {
return return
} }
applications, err = object.GetAllowedApplications(applications, userId)
if err != nil {
c.ResponseError(err.Error())
return
}
c.ResponseOk(object.GetMaskedApplications(applications, userId)) c.ResponseOk(object.GetMaskedApplications(applications, userId))
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)

View File

@ -345,6 +345,35 @@ func GetMaskedApplications(applications []*Application, userId string) []*Applic
return applications return applications
} }
func GetAllowedApplications(applications []*Application, userId string) ([]*Application, error) {
if isUserIdGlobalAdmin(userId) {
return applications, nil
}
user, err := GetUser(userId)
if err != nil {
return nil, err
}
if user.IsAdmin {
return applications, nil
}
res := []*Application{}
for _, application := range applications {
var allowed bool
allowed, err = CheckLoginPermission(userId, application)
if err != nil {
return nil, err
}
if allowed {
res = append(res, application)
}
}
return res, nil
}
func UpdateApplication(id string, application *Application) (bool, error) { func UpdateApplication(id string, application *Application) (bool, error) {
owner, name := util.GetOwnerAndNameFromId(id) owner, name := util.GetOwnerAndNameFromId(id)
oldApplication, err := getApplication(owner, name) oldApplication, err := getApplication(owner, name)