Question

Hide add records button based on user role

Hi Community,

 

Any idea how can I hide the edit pages in add records button (please refer to capture below) in section? I want to hide these items based on current user role.

 

Many thanks.

Like 0

Like

5 comments

Hello,

 

Unfortunately, as for now, there is no functionality of setting access rights for particular edit pages, but there is a solution that can fit your needs: you can dynamically change access rights to records that are created and distribute rights for specific records to specific system users or roles.



For example, you can create opportunities based on their type. Let it be "Partner sale" or "Customer sale".



So edit pages are opened based on the type of opportunity. So you want "Partners" org.role be able to see "Partner sale" opportunities and "All employees" org.role be able to see "Customer sale".  To do so you need to create two separate business processes that will be triggered on the record adding to the opportunities section and you need to specify filtering conditions based on the type of this record. So it will be a "Signal" element with the "Opportunity" object with filtering conditions set for the "Type" field.



The next element will be the "Change access rights" element that will edit access rights for this created record (if record type is "Partner sale" then "Partners" org.role receives needed access rights, if record type is "Customer sale" then "All employees" org.role receives needed access rights). You need to remove access rights for all users and roles and after that add access rights for the specific role for which you need these access rights. And the last element will be "Terminate".

 

Hello Bogdan,

 

Basically , we need to display the list of edit pages based on user roles.

 

Below is my code:

define("CaseSection", ["VisaHelper", "ConfigurationConstants", "BaseFiltersGenerateModule", "css!UsrCaseCss"], function(VisaHelper, ConfigurationConstants, BaseFiltersGenerateModule) {
    return {
        entitySchemaName: "Case",
        details: /**SCHEMA_DETAILS*/{}/**SCHEMA_DETAILS*/,
        attributes:{
 
              "IsSysAdmin": {
                "dataValueType": this.Terrasoft.DataValueType.BOOLEAN,
                "type": this.Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN,
                  "value": false
 
            },
                "IsNursesRole": {
                "dataValueType": this.Terrasoft.DataValueType.BOOLEAN,
                "type": this.Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN,
                    "value": false
            },
            "IsITRoles":{
                "dataValueType": this.Terrasoft.DataValueType.BOOLEAN,
                "type": this.Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN,
                "value": false
            },
 
            "IsParcAutoRoles":{
                "dataValueType": this.Terrasoft.DataValueType.BOOLEAN,
                "type": this.Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN,
				"value": false
            },
},
        diff: /**SCHEMA_DIFF*/[
             {
                    "operation": "merge",
                    "name": "SeparateModeAddRecordButton",
                    "parentName": "SeparateModeActionButtonsLeftContainer",
                    "propertyName": "items",
                    "values": {
                        "controlConfig": {
                            "menu": {
                                "items": {
                                    "bindTo": "EnabledEditPages",
                                    "bindConfig": {
                                        "converter": function(editPages) {
                                            if (editPages.getCount() >= 1) {
                                                return editPages;
                                            } else {
                                                return null;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                },
                {
                    "operation": "merge",
                    "name": "CombinedModeAddRecordButton",
                    "parentName": "CombinedModeActionButtonsSectionContainer",
                    "propertyName": "items",
                    "values": {
                        "controlConfig": {
                            "menu": {
                                "items": {
                                    "bindTo": "EnabledEditPages",
                                    "bindConfig": {
                                        "converter": function(editPages) {
                                            var result;
                                            if (editPages.getCount() >= 1) {
                                                return editPages;
                                            } else {
                                                return null;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
        ]/**SCHEMA_DIFF*/,
 
methods: {
                    init: function() {
                        this.callParent(arguments);
// Role 1
                        var esq = Ext.create("Terrasoft.EntitySchemaQuery", {
                            rootSchemaName: "SysUserInRole"
                            });
                            esq.addColumn("SysRole");
 
                            esq.filters.add("UserFilter", Terrasoft.createColumnFilterWithParameter(
                                Terrasoft.ComparisonType.EQUAL, "SysUser", Terrasoft.SysValue.CURRENT_USER.value
                            ));
                              var esqAdminRole = esq.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "SysRole", "83A43EBC-F36B-1410-298D-001E8C82BCAD");
                             esq.filters.add("esqAdminRole", esqAdminRole);
                             esq.getEntityCollection(function(response) {
                                 if (response && response.success) {
                                   var result = response.collection;
                                   var isSysAdmin = (result.collection.length !== 0);
                                   this.set("isSysAdmin", isSysAdmin);
                                 }                           
                            }, this);
 
// Role 2              
                            var NursesCB = "Nurses CB";
                            var NursesCR = "Nurses CR";
                            var esqWellness = Ext.create("Terrasoft.EntitySchemaQuery", {
                            rootSchemaName: "SysUserInRole"
                            });
                            esqWellness.addColumn("SysRole");
 
                            esqWellness.filters.add("UserFilter", Terrasoft.createColumnFilterWithParameter(
                                Terrasoft.ComparisonType.EQUAL, "SysUser", Terrasoft.SysValue.CURRENT_USER.value
                            ));
                             var esqNursesCBRole = esqWellness.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "SysRole.Name", NursesCB);
                              var esqNursesCRRole = esqWellness.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "SysRole.Name", NursesCR);
                             esqWellness.filters.logicalOperation = Terrasoft.LogicalOperatorType.OR;
                            esqWellness.filters.add("esqNursesCBRole", esqNursesCBRole);
                              esqWellness.filters.add("esqNursesCRRole", esqNursesCRRole);
                             esqWellness.getEntityCollection(function(response) {
                                 if (response && response.success) {
                                   var result2 = response.collection;
                                   var IsNursesRole = (result2.collection.length !== 0);
                                   this.set("IsNursesRole", IsNursesRole);
 
                                 }
 
                            }, this);
 
// Role 3        
                            var ITCB ="IT CB";
                            var Support = "SAP Support";
                            var esq2 = Ext.create("Terrasoft.EntitySchemaQuery", {
                            rootSchemaName: "SysUserInRole"
                            });
                            esq2.addColumn("SysRole");
 
                            esq2.filters.add("UserFilter", Terrasoft.createColumnFilterWithParameter(
                                Terrasoft.ComparisonType.EQUAL, "SysUser", Terrasoft.SysValue.CURRENT_USER.value
                            ));
 
                              var esqITCBRole = esq2.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "SysRole.Name", ITCB);
                              var esqSAPSupportRole = esq2.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "SysRole.Name", Support);
 
                              esq2.filters.logicalOperation = Terrasoft.LogicalOperatorType.OR;
                            esq2.filters.add("esqITCBRole", esqITCBRole);
                              esq2.filters.add("esqSAPSupportRole", esqSAPSupportRole);
 
 
                            esq2.getEntityCollection(function(response) {
                                if (response && response.success) {
                                   var result3 = response.collection;
                                   var IsITRoles = (result3.collection.length !== 0);
                                   this.set("IsITRoles", IsITRoles);
 
                                 }
 
                            }, this);
 
// Role 4
                            var managerCB = "Parc Auto Manager BG";
                            var managerCR = "Parc Auto Manager CR";
                              var esqAuto = Ext.create("Terrasoft.EntitySchemaQuery", {
                            rootSchemaName: "SysUserInRole"
                            });
                            esqAuto.addColumn("SysRole");
 
                            esqAuto.filters.add("UserFilter", Terrasoft.createColumnFilterWithParameter(
                                Terrasoft.ComparisonType.EQUAL, "SysUser", Terrasoft.SysValue.CURRENT_USER.value
                            ));
 
                              var esqParcAutoManagerBGRole = esqAuto.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "SysRole.Name", managerCB);
                              var esqParcAutoManagerCRRole = esqAuto.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "SysRole.Name", managerCR);
                            esqAuto.filters.logicalOperation = Terrasoft.LogicalOperatorType.OR;
                            esqAuto.filters.add("esqParcAutoManagerBGRole", esqParcAutoManagerBGRole);
                              esqAuto.filters.add("esqParcAutoManagerCRRole", esqParcAutoManagerCRRole);
                              esqAuto.getEntityCollection(function(response) {
                                if (response && response.success) {
                                   var result4 = response.collection;
                                   var IsParcAutoRoles = (result4.collection.length !== 0);
                                  this.set("IsParcAutoRoles", IsParcAutoRoles);     
                                 }                                     
                            }, this);              
                    },
 
                 initEditPages: function() {
                            var enabledEditPages = new this.Terrasoft.Collection();
                            this.callParent(arguments);
                            var editPages = this.get("EditPages");
                            var items = editPages.getItems();
 
 
// Display edit pages        
                                 if(this.get("IsSysAdmin") === true) { 
                                     for (var j = 0; j<items.length; j++) {
                                        if (items[j].values.Id === "001981a9-ebe5-4e05-8f91-294afc96f1b9" || items[j].values.Id === "b76ffe56-fcc2-4df0-b323-7893e4b22710" || items[j].values.Id === "8c19c5f0-8f20-4dd1-b499-548220e9e42f" || items[j].values.Id ==="d64a4837-a7ae-4a25-af00-aa6ea7c7787e" || items[j].values.Id ==="3ee4ed5c-fd03-46b0-b057-4db4dd05956b" || items[j].values.Id ==="9ccfc65c-3cfc-4ead-b47f-97a9257963a2" || items[j].values.Id ==="66c5de92-8649-4f13-bf5d-da3df5d222c4"|| items[j].values.Id ==="22170d13-4f8a-4d6a-9bc0-91f63a362a89") {
                                               enabledEditPages.add(items[j]);
                                        }                        
                                    }
                                     this.set("EnabledEditPages", enabledEditPages);    
                                }
 
                                 else if (this.get("IsNursesRole") === true ){
                                     for (var i = 0; i<items.length; i++) {
                                        if (items[i].values.Id === "8c19c5f0-8f20-4dd1-b499-548220e9e42f" || items[i].values.Id === "b76ffe56-fcc2-4df0-b323-7893e4b22710") {
                                               enabledEditPages.add(items[i]);
                                        }                        
                                    }
                                     this.set("EnabledEditPages", enabledEditPages);
                                }
 
 
                                 else if(this.get("IsITRoles") === true ){
                                     for (var k = 0; k<items.length; k++) {
                                        if (items[k].values.Id === "001981a9-ebe5-4e05-8f91-294afc96f1b9") {
                                               enabledEditPages.add(items[k]);
                                        }                        
                                    }
                                     this.set("EnabledEditPages", enabledEditPages);
                                }
 
                                 else if (this.get("IsParcAutoRoles") === true){
                                     for (var q = 0; q<items.length; q++) {
                                        if (items[q].values.Id === "9ccfc65c-3cfc-4ead-b47f-97a9257963a2") {
                                               enabledEditPages.add(items[q]);
                                        }                        
                                    }
                                     this.set("EnabledEditPages", enabledEditPages);
                                }
 
 
                                  else{
                                    this.set("EnabledEditPages", null);
 
                                 }
 
              },
 
        }
    };
});

 

But it deosn't work correctly, Is there anything wrong?

 

Best Regards.

Mouna RACHIDI,

 

Hello,

 

The issue is that regular users (non-admins) won't have access to objects like SysAdminUnitInRole or SysUserInRole or SysUser etc. It can be seen when sending requests from a regular user. I could only propose to create a backend service and call it from the client-side when forming a list (using ServiceHelper.callService) that would return set of Ids of edit pages based on the user that called the service.

 

Please use the approach proposed by Bogdan to control edit pages visibility in the grid (unfortunately it won't allow hiding the list of available edit pages, but at least you can control the list of displayed records in the section).

Oleg Drobina,

 

Thank you soo much for all your help.

 

Could you please give me the table name of edit pages to get the set of Ids ?

 

Best Regards.

 

 

 

+1 for this functionality

Show all comments