Skip to content

Commit

Permalink
Merge pull request #9544 from colemanw/CRM-19773
Browse files Browse the repository at this point in the history
CRM-19773 - Call hook_civicrm_selectWhereClause when checking event permissions
  • Loading branch information
colemanw authored Apr 19, 2017
2 parents 9a4de61 + 5836c35 commit 11243f3
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 27 deletions.
5 changes: 5 additions & 0 deletions CRM/Core/PseudoConstant.php
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ public static function populate(
return $var;
}

/* @var CRM_Core_DAO $object */
$object = new $name();

$object->selectAdd();
Expand All @@ -565,6 +566,10 @@ public static function populate(

if (!$all) {
$object->$filter = 1;
$aclClauses = array_filter($name::getSelectWhereClause());
foreach ($aclClauses as $clause) {
$object->whereAdd($clause);
}
}

$object->find();
Expand Down
66 changes: 41 additions & 25 deletions CRM/Event/BAO/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -1867,32 +1867,43 @@ public static function buildCustomProfile(
return $customProfile;
}

/* Function to retrieve all events those having location block set.
*
* @return array
* array of all events.
*/
/**
* Retrieve all event addresses.
*
* @return array
*/
public static function getLocationEvents() {
$events = array();
$ret = array(
'loc_block_id',
'loc_block_id.address_id.name',
'loc_block_id.address_id.street_address',
'loc_block_id.address_id.supplemental_address_1',
'loc_block_id.address_id.supplemental_address_2',
'loc_block_id.address_id.supplemental_address_3',
'loc_block_id.address_id.city',
'loc_block_id.address_id.state_province_id.name',
);

$query = "
SELECT CONCAT_WS(' :: ' , ca.name, ca.street_address, ca.city, sp.name, ca.supplemental_address_1, ca.supplemental_address_2, ca.supplemental_address_3) title, ce.loc_block_id
FROM civicrm_event ce
INNER JOIN civicrm_loc_block lb ON ce.loc_block_id = lb.id
INNER JOIN civicrm_address ca ON lb.address_id = ca.id
LEFT JOIN civicrm_state_province sp ON ca.state_province_id = sp.id
ORDER BY sp.name, ca.city, ca.street_address ASC
";

$dao = CRM_Core_DAO::executeQuery($query);
while ($dao->fetch()) {
$events[$dao->loc_block_id] = $dao->title;
$result = civicrm_api3('Event', 'get', array(
'check_permissions' => TRUE,
'return' => $ret,
'loc_block_id.address_id' => array('IS NOT NULL' => 1),
));

foreach ($result['values'] as $event) {
$address = '';
foreach ($ret as $field) {
if ($field != 'loc_block_id' && !empty($event[$field])) {
$address .= ($address ? ' :: ' : '') . $event[$field];
}
}
if ($address) {
$events[$event['loc_block_id']] = $address;
}
}

return $events;
return CRM_Utils_Array::asort($events);
}

/**
Expand Down Expand Up @@ -2039,13 +2050,18 @@ public static function checkPermission($eventId = NULL, $type = CRM_Core_Permiss
static $permissions = NULL;

if (empty($permissions)) {
$allEvents = CRM_Event_PseudoConstant::event(NULL, TRUE);
$createdEvents = array();

$session = CRM_Core_Session::singleton();
if ($userID = $session->get('userID')) {
$createdEvents = array_keys(CRM_Event_PseudoConstant::event(NULL, TRUE, "created_id={$userID}"));
}
$result = civicrm_api3('Event', 'get', array(
'check_permissions' => 1,
'return' => 'title',
));
$allEvents = CRM_Utils_Array::collect('title', $result['values']);

$result = civicrm_api3('Event', 'get', array(
'check_permissions' => 1,
'return' => 'title',
'created_id' => 'user_contact_id',
));
$createdEvents = CRM_Utils_Array::collect('title', $result['values']);

// Note: for a multisite setup, a user with edit all events, can edit all events
// including those from other sites
Expand Down
2 changes: 1 addition & 1 deletion CRM/Event/Page/ManageEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ public function whereClause(&$params, $sortBy = TRUE, $force) {
}
else {
$curDate = date('YmdHis');
$clauses[5] = "(end_date >= {$curDate} OR end_date IS NULL)";
$clauses[] = "(end_date >= {$curDate} OR end_date IS NULL)";
}
}
else {
Expand Down
2 changes: 1 addition & 1 deletion CRM/Utils/Array.php
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ public static function collect($prop, $records) {
$result[$key] = $record->{$prop};
}
else {
$result[$key] = $record[$prop];
$result[$key] = self::value($prop, $record);
}
}
}
Expand Down

0 comments on commit 11243f3

Please sign in to comment.