Skip to content

Fix ticket observer can edit - #1278

Open
Herafia wants to merge 6 commits into
mainfrom
fix/ticket-observer-readonly-fields
Open

Herafia wants to merge 6 commits into
mainfrom
fix/ticket-observer-readonly-fields

Conversation

@Herafia

@Herafia Herafia commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Checklist before requesting a review

Please delete options that are not relevant.

  • I have performed a self-review of my code.
  • I have added tests (when available) that prove my fix is effective or that my feature works.
  • I have updated the CHANGELOG with a short functional description of the fix or new feature.
  • This change requires a documentation update.

Description

  • It fixes !46589
  • An observer on a ticket could modify and save custom fields
    because rights were only checked at the container-profile level, not against the
    specific item. Fields are now rendered as read-only for users who cannot update the
    item, and the pre_item_update hook enforces the same check server-side.

@Herafia Herafia self-assigned this Sep 29, 2026
@Herafia
Herafia force-pushed the fix/ticket-observer-readonly-fields branch from cbf1133 to bd189b5 Compare September 30, 2026 07:53
@Herafia
Herafia requested review from Rom1-B and stonebuzz September 30, 2026 07:55

@Rom1-B Rom1-B left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test covering PluginFieldsContainer::preItemUpdate() directly (e.g. a central-interface user without ticket update right but with write access on the container) asserting _plugin_fields_data is stripped/not persisted?

Comment thread inc/container.class.php
Comment on lines +1905 to +1911
if (
isset($_SESSION['glpiactiveprofile']['id'])
&& $_SESSION['glpiactiveprofile']['id'] != null
&& $item instanceof CommonITILObject
&& Session::getCurrentInterface() === 'helpdesk'
&& !$item->canRequesterUpdateItem()
) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scoping this to helpdesk + CommonITILObject reopens the bug for central-interface users without update right (e.g. an observer with only READASSIGN). The patch validated on ticket !46589 used !$item->canUpdateItem() unconditionally, matching the field.class.php display-side fix — Ticket::canUpdateItem() already handles both interfaces correctly.

Suggested change
if (
isset($_SESSION['glpiactiveprofile']['id'])
&& $_SESSION['glpiactiveprofile']['id'] != null
&& $item instanceof CommonITILObject
&& Session::getCurrentInterface() === 'helpdesk'
&& !$item->canRequesterUpdateItem()
) {
if (
isset($_SESSION['glpiactiveprofile']['id'])
&& $_SESSION['glpiactiveprofile']['id'] !== null
&& !$item->canUpdateItem()
) {

Comment thread inc/container.class.php
*
* @return boolean
*/
public static function preItemUpdate(CommonDBTM $item)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a rights fix and the PR adds no test, even though tests/Units/ContainerItemRightTest.php already covers this area. A non-regression test should log in as a self-service observer, call $ticket->update([... dom field values ...]) and assert the stored value did not change. A second test should assert that a requester who is still allowed to edit (no followup yet) can save.

Comment thread inc/field.class.php
}

$canedit = $right > READ;
$canedit = $right > READ && ($item->isNewItem() || $item->canUpdateItem());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new $canedit rule ($item->isNewItem() || $item->canUpdateItem()) is untested, both here and in showForTabContainer() at line 894. A rendering test should assert that the inputs are read-only for a helpdesk observer and editable on a new item.

@Herafia
Herafia force-pushed the fix/ticket-observer-readonly-fields branch from 6262e88 to 83e4dc2 Compare September 30, 2026 15:26
@Herafia
Herafia requested a review from stonebuzz September 30, 2026 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants