Пример #1
0
 public function testSetGetAclIdentities()
 {
     $firstStep = new WorkflowStep();
     $firstStep->setName('first_step');
     $secondStep = new WorkflowStep();
     $secondStep->setName('second_step');
     $this->workflowDefinition->setSteps(array($firstStep, $secondStep));
     $firstEntityAcl = new WorkflowEntityAcl();
     $firstEntityAcl->setStep($firstStep)->setAttribute('first_attribute');
     $secondEntityAcl = new WorkflowEntityAcl();
     $secondEntityAcl->setStep($secondStep)->setAttribute('second_attribute');
     // default
     $this->assertEmpty($this->workflowDefinition->getEntityAcls()->toArray());
     // adding
     $this->workflowDefinition->setEntityAcls(array($firstEntityAcl));
     $this->assertCount(1, $this->workflowDefinition->getEntityAcls());
     $this->assertEquals($firstEntityAcl, $this->workflowDefinition->getEntityAcls()->first());
     // merging
     $this->workflowDefinition->setEntityAcls(array($firstEntityAcl, $secondEntityAcl));
     $this->assertCount(2, $this->workflowDefinition->getEntityAcls());
     $entityAcls = array_values($this->workflowDefinition->getEntityAcls()->toArray());
     $this->assertEquals($firstEntityAcl, $entityAcls[0]);
     $this->assertEquals($secondEntityAcl, $entityAcls[1]);
     // removing
     $this->workflowDefinition->setEntityAcls(array($secondEntityAcl));
     $this->assertCount(1, $this->workflowDefinition->getEntityAcls());
     $this->assertEquals($secondEntityAcl, $this->workflowDefinition->getEntityAcls()->first());
     // resetting
     $this->workflowDefinition->setEntityAcls(array());
     $this->assertEmpty($this->workflowDefinition->getEntityAcls()->toArray());
 }
 /**
  * @param WorkflowDefinition $workflowDefinition
  * @param Workflow $workflow
  */
 protected function setEntityAcls(WorkflowDefinition $workflowDefinition, Workflow $workflow)
 {
     $entityAcls = array();
     foreach ($workflow->getAttributeManager()->getEntityAttributes() as $attribute) {
         foreach ($workflow->getStepManager()->getSteps() as $step) {
             $updatable = $attribute->isEntityUpdateAllowed() && $step->isEntityUpdateAllowed($attribute->getName());
             $deletable = $attribute->isEntityDeleteAllowed() && $step->isEntityDeleteAllowed($attribute->getName());
             if (!$updatable || !$deletable) {
                 $entityAcl = new WorkflowEntityAcl();
                 $entityAcl->setAttribute($attribute->getName())->setStep($workflowDefinition->getStepByName($step->getName()))->setEntityClass($attribute->getOption('class'))->setUpdatable($updatable)->setDeletable($deletable);
                 $entityAcls[] = $entityAcl;
             }
         }
     }
     $workflowDefinition->setEntityAcls($entityAcls);
 }