Sidebar

Using iTop

Creating your iTop

iTop Customization

"How to" examples
DataModel

User Interface

Automation & Ticket management

Portal Customization

:: Version 3.2.0 ::

Hide transitions

Prerequisite: You must be familiar with the Syntax used in Tutorials and have already created an extension.

learning:
Hide a transition in some circumstance
level:
Advanced
domains:
PHP
min version:
3.2.1

In this tutorial, we will see how to prevent a Ticket to be transitioned by someone else than the agent, its manager or an Administrator.

For this we will use a callback on an Event EVENT_ENUM_TRANSITIONS

  • We get the agent Person
  • Check if we are in a situation where transitions should be hidden:
    • The id of the Current Connected Person (UserRights::GetContactId()) is neither the agent_id nor its manager_id
    • The current user is not an iTop Administrator (!UserRights::IsAdministrator())
    • The Ticket is “Assigned” or “Pending”
  • Then:
    • Remove the stimulus which which should be limited with $this→DenyTransition($sStimulusCode)
    • You can hide a stimulus which is not present, it has no effect
itop_design version="3.2"
  <classes>
     <class id="UserRequest">
      <event_listeners>
        <event_listener id="HideTransitionsIfNotAgent" _delta="define">
          <event>EVENT_ENUM_TRANSITIONS</event>
          <rank>10</rank>
          <callback>HideTransitionsIfNotAgent</callback>
        </event_listener>
      </event_listeners>
      <methods>
        <method id="HideTransitionsIfNotAgent" _delta="define">
          <comment>/**
            * If the current user is neither the agent, nor their manager
            * And if the current user is not an Administrator
            * And if the UserRequest is in some states
            * Then hide some transitions
            */</comment>
          <static>false</static>
          <access>public </access>
          <code><![CDATA[public function HideTransitionsIfNotAgent(Combodo\iTop\Service\Events\EventData $oEventData)....
class:UserRequest
  public function HideTransitionsIfNotAgent(Combodo\iTop\Service\Events\EventData $oEventData)
  {
      $iAgent = $this->Get('agent_id');
      if ($iAgent > 0) {
          $oAgent = MetaModel::GetObject('Person', $iAgent, true, true);
          $iManager = $oAgent->get('manager_id');
          $iCurrentPerson = UserRights::GetContactId();
 
          if ( (!in_array($iCurrentPerson, [$iAgent, $iManager]) && !UserRights::IsAdministrator())
          && ( in_array($this->Get('status'), ['assigned', 'pending'])) {
              $this->DenyTransition('ev_pending');
              $this->DenyTransition('ev_resolve');
          }
      }
  }
You can only remove a transition. It's impossible to add a transition on the fly!
3_2_0/customization/hide-transition.txt · Last modified: 2025/11/18 18:05 by 127.0.0.1
Back to top
Contact us