Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix(review): keep a review result's text the reviewer's
rebelice3fb2d442d936
diff --git a/backend/store/issue_comment.go b/backend/store/issue_comment.goindex 26bd39faf2..0fdf79c105 100644--- a/backend/store/issue_comment.go+++ b/backend/store/issue_comment.go@@ -466,9 +466,11 @@ func (s *Store) UpdateIssueComment(ctx context.Context, patch *UpdateIssueCommen}// Text edits apply to rows that already render text: thread roots,// replies, hybrid event+comment rows, and plain comments (protojson omits- // an empty comment, so a contentless one is {}) — never to pure events.+ // an empty comment, so a contentless one is {}) — never to pure events,+ // and never to review results, whose text is the reviewer's.if patch.Comment != nil {q.And("(payload ?? 'comment' OR payload = '{}'::jsonb OR thread_state IS NOT NULL OR parent_id IS NOT NULL)")+ q.And("NOT (payload ?? 'reviewMetadata')")}query, args, err := q.ToSQL()@@ -488,6 +490,12 @@ func (s *Store) UpdateIssueComment(ctx context.Context, patch *UpdateIssueCommenif patch.ThreadState != nil {return common.Errorf(common.NotFound, "comment %s in project %s is missing or not a thread root; nothing was updated", patch.ResourceID, patch.ProjectID)}+ var reviewResult bool+ if err := s.GetDB().QueryRowContext(ctx,+ "SELECT payload ? 'reviewMetadata' FROM issue_comment WHERE project = $1 AND resource_id = $2",+ patch.ProjectID, patch.ResourceID).Scan(&reviewResult); err == nil && reviewResult {+ return common.Errorf(common.Invalid, "comment %s in project %s is a review result; its text belongs to the reviewer and only its thread state can change", patch.ResourceID, patch.ProjectID)+ }return common.Errorf(common.NotFound, "comment %s in project %s is missing or a pure event; nothing was updated", patch.ResourceID, patch.ProjectID)}return nildiff --git a/backend/store/review_run_results_test.go b/backend/store/review_run_results_test.goindex debd25f870..fc8cf5b8d6 100644--- a/backend/store/review_run_results_test.go+++ b/backend/store/review_run_results_test.go@@ -5,6 +5,7 @@ import ("github.com/stretchr/testify/require"+ "github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/store")@@ -211,6 +212,24 @@ func TestCompleteReviewRunPostsResults(t *testing.T) {}require.ElementsMatch(t, []string{"person", "guideline", "default third"}, comments)+ // A review result's text belongs to the reviewer: a person can resolve or+ // reopen it but not rewrite it. A person's own thread stays editable.+ resolved := store.ThreadStateResolved+ for _, c := range openThreads {+ text := "rewritten"+ err := s.UpdateIssueComment(ctx, &store.UpdateIssueCommentMessage{ProjectID: "default", ResourceID: c.ResourceID, Comment: &text})+ if c.Payload.ReviewMetadata != nil {+ require.Equal(t, common.Invalid, common.ErrorCode(err), c.Payload.Comment)+ require.NoError(t, s.UpdateIssueComment(ctx, &store.UpdateIssueCommentMessage{ProjectID: "default", ResourceID: c.ResourceID, ThreadState: &resolved}))+ require.NoError(t, s.UpdateIssueComment(ctx, &store.UpdateIssueCommentMessage{ProjectID: "default", ResourceID: c.ResourceID, ThreadState: &open}))+ } else {+ require.NoError(t, err, c.Payload.Comment)+ }+ }+ for _, c := range listReviewComments(t, fixture, "default") {+ require.NotEqual(t, "rewritten", c.Comment)+ }+// A clean DONE with no results still resolves the previous ones._, err = s.CreateReviewRun(ctx, "default", issueUID, store.ReviewRunTypeRule)require.NoError(t, err)