How to write business rule to restrict the visibility access to records for users depending on roles

Sai_snow
Tera Contributor

I created a new user role called "user_admin." This role should be checked when granting elevated privileges. Data should only be accessible to users with this new role, while others should be denied access. For example if there are 2 admins one with user_data role should have the access when he elevate the role to security_admin and other without the role should not get the access when he elevate to security_admin. Can someone help me to correct the below BR?

 

var source = 'Test';
var user = gs.getUser();
var queryFilterUtils = new queryFilteringUtils(user);

if (!gs.hasRole("itil") && !gs.hasRole("security_admin") && !gs.hasRole("itil_admin") && gs.isInteractive()) {
gs.log(user.getDisplayName() + ' is a customer', source);

current.addEncodedQuery(
queryFilterUtils.getTaskEncodedQueryForCustomer());

} else if (!gs.hasRole("security_admin"))

current.addEncodedQuery(
queryFilterUtils.getTaskEncodedQueryForItil());

} else {
gs.log(user.getDisplayName() + ' is an admin', source);
}

2 REPLIES 2

Michael183
Tera Guru

Try to use gs.hasRoleExactly('') because gs.hasRole is bypass by admin role meaning that if you have admin it will always be true


If that doesn't make difference you can try to put the encodedQuery directly on the business rule rather than on a script include

Hello Mechael
It doesn't work when i use gs.hasRoleExactly('')