Skip to content

N°7289 - Read-only attribute, dynamically read-write, entry silently ignored on submission#724

Open
accognet wants to merge 6 commits intodevelopfrom
feature/7577-GetAttributeFlags_Attributes_HIDDEN
Open

N°7289 - Read-only attribute, dynamically read-write, entry silently ignored on submission#724
accognet wants to merge 6 commits intodevelopfrom
feature/7577-GetAttributeFlags_Attributes_HIDDEN

Conversation

@accognet
Copy link
Contributor

@accognet accognet commented Jun 12, 2025

use this delta with GetCurrentValue in place of Get and Vincent's example (in bug 7289) will work :

<?xml version="1.0" encoding="UTF-8"?>
<itop_design xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.1">
  <classes>
    <class id="Location" _created_in="itop-structure" _delta="must_exist">
      <fields>
        <field id="person_id" xsi:type="AttributeExternalKey" _delta="define">
          <sql>person_id</sql>
          <filter/>
          <dependencies>
            <attribute id="status"/>
          </dependencies>
          <is_null_allowed>true</is_null_allowed>
          <target_class>Person</target_class>
          <on_target_delete>DEL_AUTO</on_target_delete>
          <tracking_level>all</tracking_level>
        </field>
      </fields>
      <methods>
        <method id="GetAttributeFlags" _delta="define">
          <comment></comment>
          <static>false</static>
          <access>public</access>
          <code><![CDATA[public function GetAttributeFlags($sAttCode, &$aReasons = array(), $sTargetState = '')
{
	if (($sAttCode == 'person_id') && ($this->GetCurrentValue('status') == 'inactive'))
    {
       // Combine the new Flag with those impose by a parent class
       return(OPT_ATT_READONLY | parent::GetAttributeFlags($sAttCode, $aReasons, $sTargetState));
    }
    return parent::GetAttributeFlags($sAttCode, $aReasons, $sTargetState);
	}]]></code>
        </method>
      </methods>
      <presentation>
        <details >
          <items>
            <item id="person_id" _delta="define">
              <rank>100</rank>
            </item>
          </items>
        </details>
      </presentation>
    </class>
  </classes>
  <dictionaries>
  </dictionaries>
  <files>
   </files>
  <branding>
  </branding>
</itop_design>

@accognet accognet self-assigned this Jun 12, 2025
@accognet accognet added enhancement New feature or request internal Work made by Combodo labels Jun 12, 2025
@accognet accognet requested a review from rquetiez June 12, 2025 15:43
@accognet accognet changed the title N°7577 - Issue with GetAttributeFlags when Attributes are set to HIDDEN N°7289 - Read-only attribute, dynamically read-write, entry silently ignored on submission Jun 12, 2025
* this is used to check the current value in GetAttributeFlag function (useful to manage dynamic readonly attributes)
* @param $sAttr
*/
public function GetCurrentValue($sAttCode)
Copy link
Contributor

Choose a reason for hiding this comment

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

Method name too vague and comment are somewhat cryptic to me.
Need some dialog to find how to name and describe things.

* this is used to check if field has been modifed in GetAttributeFlag function (useful to manage dynamic readonly attributes)
* @param $sAttr
*/
public function IsModifiedValue($sAttCode)
Copy link
Contributor

Choose a reason for hiding this comment

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

Method name too vague and comment are somewhat cryptic to me.
Need some dialog to find how to name and describe things.

@accognet accognet force-pushed the feature/7577-GetAttributeFlags_Attributes_HIDDEN branch 2 times, most recently from 5ad63c5 to d13532d Compare September 22, 2025 13:37
accognet and others added 6 commits October 2, 2025 11:34
Co-authored-by: Thomas Casteleyn <thomas.casteleyn@super-visions.com>
…essage only on console and portal context. Avoid messages during tests, setup and other case
@accognet accognet force-pushed the feature/7577-GetAttributeFlags_Attributes_HIDDEN branch from 456854d to 88c19e6 Compare October 2, 2025 09:35
@Molkobain Molkobain requested a review from Copilot January 28, 2026 20:34
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes the “dynamic readonly/read-write” behavior during form submission by allowing GetAttributeFlags() logic to rely on posted values (not only persisted ones), so fields that become writable/readonly based on in-form changes are handled correctly.

Changes:

  • Add storage of posted form values on cmdbAbstractObject and helper methods to read “current value in screen” / detect “modified in screen”.
  • Populate the stored posted values during UpdateObjectFromPostedForm() so flag computation can use them.
  • Adjust when ormLinkSet::UpdateFromCompleteList() emits a deprecated usage warning.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
core/ormlinkset.class.inc.php Changes the context gating for the deprecated “old linkedset persistence pattern” warning.
application/cmdbabstract.class.inc.php Stores posted values and adds helpers intended for dynamic GetAttributeFlags() computations during form submission.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +3905 to +3907
* This function checks if the value of the attribute has been modified in screen
* this is used to check if field has been modified in GetAttributeFlag function (useful to manage dynamic readonly attributes)
* @param $sAttCode
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

Same as above: the doc references “GetAttributeFlag” (singular / different casing) which doesn’t match the actual GetAttributeFlags() method name. Please fix the wording so integrators know which hook this is intended for.

Copilot uses AI. Check for mistakes.

$aErrors = array();
$aFinalValues = array();
$this->aPostedValues = $aValues; // Store the values for later use (e.g. in getAttributeFlag)
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

Minor doc/casing issue: comment says “getAttributeFlag” but the method is GetAttributeFlags() (and this assignment is used before calling it). Please align wording for clarity.

Suggested change
$this->aPostedValues = $aValues; // Store the values for later use (e.g. in getAttributeFlag)
$this->aPostedValues = $aValues; // Store the values for later use (e.g. in GetAttributeFlags())

Copilot uses AI. Check for mistakes.
Comment on lines +524 to 525
if (ContextTag::Check(ContextTag::TAG_PORTAL) || ContextTag::Check(ContextTag::TAG_CONSOLE) ) {
DeprecatedCallsLog::NotifyDeprecatedPhpMethod('old pattern - please get previous value of the linked set, modify it and set it back to the host object');
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The deprecation notification condition changed from “log everywhere except setup” to “log only in portal/console”. This significantly reduces visibility of this deprecated API usage in other contexts (REST/cron/custom scripts) and isn’t mentioned in the PR description; please confirm this behavior change is intended (or restore the previous !TAG_SETUP gating).

Copilot uses AI. Check for mistakes.
Comment on lines +179 to +182
/**
* @var array Store posted values in order to be used in GetAttributeFlag
*/
protected $aPostedValues = [];
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

Indentation of this new property/docblock doesn’t follow the surrounding convention in this file (tabs). Also the doc refers to “GetAttributeFlag” but the actual API is GetAttributeFlags() / GetFormAttributeFlags(); please update the wording to avoid confusion.

Copilot uses AI. Check for mistakes.
Comment on lines +3891 to +3894
/**
* function to test if the posted value or if not exists the existing value matches the expected value
* this is used to check the current value in GetAttributeFlag function (useful to manage dynamic readonly attributes)
* @param $sAttCode
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The PHPDoc is misleading: this method doesn’t “test” anything nor compare to an “expected value”; it returns the posted value (if any) or the object’s current value. Please rewrite the doc to match behavior (and reference GetAttributeFlags() with the correct name).

Copilot uses AI. Check for mistakes.
Comment on lines +3896 to +3897
public function GetCurrentValueInScreen($sAttCode)
{
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

PR description / example mentions using $this->GetCurrentValue('status'), but the new helper is named GetCurrentValueInScreen(). To make the documented usage work and keep the API intuitive, consider adding a GetCurrentValue() alias (or renaming this method) and updating references accordingly.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request internal Work made by Combodo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants