* @return bool
* Was contact deleted?
*/
- public static function deleteContact($id, $restore = FALSE, $skipUndelete = FALSE) {
+ public static function deleteContact($id, $restore = FALSE, $skipUndelete = FALSE, $checkPermissions = TRUE) {
if (!$id) {
return FALSE;
// make sure we have edit permission for this contact
// before we delete
- if (($skipUndelete && !CRM_Core_Permission::check('delete contacts')) ||
- ($restore && !CRM_Core_Permission::check('access deleted contacts'))
+ if ($checkPermissions && (($skipUndelete && !CRM_Core_Permission::check('delete contacts')) ||
+ ($restore && !CRM_Core_Permission::check('access deleted contacts')))
) {
return FALSE;
}
if ($skipUndelete && CRM_Financial_BAO_FinancialItem::checkContactPresent(array($contactID), $error)) {
return civicrm_api3_create_error($error['_qf_default']);
}
- if (CRM_Contact_BAO_Contact::deleteContact($contactID, $restore, $skipUndelete)) {
+ if (CRM_Contact_BAO_Contact::deleteContact($contactID, $restore, $skipUndelete,
+ CRM_Utils_Array::value('check_permissions', $params))) {
return civicrm_api3_create_success();
}
else {
$this->callAPISuccess('contact', 'create', $params);
}
+ /**
+ * Test that delete with skip undelete respects permissions.
+ */
+ public function testContactDeletePermissions() {
+ $contactID = $this->individualCreate();
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM');
+ $this->callAPIFailure('Contact', 'delete', array(
+ 'id' => $contactID,
+ 'check_permissions' => 1,
+ 'skip_undelete' => 1,
+ ));
+ $this->callAPISuccess('Contact', 'delete', array(
+ 'id' => $contactID,
+ 'check_permissions' => 0,
+ 'skip_undelete' => 1,
+ ));
+ }
+
/**
* Test update with check permissions set.
*/