Skip to content

Open source AI coding agent. Designed for large projects and real world tasks.

for list plans, don't error for missing projectIds unless there are 0 valid ones

Dane Schneider3d4c56c093de
diff --git a/app/server/handlers/auth_helpers.go b/app/server/handlers/auth_helpers.go
index 0e369296..fb9d372d 100644
--- a/app/server/handlers/auth_helpers.go
+++ b/app/server/handlers/auth_helpers.go
@@ -150,6 +150,10 @@ func authenticate(w http.ResponseWriter, r *http.Request, requireOrg bool) *type
}
func authorizeProject(w http.ResponseWriter, projectId string, auth *types.ServerAuth) bool {
+ return authorizeProjectOptional(w, projectId, auth, true)
+}
+
+func authorizeProjectOptional(w http.ResponseWriter, projectId string, auth *types.ServerAuth, shouldErr bool) bool {
log.Println("authorizing project")
projectExists, err := db.ProjectExists(auth.OrgId, projectId)
@@ -160,13 +164,13 @@ func authorizeProject(w http.ResponseWriter, projectId string, auth *types.Serve
return false
}
- if !projectExists {
+ if !projectExists && shouldErr {
log.Println("project does not exist in org")
http.Error(w, "project does not exist in org", http.StatusNotFound)
return false
}
- return true
+ return projectExists
}
func authorizeProjectRename(w http.ResponseWriter, projectId string, auth *types.ServerAuth) bool {
diff --git a/app/server/handlers/plans_crud.go b/app/server/handlers/plans_crud.go
index bdfadad8..f53984f2 100644
--- a/app/server/handlers/plans_crud.go
+++ b/app/server/handlers/plans_crud.go
@@ -324,13 +324,20 @@ func ListPlansHandler(w http.ResponseWriter, r *http.Request) {
return
}
+ authorizedProjectIds := []string{}
for _, projectId := range projectIds {
- if !authorizeProject(w, projectId, auth) {
- return
+ if authorizeProjectOptional(w, projectId, auth, false) {
+ authorizedProjectIds = append(authorizedProjectIds, projectId)
}
}
- plans, err := db.ListOwnedPlans(projectIds, auth.User.Id, false)
+ if len(authorizedProjectIds) == 0 {
+ log.Println("No authorized project ids provided")
+ http.Error(w, "No authorized project ids provided", http.StatusForbidden)
+ return
+ }
+
+ plans, err := db.ListOwnedPlans(authorizedProjectIds, auth.User.Id, false)
if err != nil {
log.Printf("Error listing plans: %v\n", err)