Skip to content

Commit

Permalink
Merge pull request #1655 from stakwork/feat/fix_feature_workspace
Browse files Browse the repository at this point in the history
Added checkers for workspace and feature
  • Loading branch information
elraphty authored May 19, 2024
2 parents 8a831f5 + 644e7c5 commit 4899a3f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
16 changes: 16 additions & 0 deletions handlers/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ func (oh *featureHandler) CreateOrEditFeatures(w http.ResponseWriter, r *http.Re
return
}

// Check if workspace exists
workpace := oh.db.GetWorkspaceByUuid(features.WorkspaceUuid)
if workpace.Uuid != features.WorkspaceUuid {
w.WriteHeader(http.StatusUnauthorized)
json.NewEncoder(w).Encode("Workspace does not exists")
return
}

p, err := oh.db.CreateOrEditFeature(features)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
Expand Down Expand Up @@ -147,6 +155,14 @@ func (oh *featureHandler) CreateOrEditFeaturePhase(w http.ResponseWriter, r *htt

newPhase.UpdatedBy = pubKeyFromAuth

// Check if feature exists
feature := oh.db.GetFeatureByUuid(newPhase.FeatureUuid)
if feature.Uuid != newPhase.FeatureUuid {
w.WriteHeader(http.StatusUnauthorized)
json.NewEncoder(w).Encode("Feature does not exists")
return
}

phase, err := oh.db.CreateOrEditFeaturePhase(newPhase)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
Expand Down
8 changes: 8 additions & 0 deletions handlers/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,14 @@ func (oh *workspaceHandler) CreateWorkspaceRepository(w http.ResponseWriter, r *
return
}

// Check if workspace exists
workpace := oh.db.GetWorkspaceByUuid(workspaceRepo.WorkspaceUuid)
if workpace.Uuid != workspaceRepo.WorkspaceUuid {
w.WriteHeader(http.StatusUnauthorized)
json.NewEncoder(w).Encode("Workspace does not exists")
return
}

p, err := oh.db.CreateWorkspaceRepository(workspaceRepo)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
Expand Down

0 comments on commit 4899a3f

Please sign in to comment.