Skip to content

The only tool you need to know what is happening and how to fix it.

bug: creating new project works

dduxbc7ca58a9236
diff --git a/backend/app/controllers/project.controller.go b/backend/app/controllers/project.controller.go
index 4eca7313..f9eb0044 100644
--- a/backend/app/controllers/project.controller.go
+++ b/backend/app/controllers/project.controller.go
@@ -7,6 +7,7 @@ import (
"backend/app/pgdb"
"backend/app/repositories"
"database/sql"
+ "fmt"
"net/http"
"regexp"
"unicode/utf8"
@@ -83,8 +84,21 @@ func (p projectController) CreateProject(c *gin.Context) {
return
}
+ projectId, err := middleware.GetProjectId(c)
+ if err != nil {
+ c.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("RequireProjectAccess middleware must be applied: %w", err))
+ return
+ }
+
project, err := pgdb.ExecuteTransaction(func(tx *sql.Tx) (*models.Project, error) {
- return repositories.ProjectRepository.Create(tx, request.Name, request.Framework)
+ currentProject, err := repositories.ProjectRepository.FindById(tx, projectId)
+ if err != nil {
+ return nil, err
+ }
+ if currentProject == nil || currentProject.OrganizationId == nil {
+ return nil, fmt.Errorf("current project has no organization")
+ }
+ return repositories.ProjectRepository.CreateWithOrganization(tx, request.Name, request.Framework, *currentProject.OrganizationId)
})
if err != nil {
c.AbortWithError(500, traceway.NewStackTraceErrorf("error creating a project: %w", err))
diff --git a/backend/app/controllers/routes.go b/backend/app/controllers/routes.go
index f7ca0247..60c24703 100644
--- a/backend/app/controllers/routes.go
+++ b/backend/app/controllers/routes.go
@@ -33,7 +33,7 @@ func RegisterControllers(router *gin.RouterGroup) {
// Project management
router.GET("/projects", middleware.UseAppAuth, ProjectController.ListProjects)
- router.POST("/projects", middleware.UseAppAuth, middleware.RequireWriteAccess, ProjectController.CreateProject)
+ router.POST("/projects", middleware.UseAppAuth, middleware.RequireProjectAccess, middleware.RequireWriteAccess, ProjectController.CreateProject)
// Dashboard endpoints (projectId in query param)
router.POST("/stats", middleware.UseAppAuth, middleware.RequireProjectAccess, MetricRecordController.FindHomepageStats)