2

There are several instances where I want to remove some buttons, inputs, tabs, etc on various screens for non-admin users. For instance, on the Event Search screen in this template

CRM/Event/Form/Search.extra.tpl I have

<script>
{literal}
//remove smart group creation
CRM.$(function remove_smart_group_creation($) {
 $('#task option[value=12]').remove();
});

//remove group add contacts
CRM.$(function remove_group_add_contacts($) {
 $('#task option[value=2]').remove();
});

//remove delete participants
CRM.$(function remove_delete_participants($) {
 $('#task option[value=4]').remove();
});
</script>
{/literal}

How could I exempt the administrator role?

2

Are they in the administrators group? Since then you might be able to do something like (untested):

CRM.api3('GroupContact', 'get', {
  "contact_id": "user_contact_id", // use this exact string to mean current user
  "group_id": "Administrators"
}).then(function(result) {
  if (result.count == 0) {
    // Not in the admin group
    // ** do your removal stuff here **
  }
});

There is also CRM.checkPerm() to check a CMS permission. See e.g. https://github.com/civicrm/civicrm-core/blob/5.18.4/templates/CRM/Tag/Page/Tag.tpl#L123, e.g. CRM.checkPerm('administer reserved tags')

if (!CRM.checkPerm("administer CiviCRM")) {
  // do your removal stuff
}
| improve this answer | |
  • I am not familiar with the administrators group. It says 0 records are in it. But I tested with both admin and non-admin roles and it did not apply my jQuery. – Andy Burns Oct 24 '19 at 1:48
  • Oh ok. Do you mean administrator role in the CMS (e.g. Drupal)? Or a civi ACL maybe? – Demerit Oct 24 '19 at 1:49
  • I mean the administrator role in WP, not using ACL's. Using that group method would be fine but I worry that users could somehow add to that group? Seems like an obvious loophole. That group is only for ACL usage I assume. Alternatively, I have 4 non-admin user civi groups that all non-admins get put into I could apply the code to. – Andy Burns Oct 24 '19 at 1:54
  • I updated answer to include CRM.checkPerm(), to check a CMS permission. – Demerit Oct 24 '19 at 2:03
  • Sorry, I am not able to put that all together... – Andy Burns Oct 24 '19 at 2:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.