Fix a bug in second degree permssions where the a_b, b_a combination was mishandled
authorAidan Saunders <aidan.saunders@squiffle.uk>
Wed, 4 Jul 2018 11:04:10 +0000 (12:04 +0100)
committerAidan Saunders <aidan.saunders@squiffle.uk>
Wed, 4 Jul 2018 11:34:10 +0000 (12:34 +0100)
We need to check for:
  first_degree_relationship.contact_id_a = second_degree_relationship.contact_id_a
  first_degree_relationship.contact_id_a = second_degree_relationship.contact_id_b
  first_degree_relationship.contact_id_b = second_degree_relationship.contact_id_a
  first_degree_relationship.contact_id_b = second_degree_relationship.contact_id_b
but the last one was mishandled.

CRM/Contact/BAO/Contact/Permission.php

index 883b39922f82456ea03d4dfb1f56aeca98973b5e..c8ddb50a1ff4b2ba0d0ed776d52049af5bb0c29a 100644 (file)
@@ -354,7 +354,7 @@ AND ac.user_id IS NULL
     $queries = array();
     $contact_id_list = implode(',', $contact_ids);
 
-    // add a select statement for each direection
+    // add a select statement for each direction
     $directions = array(array('from' => 'a', 'to' => 'b'), array('from' => 'b', 'to' => 'a'));
 
     // CRM_Core_Permission::VIEW is satisfied by either CRM_Contact_BAO_Relationship::VIEW or CRM_Contact_BAO_Relationship::EDIT
@@ -402,7 +402,7 @@ SELECT civicrm_relationship.{$contact_id_column} AS contact_id
           $queries[] = "
 SELECT second_degree_relationship.contact_id_{$second_direction['to']} AS contact_id
   FROM civicrm_relationship first_degree_relationship
-  LEFT JOIN civicrm_relationship second_degree_relationship ON first_degree_relationship.contact_id_{$first_direction['to']} = second_degree_relationship.contact_id_{$first_direction['from']}
+  LEFT JOIN civicrm_relationship second_degree_relationship ON first_degree_relationship.contact_id_{$first_direction['to']} = second_degree_relationship.contact_id_{$second_direction['from']}
   {$LEFT_JOIN_DELETED}
  WHERE first_degree_relationship.contact_id_{$first_direction['from']} = {$contactID}
    AND second_degree_relationship.contact_id_{$second_direction['to']} IN ({$contact_id_list})