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) »
  • Restrict ability to manually add/remove contacts from smart groups
Pages: [1]

Author Topic: Restrict ability to manually add/remove contacts from smart groups  (Read 1266 times)

idmacdonald

  • I post occasionally
  • **
  • Posts: 69
  • Karma: 1
Restrict ability to manually add/remove contacts from smart groups
March 20, 2013, 11:16:50 am
Hi,

I am building a membership database for a client that is using quite a few Smart Groups for various categories of organisations and people. The client has complained that it is confusing to have all the smart groups appear in the 'Add to group' menu on the Groups tab for a contact. It's the same for the list of groups that comes up when one selects 'Add contacts to group' from the actions menu.

Given the number of smart groups that they have and the fact that users of the system won't have a reason to manually add or remove contacts from smart groups, I'd like to just remove the smart groups from those menus.

I thought that the way to do this would be with hook_civicrm_aclGroup, but while I can use that function to restrict the lists of groups that people see in the 'Add to group' menu, doing so also removes those groups from the menu on the basic search form. I'd like most users to be able to view all smart groups, but not manually add or remove contacts from them. I'd prefer to also prevent most users from changing the smart group criteria. However the $type variable in hook_civicrm_aclGroup doesn't seem to work as I expect... I seem to be able to remove all reference to smart groups across the installation, but not make the smart groups 'read only'. Note that I don't want to make the contacts which are members of the smart group read only, I just don't want most users to be able to change the smart group criteria or manually add or remove contacts from them.


Is hook_civicrm_aclGroup the right way to do this? Or am I missing something? Here's my code:

Code: [Select]
function mycrm_civicrm_aclGroup( $type, $contactID, $tableName, &$allGroups, &$currentGroups ) {

    if ($tableName != 'civicrm_saved_search') {
        // this hook (according to the docs) also runs for events and profiles, but we only need it for groups
        return;
    }
    // here I've tried for only type 1, type 2 or both
    if ($type == '1') {
      //I use the API to get an array of all smart group IDs, which I'm excluding for simplicity
      $smart_groups = array('1', '2', '3')
      foreach ($smart_groups as $gid) {
        if ( FALSE !== $index = array_search($gid, $currentGroups) ) {
          unset($currentGroups[$index]);
        }
      }
    }
}       

I have a feeling that this might be the wrong approach, but maybe this should work and there's some bug I'm missing??

Thanks,
-Ian

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: Restrict ability to manually add/remove contacts from smart groups
March 20, 2013, 12:12:01 pm
I dont think you should use aclGroups (that will cause other unforeseen consequences)

Seems like the easiest option might be to add a hook in the pseudoconstant stuff (CRM/Core/PseudoConstant.php) so an external module can alter the stuff as needed

For the short term you should be able to also do this via a buildForm hook and replace the select element with a new select element with a smaller number of groups

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

FatherShawn

  • Ask me questions
  • ****
  • Posts: 372
  • Karma: 25
    • C3 Design
  • CiviCRM version: 4.2.11
  • CMS version: Drupal 7.23
  • MySQL version: 5.5.32
  • PHP version: 5.3.10
Re: Restrict ability to manually add/remove contacts from smart groups
May 31, 2013, 09:16:29 am
I'm having users confused about the same "feature" and found this thread looking to see if or how others had dealt with it. 

I'm having a hard time seeing a use case where it would be desirable to manually add a contact to a smart group.  It seems to me that doing so undermines the dynamic nature of the saved search - it puts a fixed point into the data set.  Am I missing something?
Lead Developer, C3 Design.
Twitter: @FatherShawn

FatherShawn

  • Ask me questions
  • ****
  • Posts: 372
  • Karma: 25
    • C3 Design
  • CiviCRM version: 4.2.11
  • CMS version: Drupal 7.23
  • MySQL version: 5.5.32
  • PHP version: 5.3.10
Re: Restrict ability to manually add/remove contacts from smart groups
May 31, 2013, 09:19:57 am
OK - found this thread which gives some valid use cases:

http://forum.civicrm.org/index.php/topic,8358.msg39742.html#msg39742
Lead Developer, C3 Design.
Twitter: @FatherShawn

ChrisChinchilla

  • I post occasionally
  • **
  • Posts: 104
  • Karma: 3
  • CiviCRM version: 4.1.2
  • CMS version: Drupal 6 & 7
Re: Restrict ability to manually add/remove contacts from smart groups
June 30, 2013, 06:44:49 pm
Hey all,

Had a client today with the same concern and can't believe I never noticed it before as it does seem odd.

How did you go with solving this? Need any help?
Melbourne CiviCRM meetup group - http://www.meetup.com/MelbourneCiviCRM/

ChrisChinchilla

  • I post occasionally
  • **
  • Posts: 104
  • Karma: 3
  • CiviCRM version: 4.1.2
  • CMS version: Drupal 6 & 7
Re: Restrict ability to manually add/remove contacts from smart groups
June 30, 2013, 06:49:53 pm
I wonder as a compromise…

Would it be possible to add a search filter to the smart group criteria to only show those added by the 'normal' smart group process and not those 'added' or 'pending'?
Melbourne CiviCRM meetup group - http://www.meetup.com/MelbourneCiviCRM/

FatherShawn

  • Ask me questions
  • ****
  • Posts: 372
  • Karma: 25
    • C3 Design
  • CiviCRM version: 4.2.11
  • CMS version: Drupal 7.23
  • MySQL version: 5.5.32
  • PHP version: 5.3.10
Re: Restrict ability to manually add/remove contacts from smart groups
July 01, 2013, 07:04:14 am
Well, I've searched the code base for all the forms that call addContactsToGroup and I'm writing a module with a custom permission that removes smart groups from these lists.  While I'm at it I'm also throwing in a permission to do the same for ACL groups.  I don't want to generally restrict my staff from editing in Civi but I do want to restrict their ability to edit in these groups... 

I'm planning to put the code up on drupal.org when it's finished...
Lead Developer, C3 Design.
Twitter: @FatherShawn

ChrisChinchilla

  • I post occasionally
  • **
  • Posts: 104
  • Karma: 3
  • CiviCRM version: 4.1.2
  • CMS version: Drupal 6 & 7
Re: Restrict ability to manually add/remove contacts from smart groups
July 01, 2013, 11:06:16 pm
OK thanks.

I guess it does work 'as designed', but it also can be a strange behaviour for users who don't get it. Permissions would be the right way to go. Keep me posted.
Melbourne CiviCRM meetup group - http://www.meetup.com/MelbourneCiviCRM/

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Restrict ability to manually add/remove contacts from smart groups

This forum was archived on 2017-11-26.