Advanced Configuration of CMDB Grids
In Deepser you can define a custom script that allows you to specify advanced conditions for the collection of us to be displayed.
Example 1
In this case we suppose we want to make visible only to some End-users all the categories of the CMDB, all the others we want to display only on the CI of class 1 (Location).
To do this, we must go to the menu: System -> Portal -> CI.
Here, we will have to click on the pencil-shaped button.
Now the following screen will open:
In the “Prepared Collection Script” section, we are going to insert the following code:
//Array of technicians, who can see all the cis
$technicians = ['deepser_tec','mario.rossi'];
//if the current user is not in the technicians array he or she colud only see cis with class_id 1
if((!is_null($technicians) && is_array($technicians)) && (!(in_array(Deep::helper('deep_admin')->getCurrentUser()->getUsername(),$technicians)))){
$this->getCollection()->addFieldToFilter('class_id', [ "eq" => 1 ]);
}
Note: that the array technicians contain the usernames of the users and not the Display usernames.
Once this is done, you will need to click on the “Save” button to save the changes.
Example 2
In this case we suppose we want to make visible only to some End-users all the categories of the CMDB, all the others we want to have visibility only on the class 1 CI (Location), compared to the previous case in this case we are going to define a custom field of checkbox type that will allow you to define in a simpler way which users will be able to view all the ci.
To create the custom field, we must go to the menu: System -> Custom Fields
Here we will have to go in user model.
At this point in the “Fields” section, we are going to click on the “Add Field” button.
Now the following screen will open:
Here we are going to define the “Code” field as “is_cmdb_technician”.
The “Label” field will instead be “Is Technicians”.
Now, we configure “Column type” as “Integer”.
At this point, we define the “Element Type” field as “Checkbox”.
As a last step, going to the “extra” tab we set the flag: “Render as Toggle” to “Yes”.
At the end, click on the “Save” button to save the custom field.
At this point, it will be necessary to insert the newly created field in the users’ template form, and we will enhance it for those users who will have to see all the CI.
Now to implement the actual filter, we must go to the menu: System -> Portal -> CI.
Here, we will have to click on the pencil-shaped button.
Now the following screen will open:
In the “Prepared Collection Script” section, we are going to insert the following code:
$userArray = Deep::getResourceModel('deep_admin/user_collection')->addFieldToFilter('cust_is_cmdb_technician',[ ["neq" => 1], ['null' => true]]);
$userlist = [];
foreach($userArray as $user){
$userlist[$user->getUsername()] = $user->getDisplayUsername();
}
if(( !is_null($userlist) && is_array($userlist)) && (array_key_exists(Deep::helper('deep_admin')->getCurrentUser()->getUsername(),$userlist))){
$this->getCollection()->addFieldToFilter('class_id',["eq" =>1]);
}
Once this is done, you will need to click on the “Save” button to save the changes.