Skip to content
Snippets Groups Projects
Commit 7e7967c2 authored by jaapjansma's avatar jaapjansma
Browse files

better permission handling and adding form processor actions for delete and change document

parent 500f877d
Branches
Tags 1.19
No related merge requests found
......@@ -156,6 +156,32 @@ class CRM_Documents_Entity_Document {
}
}
public function isAllowedToEdit() {
$allowEdit = false;
foreach($this->contactIds as $contactId) {
if (CRM_Contact_BAO_Contact_Permission::allow($contactId, CRM_Core_Permission::EDIT)) {
$allowEdit = true;
} elseif ($allowEdit) {
$allowEdit = false;
}
}
if ($this->caseIds && CRM_Core_Permission::check('access all cases and activities')) {
$allowEdit = true;
} elseif ($this->caseIds && !CRM_Core_Permission::check('access all cases and activities')) {
foreach($this->caseIds as $caseId) {
if (CRM_Case_BAO_Case::accessCase($caseId)) {
$allowEdit = true;
} elseif ($allowEdit) {
$allowEdit = false;
}
}
}
if (empty($this->contactIds) && empty($this->caseIds)) {
$allowEdit = true;
}
return $allowEdit;
}
public function addCaseId($caseId) {
if (!in_array($caseId, $this->caseIds)) {
$this->caseIds[] = $caseId;
......
......@@ -83,11 +83,6 @@ class CRM_Documents_Form_Document extends CRM_Core_Form {
}
}
//if there is no link to anything not even a contact throw an error
if ($ref === false && !$this->cid) {
throw new Exception('Could find valid value for cid');
}
if ($ref) {
$active_entities = array(' -- Select '.$ref->getHumanName().' --') + $ref->getActiveEntities();
$attributes = array();
......
......@@ -125,7 +125,10 @@ class CRM_Documents_Selector_Search extends CRM_Core_Selector_Base implements CR
}
}
$customFieldJoinStatement = implode("\r\n", $customFieldJoins);
$customFieldJoinStatement = "";
if ($customFieldJoins && is_array($customFieldJoins) && count($customFieldJoins)) {
$customFieldJoinStatement = implode("\r\n", $customFieldJoins);
}
return "FROM `civicrm_document` `doc`
LEFT JOIN `civicrm_document_contact` `doc_contact` ON `doc`.`id` = `doc_contact`.`document_id`
......@@ -201,7 +204,7 @@ class CRM_Documents_Selector_Search extends CRM_Core_Selector_Base implements CR
}
function whereClauseSingle(&$values) {
list($name, $op, $value, $grouping, $wildcard) = $values;
[$name, $op, $value, $grouping, $wildcard] = $values;
switch ($values[0]) {
/*case 'tag':
......@@ -416,7 +419,7 @@ class CRM_Documents_Selector_Search extends CRM_Core_Selector_Base implements CR
}
function sortName(&$values) {
list($name, $op, $value, $grouping, $wildcard) = $values;
[$name, $op, $value, $grouping, $wildcard] = $values;
// handle IS NULL / IS NOT NULL / IS EMPTY / IS NOT EMPTY
if ( $this->nameNullOrEmptyOp( $name, $op, $grouping ) ) {
......@@ -589,7 +592,7 @@ class CRM_Documents_Selector_Search extends CRM_Core_Selector_Base implements CR
$dbFieldName,
$appendTimeStamp = TRUE
) {
list($name, $op, $value, $grouping, $wildcard) = $values;
[$name, $op, $value, $grouping, $wildcard] = $values;
if (!$value) {
return;
......
<?php
namespace Civi\Documents\ActionProvider\Action;
use \Civi\ActionProvider\Action\AbstractAction;
use Civi\ActionProvider\Parameter\FileSpecification;
use Civi\ActionProvider\Parameter\OptionGroupSpecification;
use \Civi\ActionProvider\Parameter\ParameterBagInterface;
use \Civi\ActionProvider\Parameter\SpecificationBag;
use \Civi\ActionProvider\Parameter\Specification;
use \Civi\ActionProvider\Utils\CustomField;
use CRM_Documents_ExtensionUtil as E;
class ChangeDocument extends AbstractAction {
/**
* Run the action
*
* @param ParameterBagInterface $parameters
* The parameters to this action.
* @param ParameterBagInterface $output
* The parameters this action can send back
* @return void
*/
protected function doAction(ParameterBagInterface $parameters, ParameterBagInterface $output) {
$documentsRepo = \CRM_Documents_Entity_DocumentRepository::singleton();
$document = $documentsRepo->getDocumentById($parameters->getParameter('document_id'));
if ($parameters->getParameter('subject')) {
$document->setSubject($parameters->getParameter('subject'));
} elseif ($this->configuration->getParameter('subject')) {
$document->setSubject($this->configuration->getParameter('subject'));
}
if ($parameters->getParameter('type')) {
$document->setTypeId($parameters->getParameter('type'));
} elseif ($this->configuration->getParameter('type')) {
$document->setTypeId($this->configuration->getParameter('type'));
}
if ($parameters->getParameter('status')) {
$document->setStatusId($parameters->getParameter('status'));
} elseif ($this->configuration->getParameter('status')) {
$document->setStatusId($this->configuration->getParameter('status'));
}
$documentsRepo->persist($document);
$output->setParameter('document_id', $document->getId());
}
/**
* Returns the specification of the configuration options for the actual action.
*
* @return SpecificationBag
*/
public function getConfigurationSpecification() {
return new SpecificationBag([
new Specification('subject', 'String', E::ts('Subject'), false),
new OptionGroupSpecification('type', 'document_type', E::ts('Document Type'), false),
new OptionGroupSpecification('status', 'document_status', E::ts('Document Status'), false),
]);
}
/**
* Returns the specification of the parameters of the actual action.
*
* @return SpecificationBag
*/
public function getParameterSpecification() {
$specs = new SpecificationBag([
new Specification('subject', 'String', E::ts('Subject'), false),
new OptionGroupSpecification('type', 'document_type', E::ts('Document Type'), false),
new OptionGroupSpecification('status', 'document_status', E::ts('Document Status'), false),
new Specification('document_id', 'Integer', E::ts('Document ID'), true, null, null, null, false)
]);
return $specs;
}
/**
* Returns the specification of the output parameters of this action.
*
* This function could be overriden by child classes.
*
* @return SpecificationBag
*/
public function getOutputSpecification() {
return new SpecificationBag([
new Specification('document_id', 'Integer', E::ts('Document ID')),
]);
}
}
<?php
namespace Civi\Documents\ActionProvider\Action;
use \Civi\ActionProvider\Action\AbstractAction;
use Civi\ActionProvider\Parameter\FileSpecification;
use Civi\ActionProvider\Parameter\OptionGroupSpecification;
use \Civi\ActionProvider\Parameter\ParameterBagInterface;
use \Civi\ActionProvider\Parameter\SpecificationBag;
use \Civi\ActionProvider\Parameter\Specification;
use \Civi\ActionProvider\Utils\CustomField;
use CRM_Documents_ExtensionUtil as E;
class DeleteDocument extends AbstractAction {
/**
* Run the action
*
* @param ParameterBagInterface $parameters
* The parameters to this action.
* @param ParameterBagInterface $output
* The parameters this action can send back
* @return void
*/
protected function doAction(ParameterBagInterface $parameters, ParameterBagInterface $output) {
$documentsRepo = \CRM_Documents_Entity_DocumentRepository::singleton();
$document = $documentsRepo->getDocumentById($parameters->getParameter('document_id'));
$documentsRepo->remove($document);
}
/**
* Returns the specification of the configuration options for the actual action.
*
* @return SpecificationBag
*/
public function getConfigurationSpecification() {
return new SpecificationBag([]);
}
/**
* Returns the specification of the parameters of the actual action.
*
* @return SpecificationBag
*/
public function getParameterSpecification() {
$specs = new SpecificationBag([
new Specification('document_id', 'Integer', E::ts('Document ID'), true, null, null, null, false)
]);
return $specs;
}
/**
* Returns the specification of the output parameters of this action.
*
* This function could be overriden by child classes.
*
* @return SpecificationBag
*/
public function getOutputSpecification() {
return new SpecificationBag([]);
}
}
......@@ -82,6 +82,24 @@ class CompilerPass implements CompilerPassInterface {
AbstractAction::WITHOUT_CONTACT_ACTION_TAG
],
]);
$actionTypeFactoryDefinition->addMethodCall('addAction', [
'document_change',
'Civi\Documents\ActionProvider\Action\ChangeDocument',
E::ts('Documents: change document'),
[
AbstractAction::DATA_MANIPULATION_TAG,
AbstractAction::MULTIPLE_CONTACTS_ACTION_TAG
],
]);
$actionTypeFactoryDefinition->addMethodCall('addAction', [
'document_delete',
'Civi\Documents\ActionProvider\Action\DeleteDocument',
E::ts('Documents: delete'),
[
AbstractAction::DATA_MANIPULATION_TAG,
AbstractAction::MULTIPLE_CONTACTS_ACTION_TAG
],
]);
}
}
......
......@@ -15,7 +15,7 @@
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<releaseDate>2021-11-24</releaseDate>
<version>1.19-dev</version>
<version>1.19</version>
<develStage>stable</develStage>
<compatibility>
<ver>5.41</ver>
......
......@@ -19,6 +19,9 @@
{/if}
{assign var=document_id value=$doc->getId()}
{if ($doc->isAllowedToEdit())}
{assign var=permission value='edit'}
{/if}
{assign var=version value=$doc->getCurrentVersion()}
{capture assign=newVersionUrl}{crmURL p="civicrm/documents/newversion" q="reset=1&action=add&cid=`$contactId`&id=`$document_id`"}{/capture}
{capture assign=editDocumentURL}{crmURL p="civicrm/documents/document" q="reset=1&action=add&cid=`$contactId`&id=`$document_id`&entity=`$entity`&entity_id=`$entity_id`"}{/capture}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment