Skip to content

Commit

Permalink
CRM-12645 fix the code that calls the links function to not whomp it.
Browse files Browse the repository at this point in the history
Also, index rows by id so array_keys is useful
  • Loading branch information
eileenmcnaughton committed Oct 13, 2016
1 parent cfa11d4 commit 6819ba0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 29 deletions.
1 change: 1 addition & 0 deletions CRM/Contact/BAO/Contact/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public static function allowList($contact_ids, $type = CRM_Core_Permission::VIEW
// if some have been rejected, double check for permissions inherited by relationship
if (count($result_set) < count($contact_ids)) {
$rejected_contacts = array_diff_key($contact_ids, $result_set);
// @todo consider storing these to the acl cache for next time, since we have fetched.
$allowed_by_relationship = self::relationshipList($rejected_contacts);
foreach ($allowed_by_relationship as $contact_id) {
$result_set[(int) $contact_id] = TRUE;
Expand Down
43 changes: 14 additions & 29 deletions CRM/Contact/Selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,6 @@ public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
);
}

$seenIDs = array();
while ($result->fetch()) {
$row = array();
$this->_query->convertToPseudoNames($result);
Expand Down Expand Up @@ -836,16 +835,13 @@ public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
$row['contact_sub_type'] = $result->contact_sub_type ? CRM_Contact_BAO_ContactType::contactTypePairs(FALSE, $result->contact_sub_type, ', ') : $result->contact_sub_type;
$row['contact_id'] = $result->contact_id;
$row['sort_name'] = $result->sort_name;
// Surely this if should be if NOT - otherwise it's just wierd.
if (array_key_exists('id', $row)) {
$row['id'] = $result->contact_id;
}
}

// Dedupe contacts
if (in_array($row['contact_id'], $seenIDs) === FALSE) {
$seenIDs[] = $row['contact_id'];
$rows[] = $row;
}
$rows[$row['contact_id']] = $row;
}

return $rows;
Expand Down Expand Up @@ -918,20 +914,25 @@ public function addActions(&$rows) {
$permissions[] = CRM_Core_Permission::DELETE;
}
$mask = CRM_Core_Action::mask($permissions);
// mask value to hide map link if there are not lat/long
$mapMask = $mask & 4095;

// get permissions on an individual level (CRM-12645)
// @todo look at storing this to the session as this is called twice during search results render.
$can_edit_list = CRM_Contact_BAO_Contact_Permission::allowList(array_keys($rows), CRM_Core_Permission::EDIT);

$links_template = self::links($this->_context, $this->_contextMenu, $this->_key);

foreach ($rows as $id => & $row) {
$links = $links_template;

// remove edit/view links (CRM-12645)
if (isset($links[CRM_Core_Action::UPDATE]) && !in_array($id, $can_edit_list)) {
unset($links[CRM_Core_Action::UPDATE]);
$rowMask = $mask;
if (($mask ^ CRM_Core_Action::UPDATE) && (in_array($id, $can_edit_list))) {
$rowMask += CRM_Core_Action::UPDATE;
}
if ((!is_numeric(CRM_Utils_Array::value('geo_code_1', $row))) &&
(empty($row['city']) ||
!CRM_Utils_Array::value('state_province', $row)
)
) {
$rowMask = $rowMask & 4095;
}

if (!empty($this->_formValues['deleted_contacts']) && CRM_Core_Permission::check('access deleted contacts')
Expand Down Expand Up @@ -970,26 +971,10 @@ public function addActions(&$rows) {
$row['contact_id']
);
}
elseif ((is_numeric(CRM_Utils_Array::value('geo_code_1', $row))) ||
(!empty($row['city']) &&
CRM_Utils_Array::value('state_province', $row)
)
) {
$row['action'] = CRM_Core_Action::formLink(
$links,
$mask,
array('id' => $row['contact_id']),
ts('more'),
FALSE,
'contact.selector.actions',
'Contact',
$row['contact_id']
);
}
else {
$row['action'] = CRM_Core_Action::formLink(
$links,
$mapMask,
$rowMask,
array('id' => $row['contact_id']),
ts('more'),
FALSE,
Expand Down

0 comments on commit 6819ba0

Please sign in to comment.