Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

Respect user=xxx in the GET /project endpoint

天舟844839d0dc51
diff --git a/backend/api/project.go b/backend/api/project.go
index b524a1b651..50d825700b 100644
--- a/backend/api/project.go
+++ b/backend/api/project.go
@@ -39,6 +39,10 @@ type ProjectFind struct {
// Standard fields
WorkspaceId *int
+
+ // Domain specific fields
+ // If present, will only find project containing PrincipalId as a member
+ PrincipalId *int
}
type ProjectPatch struct {
diff --git a/backend/server/project.go b/backend/server/project.go
index ccdad34bbd..45c3f88f11 100644
--- a/backend/server/project.go
+++ b/backend/server/project.go
@@ -43,6 +43,13 @@ func (s *Server) registerProjectRoutes(g *echo.Group) {
projectFind := &api.ProjectFind{
WorkspaceId: &workspaceId,
}
+ if userIdStr := c.QueryParam("user"); userIdStr != "" {
+ userId, err := strconv.Atoi(userIdStr)
+ if err != nil {
+ return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Query parameter user is not a number: %s", userIdStr)).SetInternal(err)
+ }
+ projectFind.PrincipalId = &userId
+ }
list, err := s.ProjectService.FindProjectList(context.Background(), projectFind)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to fetch project list").SetInternal(err)
diff --git a/backend/store/project.go b/backend/store/project.go
index 759b13cd7f..61d640b6ec 100644
--- a/backend/store/project.go
+++ b/backend/store/project.go
@@ -157,6 +157,9 @@ func findProjectList(ctx context.Context, tx *Tx, find *api.ProjectFind) (_ []*a
if v := find.WorkspaceId; v != nil {
where, args = append(where, "workspace_id = ?"), append(args, *v)
}
+ if v := find.PrincipalId; v != nil {
+ where, args = append(where, "id IN (SELECT project_id FROM project_member WHERE principal_id = ?)"), append(args, *v)
+ }
rows, err := tx.QueryContext(ctx, `
SELECT