foreach ($allTags as $key => $dnc) {
$this->_name[] = $this->_tags[$key];
- list($total, $added, $notAdded) = CRM_Core_BAO_EntityTag::addEntitiesToTag($this->_activityHolderIds, $key, 'civicrm_activity');
+ list($total, $added, $notAdded) = CRM_Core_BAO_EntityTag::addEntitiesToTag($this->_activityHolderIds, $key,
+ 'civicrm_activity', FALSE);
$status = array(ts('Activity tagged', array('count' => $added, 'plural' => '%count activities tagged')));
if ($notAdded) {
foreach ($allTags as $key => $dnc) {
$this->_name[] = $this->_tags[$key];
- list($total, $removed, $notRemoved) = CRM_Core_BAO_EntityTag::removeEntitiesFromTag($this->_activityHolderIds, $key, 'civicrm_activity');
+ list($total, $removed, $notRemoved) = CRM_Core_BAO_EntityTag::removeEntitiesFromTag($this->_activityHolderIds,
+ $key, 'civicrm_activity', FALSE);
$status = array(
ts('%count activity un-tagged', array(
foreach ($allTags as $key => $dnc) {
$this->_name[] = $this->_tags[$key];
- list($total, $added, $notAdded) = CRM_Core_BAO_EntityTag::addEntitiesToTag($this->_contactIds, $key);
+ list($total, $added, $notAdded) = CRM_Core_BAO_EntityTag::addEntitiesToTag($this->_contactIds, $key,
+ 'civicrm_contact', FALSE);
$status = array(ts('%count contact tagged', array('count' => $added, 'plural' => '%count contacts tagged')));
if ($notAdded) {
foreach ($allTags as $key => $dnc) {
$this->_name[] = $this->_tags[$key];
- list($total, $removed, $notRemoved) = CRM_Core_BAO_EntityTag::removeEntitiesFromTag($this->_contactIds, $key);
+ list($total, $removed, $notRemoved) = CRM_Core_BAO_EntityTag::removeEntitiesFromTag($this->_contactIds, $key,
+ 'civicrm_contact', FALSE);
$status = array(
ts('%count contact un-tagged', array(
if (is_array($this->_tag)) {
$tagAdditions = array();
foreach ($this->_tag as $tagId => $val) {
- $addTagCount = CRM_Core_BAO_EntityTag::addEntitiesToTag($contactIds, $tagId);
+ $addTagCount = CRM_Core_BAO_EntityTag::addEntitiesToTag($contactIds, $tagId, 'civicrm_contact', FALSE);
$totalTagCount = $addTagCount[1];
if (isset($addedTag) && $tagId == $addedTag->id) {
$tagName = $newTagName;
* The id of the tag.
* @param string $entityTable
* Name of entity table default:civicrm_contact.
+ * @param bool $applyPermissions
+ * Should permissions be applied in this function.
*
* @return array
- * (total, added, notAdded) count of enities added to tag
+ * (total, added, notAdded) count of entities added to tag
*/
- public static function addEntitiesToTag(&$entityIds, $tagId, $entityTable = 'civicrm_contact') {
+ public static function addEntitiesToTag(&$entityIds, $tagId, $entityTable, $applyPermissions) {
$numEntitiesAdded = 0;
$numEntitiesNotAdded = 0;
$entityIdsAdded = array();
foreach ($entityIds as $entityId) {
// CRM-17350 - check if we have permission to edit the contact
// that this tag belongs to.
- if (!CRM_Contact_BAO_Contact_Permission::allow($entityId, CRM_Core_Permission::EDIT)) {
+ if ($applyPermissions && !self::checkPermissionOnEntityTag($entityId, $entityTable)) {
$numEntitiesNotAdded++;
continue;
}
}
/**
- * Given an array of entity ids and entity table, remove entity(s) tags
+ * Basic check for ACL permission on editing/creating/removing a tag.
+ *
+ * In the absence of something better contacts get a proper check and other entities
+ * default to 'edit all contacts'. This is currently only accessed from the api which previously
+ * applied edit all contacts to all - so while still too restrictive it represents a loosening.
+ *
+ * Current possible entities are attachments, activities, cases & contacts.
+ *
+ * @param int $entityID
+ * @param string $entityTable
+ *
+ * @return bool
+ */
+ public static function checkPermissionOnEntityTag($entityID, $entityTable) {
+ if ($entityTable == 'civicrm_contact') {
+ return CRM_Contact_BAO_Contact_Permission::allow($entityID, CRM_Core_Permission::EDIT);
+ }
+ else {
+ return CRM_Core_Permission::check('edit all contacts');
+ }
+ }
+
+ /**
+ * Given an array of entity ids and entity table, remove entity(s)tags.
*
* @param array $entityIds
* (reference ) the array of entity ids to be removed.
* The id of the tag.
* @param string $entityTable
* Name of entity table default:civicrm_contact.
+ * @param bool $applyPermissions
+ * Should permissions be applied in this function.
*
* @return array
* (total, removed, notRemoved) count of entities removed from tags
*/
- public static function removeEntitiesFromTag(&$entityIds, $tagId, $entityTable = 'civicrm_contact') {
+ public static function removeEntitiesFromTag(&$entityIds, $tagId, $entityTable, $applyPermissions) {
$numEntitiesRemoved = 0;
$numEntitiesNotRemoved = 0;
$entityIdsRemoved = array();
foreach ($entityIds as $entityId) {
// CRM-17350 - check if we have permission to edit the contact
// that this tag belongs to.
- if (!CRM_Contact_BAO_Contact_Permission::allow($entityId, CRM_Core_Permission::EDIT)) {
- $numEntitiesNotAdded++;
+ if ($applyPermissions && !self::checkPermissionOnEntityTag($entityId, $entityTable)) {
+ $numEntitiesNotRemoved++;
continue;
}
$tag = new CRM_Core_DAO_EntityTag();
else {
//do legacy non-standard behaviour
$values = CRM_Core_BAO_EntityTag::getTag($params['entity_id'], $params['entity_table']);
+
$result = array();
foreach ($values as $v) {
$result[$v] = array('tag_id' => $v);
}
}
}
+
if (empty($entityIDs)) {
return civicrm_api3_create_error('contact_id is a required field');
}
if ($op == 'add') {
$values['total_count'] = $values['added'] = $values['not_added'] = 0;
foreach ($tagIDs as $tagID) {
- list($te, $a, $na) = CRM_Core_BAO_EntityTag::addEntitiesToTag($entityIDs, $tagID, $entityTable);
+ list($te, $a, $na) = CRM_Core_BAO_EntityTag::addEntitiesToTag($entityIDs, $tagID, $entityTable,
+ CRM_Utils_Array::value('check_permissions', $params));
$values['total_count'] += $te;
$values['added'] += $a;
$values['not_added'] += $na;
else {
$values['total_count'] = $values['removed'] = $values['not_removed'] = 0;
foreach ($tagIDs as $tagID) {
- list($te, $r, $nr) = CRM_Core_BAO_EntityTag::removeEntitiesFromTag($entityIDs, $tagID, $entityTable);
+ list($te, $r, $nr) = CRM_Core_BAO_EntityTag::removeEntitiesFromTag($entityIDs, $tagID, $entityTable, CRM_Utils_Array::value('check_permissions', $params));
$values['total_count'] += $te;
$values['removed'] += $r;
$values['not_removed'] += $nr;