Menu

Hiding or removing a field based on profile

Cyro
2025-06-26
2025-06-26
  • Cyro

    Cyro - 2025-06-26

    Heya,

    I'm trying to ensure that a specific field in the Organization class does not appear for users that have the "Portal User" profile. The issue is that I do not believe GetAttributeFlags nor GetInitialStateAttributeFlags is invoking properly. I've tried it for both the customer portal and the backoffice. Itop version is 3.1.0. I'm looking to hide or remove the field.

    Would anyone have an idea about this?

    <?xml version="1.0" encoding="UTF-8"?>
    <itop_design xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.6">
      <constants>
      </constants>
      <classes>
     <class id="Organization"  _delta="must_exist">
         <fields>
          <field id="organization_customerclass" xsi:type="AttributeString" _delta="define">
            <sql>organization_customerclass</sql>
            <default_value/>
            <is_null_allowed>true</is_null_allowed>
            <on_target_delete>DEL_AUTO</on_target_delete>
           </field>
         </fields>
        <presentation>
         <details>
           <items>
             <item id="tab:Info" _delta="define">
               <rank>32</rank>
               <items>
                <item id="fieldset:Info">
                  <rank>10</rank>
                  <items>
                    <item id="organization_customerclass">
                      <rank>10</rank>
                    </item>
                  </items>
                </item>
              </items>
             </item>
           </items>
         </details>
       </presentation>
       <methods> 
              <method id="GetAttributeFlags" _delta="define">
                <static>false</static>
                <access>public</access>
                <code><![CDATA[
                  public function GetAttributeFlags($sAttCode, &$aReasons = array(), $sTargetState = '')
                  {    
                     IssueLog::Info("GetAttributeFlags called for $sAttCode");
                      if (($sAttCode == 'organization_customerclass') && (UserRights::HasProfile('Portal User')))
                      {
                          return(OPT_ATT_READONLY | OPT_ATT_HIDDEN | parent::GetAttributeFlags($sAttCode, $aReasons, $sTargetState));
                      }
                      return parent::GetAttributeFlags($sAttCode, $aReasons, $sTargetState);
                  }
                ]]></code>
              </method>
              <method id="GetInitialStateAttributeFlags" _delta="define">
                <static>false</static>
                <access>public</access>
                <code><![CDATA[
                  public function GetInitialStateAttributeFlags($sAttCode, &$aReasons = array())
                  {    
                      IssueLog::Info("GetInitialStateAttributeFlags called for $sAttCode");
                      if (($sAttCode == 'organization_customerclass') && (UserRights::HasProfile('Portal User')))
                      {
                          return(OPT_ATT_READONLY | OPT_ATT_HIDDEN | parent::GetInitialStateAttributeFlags($sAttCode, $aReasons));
                      }
                      return parent::GetInitialStateAttributeFlags($sAttCode, $aReasons);
                  }
                ]]></code>
              </method>
         </methods>
       </class>
      </classes>
      <menus>
      </menus>
      <user_rights>
        <groups>
        </groups>
        <profiles>
        </profiles>
      </user_rights>
    </itop_design>
    
     

    Last edit: Cyro 2025-06-26
  • Cyro

    Cyro - 2025-06-26

    Heya,

    Looks like the issue was that UserRights::HasProfile('Portal User') should be lowercase: UserRights::HasProfile('Portal user')

     
  • Vincent @ Combodo

    Using GetAttributeFlags to hide a field of a class to a Portal User, is not the easiest solution.
    When you are a Portal User, you only have access on itop-portal, adding a specific form, for the class Organization on the Portal, without that particular field, does the job...

     
    👍
    1

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.