View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0037474 | mantisbt | security | public | 2026-10-31 15:10 | 2026-11-22 16:08 |
| Reporter | dombn | Assigned To | dregad | ||
| Priority | normal | Severity | minor | Reproducibility | always |
| Status | closed | Resolution | fixed | ||
| Product Version | 1.3.0 | ||||
| Target Version | 2.29.0 | Fixed in Version | 2.29.0 | ||
| Summary | 0037474: Updating an existing note via REST/SOAP resets its view state if none is given | ||||
| Description | When an existing note is updated through mc_issue_update() without specifying a view_state, the note's view state is reset to default_bugnote_view_status instead of being left unchanged. With the default configuration this means a private note becomes public when only its text is edited, e.g. via PATCH /api/rest/issues/{id} (rest_issue_update() calls mc_issue_update()) or via SOAP mc_issue_update. The cause is in api/soap/mc_issue_api.php, mc_issue_update():
This default is applied to existing notes as well. Text and time tracking are only changed when specified; view_state is not. Affects master-2.28 (2.28.4) and master. | ||||
| Steps To Reproduce |
| ||||
| Additional Information | The attached patch only evaluates The patch applies cleanly to master-2.28 and master. I verified the fix on our 2.28.4 instance via REST (before: note became public; after: note stays private, explicit view_state changes still work). I was not able to run the SOAP test suite locally. Happy to submit it as a GitHub PR once you think that is appropriate. | ||||
| Tags | No tags attached. | ||||
| Attached Files | 0001-Keep-note-view-state-on-update-if-not-specified.patch (4,452 bytes)
From 8ef7de79034acb6ae1df40a1acfdfc3228c8273b Mon Sep 17 00:00:00 2001
From: Dominik Pesch <d.pesch@11com7.de>
Date: Sat, 31 Oct 2026 18:34:07 +0100
Subject: [PATCH] Keep note view state on update if not specified
mc_issue_update() reset the view state of existing notes to
default_bugnote_view_status when the update did not include a view
state, e.g. via REST PATCH with only the note text. Only apply the
view state when it is specified, as already done for text and
time tracking.
---
api/soap/mc_issue_api.php | 13 +++++-----
tests/soap/IssueUpdateTest.php | 44 ++++++++++++++++++++++++++++++++++
2 files changed, 51 insertions(+), 6 deletions(-)
diff --git a/api/soap/mc_issue_api.php b/api/soap/mc_issue_api.php
index 7a1595bf8..e7332b1d2 100644
--- a/api/soap/mc_issue_api.php
+++ b/api/soap/mc_issue_api.php
@@ -1203,13 +1203,10 @@ function mc_issue_update( $p_username, $p_password, $p_issue_id, stdClass $p_iss
foreach( $p_issue['notes'] as $t_note ) {
$t_note = ApiObjectFactory::objectToArray( $t_note );
- $t_view_state = $t_note['view_state'] ?? config_get( 'default_bugnote_view_status' );
if( isset( $t_note['id'] ) && ( (int)$t_note['id'] > 0 ) ) {
$t_bugnote_id = (int)$t_note['id'];
- $t_view_state_id = mci_get_enum_id_from_objectref( 'view_state', $t_view_state );
-
if( array_key_exists( $t_bugnote_id, $t_bugnotes_by_id ) ) {
$t_bugnote = $t_bugnotes_by_id[$t_bugnote_id];
@@ -1228,9 +1225,13 @@ function mc_issue_update( $p_username, $p_password, $p_issue_id, stdClass $p_iss
$t_bugnote_changed = true;
}
- if( $t_bugnote->view_state != $t_view_state_id ) {
- bugnote_set_view_state( $t_bugnote_id, $t_view_state_id == VS_PRIVATE );
- $t_bugnote_changed = true;
+ # Only change the view state if specified, otherwise keep it
+ if( isset( $t_note['view_state'] ) ) {
+ $t_view_state_id = mci_get_enum_id_from_objectref( 'view_state', $t_note['view_state'] );
+ if( $t_bugnote->view_state != $t_view_state_id ) {
+ bugnote_set_view_state( $t_bugnote_id, $t_view_state_id == VS_PRIVATE );
+ $t_bugnote_changed = true;
+ }
}
if( isset( $t_note['time_tracking']) && $t_note['time_tracking'] != $t_bugnote->time_tracking ) {
diff --git a/tests/soap/IssueUpdateTest.php b/tests/soap/IssueUpdateTest.php
index 05b21d3e3..de8f30191 100644
--- a/tests/soap/IssueUpdateTest.php
+++ b/tests/soap/IssueUpdateTest.php
@@ -358,6 +358,50 @@ class IssueUpdateTest extends SoapBase {
$this->assertEquals( 30, $t_issue_with_note->notes[0]->time_tracking );
}
+ /**
+ * Updating an existing note without specifying its view state must not
+ * change the view state, while an explicit view state is still applied.
+ *
+ * @return void
+ */
+ public function testUpdateNoteKeepsViewStateIfNotSpecified() {
+ $t_issue_to_add = $this->getIssueToAdd();
+ $t_issue_id = $this->client->mc_issue_add( $this->userName, $this->password, $t_issue_to_add );
+ $this->deleteAfterRun( $t_issue_id );
+
+ $t_note_id = $this->client->mc_issue_note_add( $this->userName, $this->password, $t_issue_id, array(
+ 'text' => 'private note',
+ 'view_state' => array( 'id' => VS_PRIVATE ),
+ ) );
+
+ # Update the note text only, without a view state
+ $t_issue = $this->client->mc_issue_get( $this->userName, $this->password, $t_issue_id );
+ $t_issue->notes = array(
+ array(
+ 'id' => $t_note_id,
+ 'text' => 'private note, edited',
+ )
+ );
+ $this->client->mc_issue_update( $this->userName, $this->password, $t_issue_id, $t_issue );
+
+ $t_issue = $this->client->mc_issue_get( $this->userName, $this->password, $t_issue_id );
+ $this->assertCount( 1, $t_issue->notes );
+ $this->assertEquals( 'private note, edited', $t_issue->notes[0]->text );
+ $this->assertEquals( VS_PRIVATE, $t_issue->notes[0]->view_state->id, 'View state is unchanged' );
+
+ # Explicitly changing the view state still works
+ $t_issue->notes = array(
+ array(
+ 'id' => $t_note_id,
+ 'view_state' => array( 'id' => VS_PUBLIC ),
+ )
+ );
+ $this->client->mc_issue_update( $this->userName, $this->password, $t_issue_id, $t_issue );
+
+ $t_issue = $this->client->mc_issue_get( $this->userName, $this->password, $t_issue_id );
+ $this->assertEquals( VS_PUBLIC, $t_issue->notes[0]->view_state->id, 'View state has been changed' );
+ }
+
/**
* Adding REMINDER notes is not supported.
--
2.56.0.windows.4
| ||||
|
MantisBT: master d736817f 2026-10-31 13:34 Committer: dregad Details Diff |
Keep note view state on update if not specified mc_issue_update() reset the view state of existing notes to default_bugnote_view_status when the update did not include a view state, e.g. via REST PATCH with only the note text. Only apply the view state when it is specified, as already done for text and time tracking. Fixes 0037474 Signed-off-by: Damien Regad <dregad@mantisbt.org> |
Affected Issues 0037474 |
|
| mod - api/soap/mc_issue_api.php | Diff File | ||
| mod - tests/soap/IssueUpdateTest.php | Diff File | ||