CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Access Restriction to tasks in the action pull-down
Pages: [1]

Author Topic: Access Restriction to tasks in the action pull-down  (Read 1063 times)

axlroach

  • I’m new here
  • *
  • Posts: 22
  • Karma: 0
Access Restriction to tasks in the action pull-down
July 01, 2009, 03:58:40 pm
Hi all,

I have several actions in the contact search dropdown, and I'd like to be able to restrict access for many of those tasks to certain users or groups of users.

Now, since I have a custom drupal module, I could define hook_perm() and then, I know that I could limit access to these tasks quite easily by modifying the CRM/Contact/Task.php file in the following way:

Code: [Select]
// For each task that I want to restrict access on, I would wrap it like so:
if (user_access('PERMISSION TO DO SOME TASK')) {   // This permission is defined in hook_perm() of my custom drupal module
  self::$_tasks['4096'] = array( 'title' => ts( 'Some Task' ),
                                             'class' => 'CRM_Contact_Form_Task_SomeTask',
                                             'result' => true );
}

Now of course the action would only show up in the dropdown if the user had the proper permission.  I've already modified the Task.php file to create custom actions as per the instructions at http://wiki.civicrm.org/confluence/display/CRMDOC/How+to+Add+Actions+to+the+Contact+Search+Dropdown

My question is this:  Is further hacking the Task.php file in order to impose access restriction best practice?  I'm wondering if there isn't a better and cleaner way to accomplish the same thing.  I can't seem to find any documentation about restricting tasks with civicrm's ACL though -- just groups, profiles, custom data and events. 

If this is the best and most logical way to solve this problem, then great!  I figured it out.  But if there is a better solution it'd be great if someone could share that knowledge here on the forum.

Thanks!
aj

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Access Restriction to tasks in the action pull-down
July 01, 2009, 08:15:15 pm

you should be able to accomplish this via the hook_civicrm_searchTasks

check:

http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+hook+specification#CiviCRMhookspecification-hookcivicrmsearchTasks

there is an example implementation in civitest.module.sample

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Access Restriction to tasks in the action pull-down

This forum was archived on 2017-11-26.