Skip to content

Commit

Permalink
apps dropdown apis auth free for super admin now (devtron-labs#2145)
Browse files Browse the repository at this point in the history
  • Loading branch information
vikramdevtron authored Aug 8, 2022
1 parent ccf1119 commit 03d1b14
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions api/restHandler/app/AutoCompleteRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ func (handler PipelineConfigRestHandlerImpl) GetAppListForAutocomplete(w http.Re
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
return
}
isActionUserSuperAdmin, err := handler.userAuthService.IsSuperAdmin(int(userId))
if err != nil {
common.WriteJsonResp(w, err, "Failed to check admin check", http.StatusInternalServerError)
return
}

v := r.URL.Query()
teamId := v.Get("teamId")
appName := v.Get("appName")
Expand Down Expand Up @@ -55,6 +61,10 @@ func (handler PipelineConfigRestHandlerImpl) GetAppListForAutocomplete(w http.Re
// RBAC
objects := handler.enforcerUtil.GetRbacObjectsForAllApps()
for _, app := range apps {
if isActionUserSuperAdmin {
accessedApps = append(accessedApps, app)
continue
}
object := objects[app.Id]
if ok := handler.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionGet, object); ok {
accessedApps = append(accessedApps, app)
Expand Down
10 changes: 10 additions & 0 deletions api/restHandler/app/PipelineConfigRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,12 @@ func (handler PipelineConfigRestHandlerImpl) GetAppListByTeamIds(w http.Response
return
}

isActionUserSuperAdmin, err := handler.userAuthService.IsSuperAdmin(int(userId))
if err != nil {
common.WriteJsonResp(w, err, "Failed to check admin check", http.StatusInternalServerError)
return
}

appType := v.Get("appType")
handler.Logger.Infow("request payload, GetAppListByTeamIds", "payload", params)
var teamIds []int
Expand All @@ -510,6 +516,10 @@ func (handler PipelineConfigRestHandlerImpl) GetAppListByTeamIds(w http.Response
for _, project := range projectWiseApps {
var accessedApps []*pipeline.AppBean
for _, app := range project.AppList {
if isActionUserSuperAdmin {
accessedApps = append(accessedApps, app)
continue
}
object := fmt.Sprintf("%s/%s", project.ProjectName, app.Name)
if ok := handler.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionGet, object); ok {
accessedApps = append(accessedApps, app)
Expand Down

0 comments on commit 03d1b14

Please sign in to comment.