Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(docs): hide a private project's issue in doc history (#10967)

pseudoyub6edca475a02
diff --git a/server/internal/handler/doc.go b/server/internal/handler/doc.go
index bd8c7c05ea..a1dfb2d410 100644
--- a/server/internal/handler/doc.go
+++ b/server/internal/handler/doc.go
@@ -652,7 +652,7 @@ func (h *Handler) DeleteDoc(w http.ResponseWriter, r *http.Request) {
}
func (h *Handler) ListDocVersions(w http.ResponseWriter, r *http.Request) {
- _, wsUUID, _, ok := h.docWorkspace(w, r)
+ _, wsUUID, workspaceID, ok := h.docWorkspace(w, r)
if !ok {
return
}
@@ -666,14 +666,19 @@ func (h *Handler) ListDocVersions(w http.ResponseWriter, r *http.Request) {
return
}
versions := make([]DocVersionResponse, len(rows))
+ issueIDs := make([]pgtype.UUID, len(rows))
for i, v := range rows {
versions[i] = docVersionRowToResponse(v)
+ issueIDs[i] = v.IssueID
+ }
+ if !h.hideDocVersionIssues(w, r, workspaceID, versions, issueIDs) {
+ return
}
writeJSON(w, http.StatusOK, map[string]any{"versions": versions})
}
func (h *Handler) GetDocVersion(w http.ResponseWriter, r *http.Request) {
- _, wsUUID, _, ok := h.docWorkspace(w, r)
+ _, wsUUID, workspaceID, ok := h.docWorkspace(w, r)
if !ok {
return
}
@@ -695,7 +700,40 @@ func (h *Handler) GetDocVersion(w http.ResponseWriter, r *http.Request) {
}
return
}
- writeJSON(w, http.StatusOK, docVersionToResponse(v, true))
+ versions := []DocVersionResponse{docVersionToResponse(v, true)}
+ if !h.hideDocVersionIssues(w, r, workspaceID, versions, []pgtype.UUID{v.IssueID}) {
+ return
+ }
+ writeJSON(w, http.StatusOK, versions[0])
+}
+
+// hideDocVersionIssues clears issue_id on the versions whose issue sits in a
+// private project the caller cannot see (MUL-8472). The edit and its task_id
+// stay, as a restricted run does in an agent's history. versions and issueIDs
+// are parallel slices. It writes a 500 and returns false when access cannot
+// be resolved.
+func (h *Handler) hideDocVersionIssues(w http.ResponseWriter, r *http.Request, workspaceID string, versions []DocVersionResponse, issueIDs []pgtype.UUID) bool {
+ hidden, ok := h.requestHiddenProjects(w, r, workspaceID)
+ if !ok {
+ return false
+ }
+ named := make([]pgtype.UUID, 0, len(issueIDs))
+ for _, id := range issueIDs {
+ if id.Valid {
+ named = append(named, id)
+ }
+ }
+ hiddenIssues, err := h.hiddenIssueIDs(r, hidden, named)
+ if err != nil {
+ writeError(w, http.StatusInternalServerError, "failed to resolve project access")
+ return false
+ }
+ for i, id := range issueIDs {
+ if _, hide := hiddenIssues[id]; hide {
+ versions[i].IssueID = nil
+ }
+ }
+ return true
}
// --- Folders ---
diff --git a/server/internal/handler/doc_test.go b/server/internal/handler/doc_test.go
index 3b8f99de8b..65002a8667 100644
--- a/server/internal/handler/doc_test.go
+++ b/server/internal/handler/doc_test.go
@@ -274,3 +274,67 @@ func TestSearchDocsRanksTitleHitsAndExcerptsContent(t *testing.T) {
t.Fatalf("search leaked across workspaces: %v", ids(other))
}
}
+
+// History links an agent's edit to the run and the issue it came from. An
+// issue in a private project is not named to a member who cannot see that
+// project; the edit and its run stay in the history.
+func TestDocVersionsHideIssuesInPrivateProjects(t *testing.T) {
+ f := newPrivateProjectFixture(t)
+ agentID := createHandlerTestAgent(t, f.marker+"-writer", []byte(`{}`))
+ doc := createDocForTest(t)
+ revision := doc.Revision
+ edit := func(issueID, content string) string {
+ t.Helper()
+ taskID := dbfx.Task(t, agentID, testutil.Cols{"issue_id": issueID, "runtime_id": testRuntimeID, "status": "running"})
+ req := agentRequest("PATCH", "/api/docs/"+doc.ID, map[string]any{"base_revision": revision, "content": content}, agentID, taskID)
+ var updated DocResponse
+ testutil.Call(t, testHandler.UpdateDoc, withURLParam(req, "id", doc.ID)).Want(http.StatusOK).JSON(&updated)
+ revision = updated.Revision
+ return taskID
+ }
+ secretTask := edit(f.secretIssue, "from the private project")
+ publicTask := edit(f.publicIssue, "from a workspace issue")
+
+ issueOf := func(v DocVersionResponse) string {
+ if v.IssueID == nil {
+ return ""
+ }
+ return *v.IssueID
+ }
+ for _, tc := range []struct {
+ name, userID, secretIssue string
+ }{
+ {"project member", f.insider, f.secretIssue},
+ {"workspace member outside the project", f.outsider, ""},
+ {"workspace admin outside the project", f.outsideAdmin, ""},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ var history struct {
+ Versions []DocVersionResponse `json:"versions"`
+ }
+ list := asUser(newRequest("GET", "/api/docs/"+doc.ID+"/versions", nil), tc.userID)
+ testutil.Call(t, testHandler.ListDocVersions, withURLParam(list, "id", doc.ID)).Want(http.StatusOK).JSON(&history)
+ if len(history.Versions) != 3 {
+ t.Fatalf("history has %d versions, want 3", len(history.Versions))
+ }
+ // Newest first: the workspace issue's edit, then the private one.
+ for i, want := range []struct{ number, task, issue string }{
+ {"3", publicTask, f.publicIssue},
+ {"2", secretTask, tc.secretIssue},
+ } {
+ listed := history.Versions[i]
+ var single DocVersionResponse
+ get := asUser(newRequest("GET", "/api/docs/"+doc.ID+"/versions/"+want.number, nil), tc.userID)
+ testutil.Call(t, testHandler.GetDocVersion, withURLParams(get, "id", doc.ID, "number", want.number)).Want(http.StatusOK).JSON(&single)
+ for where, v := range map[string]DocVersionResponse{"list": listed, "single version": single} {
+ if v.TaskID == nil || *v.TaskID != want.task {
+ t.Errorf("%s v%s: task_id = %v, want %s", where, want.number, v.TaskID, want.task)
+ }
+ if got := issueOf(v); got != want.issue {
+ t.Errorf("%s v%s: issue_id = %q, want %q", where, want.number, got, want.issue)
+ }
+ }
+ }
+ })
+ }
+}