Details
-
Type:
Bug
-
Status: Done/Fixed
-
Priority:
Major
-
Resolution: Fixed/Completed
-
Affects Version/s: 4.1.2
-
Fix Version/s: 4.1.3
-
Component/s: Drupal Integration Modules
-
Labels:None
Description
In my testing on a Civi 4.1.2 / Drupal 7 site, CiviGroup Roles Sync fails to sync roles to groups in each of the following scenarios:
1. Create user at /admin/people/create
2. Add role to user at /user/N/edit
3. Remove role from user at /user/N/edit
I investigated and found that this was due to multiple bugs in civicrm_group_roles.module, mostly due to code having been only partially adapted for API v3 & D7 db calls & D7 forms, so left in a non-working state.
The attached patch gets it working in the above scenarios in my testing. I took the approach of only changing what was needed to get it working; there are parts that could probably be cleaned up but I was reluctant to change without understanding the rationale for the way they were done, e.g.
a. The test for module_exists('content_profile') in civicrm_group_roles_form_alter: I left this but added a rather speculative '|| isset( $form['account'] )' - I found that /user/N/edit (with or without a Civi profile in the edit form and without module content_profile) had form id 'user-profile-form', so I somewhat arbitrarily broadened the test to succeed for form id 'user-profile-form' provided $form['account'] is set.
b. Could / should civicrm_group_roles_add_remove_groups use CRM_Core_BAO_UFMatch::getContactId() instead of API?
I added an update function to change the module weight, as I found that otherwise, with the default 0 vs civicrm's 100, CRM_Core_BAO_UFMatch::getContactId() returned nothing in civicrm_group_roles_add_groups_oncreate() (called from civicrm_group_roles_user_insert() ).