Beispiel #1
0
 /**
  * @param WorkflowItem $workflowItem
  * @return WorkflowItem
  * @throws WorkflowException
  */
 public function updateAclIdentities(WorkflowItem $workflowItem)
 {
     $workflow = $this->workflowRegistry->getWorkflow($workflowItem->getWorkflowName());
     $definition = $workflowItem->getDefinition();
     $currentStepName = $workflowItem->getCurrentStep()->getName();
     $aclIdentities = array();
     foreach ($definition->getEntityAcls() as $entityAcl) {
         if ($entityAcl->getStep()->getName() == $currentStepName) {
             $attributeName = $entityAcl->getAttribute();
             $attribute = $workflow->getAttributeManager()->getAttribute($attributeName);
             $entity = $workflowItem->getData()->get($attributeName);
             if (!$entity) {
                 continue;
             }
             if (!is_object($entity)) {
                 throw new WorkflowException(sprintf('Value of attribute "%s" must be an object', $attributeName));
             }
             $aclIdentity = new WorkflowEntityAclIdentity();
             $aclIdentity->setAcl($entityAcl)->setEntityClass($attribute->getOption('class'))->setEntityId($this->doctrineHelper->getSingleEntityIdentifier($entity));
             $aclIdentities[] = $aclIdentity;
         }
     }
     $workflowItem->setAclIdentities($aclIdentities);
     return $workflowItem;
 }
 /**
  * @param int $expected
  * @param object $object
  * @param array $attributes
  * @param bool $updatable
  * @param bool $deletable
  * @dataProvider voteDataProvider
  */
 public function testVote($expected, $object, array $attributes = [], $updatable = true, $deletable = true)
 {
     $entityAcl = new WorkflowEntityAcl();
     $entityAcl->setEntityClass('WorkflowEntity')->setUpdatable($updatable)->setDeletable($deletable);
     $aclIdentity = new WorkflowEntityAclIdentity();
     $aclIdentity->setAcl($entityAcl);
     $identifier = null;
     if ($object instanceof WorkflowEntity) {
         $identifier = $object->getId();
         $this->setDoctrineHelper('WorkflowEntity', $identifier);
     } elseif ($object instanceof ObjectIdentity && filter_var($object->getIdentifier(), FILTER_VALIDATE_INT)) {
         $identifier = $object->getIdentifier();
     }
     $this->setRegistryRepositories([$entityAcl], 'WorkflowEntity', $identifier, [$aclIdentity]);
     $token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface');
     $this->assertEquals($expected, $this->voter->vote($token, $object, $attributes));
 }
 /**
  * @param WorkflowEntityAclIdentity $aclIdentity
  * @return WorkflowEntityAclIdentity
  */
 public function import(WorkflowEntityAclIdentity $aclIdentity)
 {
     $this->setEntityId($aclIdentity->getEntityId());
     return $this;
 }
 /**
  * @expectedException \Oro\Bundle\WorkflowBundle\Exception\WorkflowException
  * @expectedExceptionMessage Workflow ACL identity with ID 1 doesn't have entity ACL
  */
 public function testGetAclAttributeStepKeyNoAclException()
 {
     $this->setEntityId(1);
     $this->aclIdentity->getAclAttributeStepKey();
 }
Beispiel #5
0
 /**
  * @param WorkflowEntityAclIdentity $aclIdentity
  * @return WorkflowItem
  */
 public function removeEntityAcl(WorkflowEntityAclIdentity $aclIdentity)
 {
     $attributeStep = $aclIdentity->getAclAttributeStepKey();
     if ($this->hasAclIdentityByAttribute($attributeStep)) {
         $aclIdentity = $this->getAclIdentityByAttributeStep($attributeStep);
         $this->aclIdentities->removeElement($aclIdentity);
     }
     return $this;
 }
Beispiel #6
0
 public function testSetGetAclIdentities()
 {
     $firstStep = new WorkflowStep();
     $firstStep->setName('first_step');
     $secondStep = new WorkflowStep();
     $secondStep->setName('second_step');
     $firstEntityAcl = new WorkflowEntityAcl();
     $firstEntityAcl->setStep($firstStep)->setAttribute('first_attribute');
     $secondEntityAcl = new WorkflowEntityAcl();
     $secondEntityAcl->setStep($secondStep)->setAttribute('second_attribute');
     $firstAclIdentity = new WorkflowEntityAclIdentity();
     $firstAclIdentity->setAcl($firstEntityAcl);
     $alternativeFirstAclIdentity = new WorkflowEntityAclIdentity();
     $alternativeFirstAclIdentity->setAcl($firstEntityAcl);
     $secondAclIdentity = new WorkflowEntityAclIdentity();
     $secondAclIdentity->setAcl($secondEntityAcl);
     // default
     $this->assertEmpty($this->workflowItem->getAclIdentities()->toArray());
     // adding
     $this->workflowItem->setAclIdentities(array($firstAclIdentity));
     $this->assertCount(1, $this->workflowItem->getAclIdentities());
     $this->assertEquals($firstAclIdentity, $this->workflowItem->getAclIdentities()->first());
     // merging
     $this->workflowItem->setAclIdentities(array($alternativeFirstAclIdentity, $secondAclIdentity));
     $this->assertCount(2, $this->workflowItem->getAclIdentities());
     $aclIdentities = array_values($this->workflowItem->getAclIdentities()->toArray());
     $this->assertEquals($firstAclIdentity, $aclIdentities[0]);
     $this->assertEquals($secondAclIdentity, $aclIdentities[1]);
     // removing
     $this->workflowItem->setAclIdentities(array($secondAclIdentity));
     $this->assertCount(1, $this->workflowItem->getAclIdentities());
     $this->assertEquals($secondAclIdentity, $this->workflowItem->getAclIdentities()->first());
     // resetting
     $this->workflowItem->setAclIdentities(array());
     $this->assertEmpty($this->workflowItem->getAclIdentities()->toArray());
 }