View Rules with Roles
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-01-2013 02:03 PM
Hi All,
I wanted to share / get feedback on my solution to allow us to assign roles to view rules.
We had situations where we only wanted view rules to apply to certain roles and we wanted none of them to affect Admins.
My solution was to add a roles field to the view rules and create a before query business rule which restricts access to the view rules thus disabling them from applying to views for people without those roles, the condition disables this from happening when viewing the list of view rules so none are hidden.
- Rules apply to anyone with any of the roles (follows normal rule order if multiple)
- If no roles it applies to everyone (but admins)
- Rules do not apply to admins, even if they specify
Add a Field
Column name: Roles
Type: glide_list
Reference: sys_user_role
(I know you're supposed to use the personalize form to add a column, but Roles wasn't showing in the 'Table to reference' list)
New Business Rule
Name: View Rules w Roles
Table: View Rule [sysrule_view]
Client callable: false
When: before
Insert: false
Upate: false
Delete: false
Query: true
Condition:
gs.action.getGlideURI().toString().indexOf('sysrule_view') != 0
Script:
FilterViewRules();
function FilterViewRules() {
var IDs = '';
if(!gs.hasRole('admin')) {
var vr = new GlideRecord('sysrule_view');
vr.addQuery('u_roles', '!=', 'NULL');
vr.setWorkflow(false); // Don't run workflows
vr.query();
while(vr.next()) {
var roles = vr.getDisplayValue('u_roles');
if(gs.hasRole(roles)) {
IDs += ',' + vr.sys_id;
}
}
}
var cond = current.addQuery('sys_id', 'IN', IDs);
cond.addOrCondition('u_roles', '=', 'NULL');
}
It would also be really easy to add an "Admin Overrides" checkbox also like the ACLs have, I didn't need it for my solution.
If anyone has a better solution / tweaks to make this better please share.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2014 01:48 PM
This is great! I have been looking for Admin Override on View Rules for some time now. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2014 01:59 PM
Glad to hear it! Always happy to help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2016 12:30 PM
Hi Shane- I tried this but it ends up corrupting the View Rule. Each time the "current.addQuery" line ran, it disabled the view rule entirely. I couldn't get it to run again until I deleted it and re-created it. Did you have this issue at all? I'm trying to implement an admin override for View Rules.
thanks,
Lou