class Address extends Generic\DAOEntity {
/**
- * @return \Civi\Api4\Action\Address\Create
+ * @param bool $checkPermissions
+ * @return Action\Address\Create
*/
- public static function create() {
- return new \Civi\Api4\Action\Address\Create(__CLASS__, __FUNCTION__);
+ public static function create($checkPermissions = TRUE) {
+ return (new Action\Address\Create(__CLASS__, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
}
/**
- * @return \Civi\Api4\Action\Address\Save
+ * @param bool $checkPermissions
+ * @return Action\Address\Save
*/
- public static function save() {
- return new \Civi\Api4\Action\Address\Save(__CLASS__, __FUNCTION__);
+ public static function save($checkPermissions = TRUE) {
+ return (new Action\Address\Save(__CLASS__, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
}
/**
- * @return \Civi\Api4\Action\Address\Update
+ * @param bool $checkPermissions
+ * @return Action\Address\Update
*/
- public static function update() {
- return new \Civi\Api4\Action\Address\Update(__CLASS__, __FUNCTION__);
+ public static function update($checkPermissions = TRUE) {
+ return (new Action\Address\Update(__CLASS__, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
}
}
class Campaign extends Generic\DAOEntity {
/**
- * @return \Civi\Api4\Action\Campaign\Get
+ * @param bool $checkPermissions
+ * @return Action\Campaign\Get
*/
- public static function get() {
- return new \Civi\Api4\Action\Campaign\Get(__CLASS__, __FUNCTION__);
+ public static function get($checkPermissions = TRUE) {
+ return (new Action\Campaign\Get(__CLASS__, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
}
}
class Contact extends Generic\DAOEntity {
/**
- * @return \Civi\Api4\Action\Contact\GetChecksum
+ * @param bool $checkPermissions
+ * @return Action\Contact\GetChecksum
*/
- public static function getChecksum() {
- return new Action\Contact\GetChecksum(__CLASS__, __FUNCTION__);
+ public static function getChecksum($checkPermissions = TRUE) {
+ return (new Action\Contact\GetChecksum(__CLASS__, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
}
/**
- * @return \Civi\Api4\Action\Contact\ValidateChecksum
+ * @param bool $checkPermissions
+ * @return Action\Contact\ValidateChecksum
*/
- public static function validateChecksum() {
- return new Action\Contact\ValidateChecksum(__CLASS__, __FUNCTION__);
+ public static function validateChecksum($checkPermissions = TRUE) {
+ return (new Action\Contact\ValidateChecksum(__CLASS__, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
}
}
/**
* @param string $customGroup
+ * @param bool $checkPermissions
* @return Action\CustomValue\Get
* @throws \API_Exception
*/
- public static function get($customGroup) {
- return new Action\CustomValue\Get($customGroup, __FUNCTION__);
+ public static function get($customGroup, $checkPermissions = TRUE) {
+ return (new Action\CustomValue\Get($customGroup, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
}
/**
* @param string $customGroup
+ * @param bool $checkPermissions
* @return Action\CustomValue\GetFields
* @throws \API_Exception
*/
- public static function getFields($customGroup = NULL) {
- return new Action\CustomValue\GetFields($customGroup, __FUNCTION__);
+ public static function getFields($customGroup = NULL, $checkPermissions = TRUE) {
+ return (new Action\CustomValue\GetFields($customGroup, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
}
/**
* @param string $customGroup
+ * @param bool $checkPermissions
* @return Action\CustomValue\Save
* @throws \API_Exception
*/
- public static function save($customGroup) {
- return new Action\CustomValue\Save($customGroup, __FUNCTION__);
+ public static function save($customGroup, $checkPermissions = TRUE) {
+ return (new Action\CustomValue\Save($customGroup, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
}
/**
* @param string $customGroup
+ * @param bool $checkPermissions
* @return Action\CustomValue\Create
* @throws \API_Exception
*/
- public static function create($customGroup) {
- return new Action\CustomValue\Create($customGroup, __FUNCTION__);
+ public static function create($customGroup, $checkPermissions = TRUE) {
+ return (new Action\CustomValue\Create($customGroup, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
}
/**
* @param string $customGroup
+ * @param bool $checkPermissions
* @return Action\CustomValue\Update
* @throws \API_Exception
*/
- public static function update($customGroup) {
- return new Action\CustomValue\Update($customGroup, __FUNCTION__);
+ public static function update($customGroup, $checkPermissions = TRUE) {
+ return (new Action\CustomValue\Update($customGroup, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
}
/**
* @param string $customGroup
+ * @param bool $checkPermissions
* @return Action\CustomValue\Delete
* @throws \API_Exception
*/
- public static function delete($customGroup) {
- return new Action\CustomValue\Delete($customGroup, __FUNCTION__);
+ public static function delete($customGroup, $checkPermissions = TRUE) {
+ return (new Action\CustomValue\Delete($customGroup, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
}
/**
* @param string $customGroup
+ * @param bool $checkPermissions
* @return Action\CustomValue\Replace
* @throws \API_Exception
*/
- public static function replace($customGroup) {
- return new Action\CustomValue\Replace($customGroup, __FUNCTION__);
+ public static function replace($customGroup, $checkPermissions = TRUE) {
+ return (new Action\CustomValue\Replace($customGroup, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
}
/**
* @param string $customGroup
+ * @param bool $checkPermissions
* @return Action\CustomValue\GetActions
* @throws \API_Exception
*/
- public static function getActions($customGroup = NULL) {
- return new Action\CustomValue\GetActions($customGroup, __FUNCTION__);
+ public static function getActions($customGroup = NULL, $checkPermissions = TRUE) {
+ return (new Action\CustomValue\GetActions($customGroup, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
}
/**
*/
class Domain extends Generic\DAOEntity {
- public static function get() {
- return new \Civi\Api4\Action\Domain\Get(__CLASS__, __FUNCTION__);
+ /**
+ * @param bool $checkPermissions
+ * @return Action\Domain\Get
+ */
+ public static function get($checkPermissions = TRUE) {
+ return (new Action\Domain\Get(__CLASS__, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
}
}
class Entity extends Generic\AbstractEntity {
/**
+ * @param bool $checkPermissions
* @return Action\Entity\Get
*/
- public static function get() {
- return new Action\Entity\Get('Entity', __FUNCTION__);
+ public static function get($checkPermissions = TRUE) {
+ return (new Action\Entity\Get('Entity', __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
}
/**
- * @return \Civi\Api4\Generic\BasicGetFieldsAction
+ * @param bool $checkPermissions
+ * @return Generic\BasicGetFieldsAction
*/
- public static function getFields() {
- return new \Civi\Api4\Generic\BasicGetFieldsAction('Entity', __FUNCTION__, function() {
+ public static function getFields($checkPermissions = TRUE) {
+ return (new Generic\BasicGetFieldsAction('Entity', __FUNCTION__, function() {
return [
[
'name' => 'name',
'description' => 'Any @see annotations from docblock',
],
];
- });
+ }))->setCheckPermissions($checkPermissions);
}
/**
+ * @param bool $checkPermissions
* @return Action\Entity\GetLinks
*/
- public static function getLinks() {
- return new Action\Entity\GetLinks('Entity', __FUNCTION__);
+ public static function getLinks($checkPermissions = TRUE) {
+ return (new Action\Entity\GetLinks('Entity', __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
}
/**
class Event extends Generic\DAOEntity {
/**
- * @return \Civi\Api4\Action\Event\Get
+ * @param bool $checkPermissions
+ * @return Action\Event\Get
*/
- public static function get() {
- return new \Civi\Api4\Action\Event\Get(__CLASS__, __FUNCTION__);
+ public static function get($checkPermissions = TRUE) {
+ return (new Action\Event\Get(__CLASS__, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
}
}
* - Expose the param in the Api Explorer (be sure to add a doc-block as it displays in the help panel).
* - Require a value for the param if you add the "@required" annotation.
*
- * @method $this setCheckPermissions(bool $value) Enable/disable permission checks
* @method bool getCheckPermissions()
* @method $this setDebug(bool $value) Enable/disable debug output
* @method bool getDebug()
return $this;
}
+ /**
+ * @param bool $checkPermissions
+ * @return $this
+ */
+ public function setCheckPermissions(bool $checkPermissions) {
+ $this->checkPermissions = $checkPermissions;
+ return $this;
+ }
+
/**
* @param string $name
* Unique name for this chained request
abstract class AbstractEntity {
/**
+ * @param bool $checkPermissions
* @return \Civi\Api4\Action\GetActions
*/
- public static function getActions() {
- return new \Civi\Api4\Action\GetActions(self::getEntityName(), __FUNCTION__);
+ public static function getActions($checkPermissions = TRUE) {
+ return (new \Civi\Api4\Action\GetActions(self::getEntityName(), __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
}
/**
* Magic method to return the action object for an api.
*
* @param string $action
- * @param null $args
+ * @param array $args
* @return AbstractAction
* @throws NotImplementedException
*/
$entityAction = "\\Civi\\Api4\\Action\\$entity\\" . ucfirst($action);
if (class_exists($entityAction)) {
$actionObject = new $entityAction($entity, $action);
+ if (isset($args[0]) && $args[0] === FALSE) {
+ $actionObject->setCheckPermissions(FALSE);
+ }
}
else {
throw new NotImplementedException("Api $entity $action version 4 does not exist.");
abstract class DAOEntity extends AbstractEntity {
/**
+ * @param bool $checkPermissions
* @return DAOGetAction
- *
- * @throws \API_Exception
*/
- public static function get() {
- return new DAOGetAction(static::class, __FUNCTION__);
+ public static function get($checkPermissions = TRUE) {
+ return (new DAOGetAction(static::class, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
}
/**
+ * @param bool $checkPermissions
* @return DAOSaveAction
*/
- public static function save() {
- return new DAOSaveAction(static::class, __FUNCTION__);
+ public static function save($checkPermissions = TRUE) {
+ return (new DAOSaveAction(static::class, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
}
/**
+ * @param bool $checkPermissions
* @return DAOGetFieldsAction
*/
- public static function getFields() {
- return new DAOGetFieldsAction(static::class, __FUNCTION__);
+ public static function getFields($checkPermissions = TRUE) {
+ return (new DAOGetFieldsAction(static::class, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
}
/**
+ * @param bool $checkPermissions
* @return DAOCreateAction
- *
- * @throws \API_Exception
*/
- public static function create() {
- return new DAOCreateAction(static::class, __FUNCTION__);
+ public static function create($checkPermissions = TRUE) {
+ return (new DAOCreateAction(static::class, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
}
/**
+ * @param bool $checkPermissions
* @return DAOUpdateAction
*/
- public static function update() {
- return new DAOUpdateAction(static::class, __FUNCTION__);
+ public static function update($checkPermissions = TRUE) {
+ return (new DAOUpdateAction(static::class, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
}
/**
+ * @param bool $checkPermissions
* @return DAODeleteAction
*/
- public static function delete() {
- return new DAODeleteAction(static::class, __FUNCTION__);
+ public static function delete($checkPermissions = TRUE) {
+ return (new DAODeleteAction(static::class, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
}
/**
+ * @param bool $checkPermissions
* @return BasicReplaceAction
*/
- public static function replace() {
- return new BasicReplaceAction(static::class, __FUNCTION__);
+ public static function replace($checkPermissions = TRUE) {
+ return (new BasicReplaceAction(static::class, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
}
/**
class GroupContact extends Generic\DAOEntity {
/**
+ * @param bool $checkPermissions
* @return Action\GroupContact\Create
*/
- public static function create() {
- return new Action\GroupContact\Create(__CLASS__, __FUNCTION__);
+ public static function create($checkPermissions = TRUE) {
+ return (new Action\GroupContact\Create(__CLASS__, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
}
/**
+ * @param bool $checkPermissions
* @return Action\GroupContact\Save
*/
- public static function save() {
- return new Action\GroupContact\Save(__CLASS__, __FUNCTION__);
+ public static function save($checkPermissions = TRUE) {
+ return (new Action\GroupContact\Save(__CLASS__, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
}
/**
+ * @param bool $checkPermissions
* @return Action\GroupContact\Update
*/
- public static function update() {
- return new Action\GroupContact\Update(__CLASS__, __FUNCTION__);
+ public static function update($checkPermissions = TRUE) {
+ return (new Action\GroupContact\Update(__CLASS__, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
}
}
class Relationship extends Generic\DAOEntity {
/**
- * @return \Civi\Api4\Action\Relationship\Get
+ * @param bool $checkPermissions
+ * @return Action\Relationship\Get
*/
- public static function get() {
- return new \Civi\Api4\Action\Relationship\Get(static::class, __FUNCTION__);
+ public static function get($checkPermissions = TRUE) {
+ return (new Action\Relationship\Get(static::class, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
}
}
*
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
- * $Id$
- *
*/
namespace Civi\Api4;
-use Civi\Api4\Generic\BasicGetFieldsAction;
-
/**
* CiviCRM menu route.
*
class Route extends \Civi\Api4\Generic\AbstractEntity {
/**
+ * @param bool $checkPermissions
* @return \Civi\Api4\Generic\BasicGetAction
*/
- public static function get() {
- return new \Civi\Api4\Generic\BasicGetAction(__CLASS__, __FUNCTION__, function ($get) {
+ public static function get($checkPermissions = TRUE) {
+ return (new \Civi\Api4\Generic\BasicGetAction(__CLASS__, __FUNCTION__, function ($get) {
// Pulling from ::items() rather than DB -- because it provides the final/live/altered data.
$items = \CRM_Core_Menu::items();
$result = [];
$result[] = ['path' => $path] + $item;
}
return $result;
- });
+ }))->setCheckPermissions($checkPermissions);
}
- public static function getFields() {
- return new BasicGetFieldsAction(__CLASS__, __FUNCTION__, function() {
+ /**
+ * @param bool $checkPermissions
+ * @return Generic\BasicGetFieldsAction
+ */
+ public static function getFields($checkPermissions = TRUE) {
+ return (new Generic\BasicGetFieldsAction(__CLASS__, __FUNCTION__, function() {
return [
[
'name' => 'path',
'data_type' => 'Array',
],
];
- });
+ }))->setCheckPermissions($checkPermissions);
}
/**
*/
class Setting extends Generic\AbstractEntity {
- public static function get() {
- return new Action\Setting\Get(__CLASS__, __FUNCTION__);
+ /**
+ * @param bool $checkPermissions
+ * @return Action\Setting\Get
+ */
+ public static function get($checkPermissions = TRUE) {
+ return (new Action\Setting\Get(__CLASS__, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
}
- public static function set() {
- return new Action\Setting\Set(__CLASS__, __FUNCTION__);
+ /**
+ * @param bool $checkPermissions
+ * @return Action\Setting\Set
+ */
+ public static function set($checkPermissions = TRUE) {
+ return (new Action\Setting\Set(__CLASS__, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
}
- public static function revert() {
- return new Action\Setting\Revert(__CLASS__, __FUNCTION__);
+ /**
+ * @param bool $checkPermissions
+ * @return Action\Setting\Revert
+ */
+ public static function revert($checkPermissions = TRUE) {
+ return (new Action\Setting\Revert(__CLASS__, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
}
- public static function getFields() {
- return new Action\Setting\GetFields(__CLASS__, __FUNCTION__);
+ /**
+ * @param bool $checkPermissions
+ * @return Action\Setting\GetFields
+ */
+ public static function getFields($checkPermissions = TRUE) {
+ return (new Action\Setting\GetFields(__CLASS__, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
}
}
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/
-
namespace Civi\Api4;
-use Civi\Api4\Generic\BasicGetFieldsAction;
-
/**
* A collection of system maintenance/diagnostic utilities.
*
*/
class System extends Generic\AbstractEntity {
- public static function flush() {
- return new Action\System\Flush(__CLASS__, __FUNCTION__);
+ /**
+ * @param bool $checkPermissions
+ * @return Action\System\Flush
+ */
+ public static function flush($checkPermissions = TRUE) {
+ return (new Action\System\Flush(__CLASS__, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
}
- public static function check() {
- return new Action\System\Check(__CLASS__, __FUNCTION__);
+ /**
+ * @param bool $checkPermissions
+ * @return Action\System\Check
+ */
+ public static function check($checkPermissions = TRUE) {
+ return (new Action\System\Check(__CLASS__, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
}
- public static function getFields() {
- return new BasicGetFieldsAction(__CLASS__, __FUNCTION__, function() {
+ /**
+ * @param bool $checkPermissions
+ * @return Generic\BasicGetFieldsAction
+ */
+ public static function getFields($checkPermissions = TRUE) {
+ return (new Generic\BasicGetFieldsAction(__CLASS__, __FUNCTION__, function() {
return [];
- });
+ }))->setCheckPermissions($checkPermissions);
}
}
// Format oop params
function formatOOP(entity, action, params, indent) {
var code = '',
- newLine = "\n" + _.repeat(' ', indent);
+ newLine = "\n" + _.repeat(' ', indent),
+ perm = params.checkPermissions === false ? 'FALSE' : '';
if (entity.substr(0, 7) !== 'Custom_') {
- code = "\\Civi\\Api4\\" + entity + '::' + action + '()';
+ code = "\\Civi\\Api4\\" + entity + '::' + action + '(' + perm + ')';
} else {
- code = "\\Civi\\Api4\\CustomValue::" + action + "('" + entity.substr(7) + "')";
+ code = "\\Civi\\Api4\\CustomValue::" + action + "('" + entity.substr(7) + "'" + (perm ? ', ' : '') + perm + ")";
}
_.each(params, function(param, key) {
var val = '';
code += (chain.length > 3 ? ',' : '') + (!_.isEmpty(chain[2]) ? newLine : ' ') + (chain.length > 3 ? phpFormat(chain[3]) : '') + ')';
});
}
- else {
+ else if (key !== 'checkPermissions') {
code += newLine + "->set" + ucfirst(key) + '(' + phpFormat(param, 2 + indent) + ')';
}
});
return strpos(json_encode($mixed), $key) === FALSE;
};
- $contact = Contact::create()
- ->setCheckPermissions(FALSE)
+ $contact = Contact::create(FALSE)
->addValue('first_name', 'Api')
->addValue('last_name', 'Key0')
->addValue('api_key', $key)
->first();
$this->assertFalse($isSafe($contact), "Should reveal secret details ($key): " . var_export($contact, 1));
- Email::create()
- ->setCheckPermissions(FALSE)
+ Email::create(FALSE)
->addValue('email', 'foo@example.org')
->addValue('contact_id', $contact['id'])
->execute();
- $result = Email::get()
- ->setCheckPermissions(FALSE)
+ $result = Email::get(FALSE)
->addWhere('contact_id', '=', $contact['id'])
->addSelect('email')
->addSelect('contact.api_key')
->first();
$this->assertFalse($isSafe($result), "Should reveal secret details ($key): " . var_export($result, 1));
- $result = Email::get()
- ->setCheckPermissions(TRUE)
+ $result = Email::get(TRUE)
->addWhere('contact_id', '=', $contact['id'])
->addSelect('contact.api_key')
->execute()
\CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM', 'edit all contacts'];
$key = uniqid();
- $contact = Contact::create()
- ->setCheckPermissions(FALSE)
+ $contact = Contact::create(FALSE)
->addValue('first_name', 'Api')
->addValue('last_name', 'Key2')
->addValue('api_key', $key)
$error = $e->getMessage();
}
- $result = Contact::get()
- ->setCheckPermissions(FALSE)
+ $result = Contact::get(FALSE)
->addWhere('id', '=', $contact['id'])
->addSelect('api_key')
->execute()
\CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM', 'edit own api keys', 'edit all contacts'];
$key = uniqid();
- $contact = Contact::create()
- ->setCheckPermissions(FALSE)
+ $contact = Contact::create(FALSE)
->addValue('first_name', 'Api')
->addValue('last_name', 'Key3')
->addValue('api_key', $key)
$this->assertContains('key', $error);
- $result = Contact::get()
- ->setCheckPermissions(FALSE)
+ $result = Contact::get(FALSE)
->addWhere('id', '=', $contact['id'])
->addSelect('api_key')
->execute()
->addValue('api_key', "MyId!")
->execute();
- $result = Contact::get()
- ->setCheckPermissions(FALSE)
+ $result = Contact::get(FALSE)
->addWhere('id', '=', $contact['id'])
->addSelect('api_key')
->execute()
$exceptionThrown = '';
try {
$entityClass::get()
- ->setCheckPermissions('nada')
+ ->setDebug('not a bool')
->execute();
}
catch (\API_Exception $e) {
$exceptionThrown = $e->getMessage();
}
- $this->assertContains('checkPermissions', $exceptionThrown);
+ $this->assertContains('debug', $exceptionThrown);
$this->assertContains('type', $exceptionThrown);
}