コード例 #1
0
 /**
  * @covers AclListener::aclUpdate()
  */
 public function testUpdateNonExistingAcl()
 {
     // get an ACL id not yet used
     $initialAclId = 1;
     while (null !== AclQuery::create()->findPk($initialAclId)) {
         ++$initialAclId;
     }
     $testAclCode = $this->makeUniqueAclCode("-customer-group-acl-unit-test-new-acl-code-");
     $anotherModuleId = ModuleQuery::create()->findOneByCode(CustomerGroup::getModuleCode())->getId();
     $updateEvent = new AclEvent($testAclCode, $anotherModuleId, "en_US", "New title", "New description", $initialAclId);
     $this->dispatcher->dispatch(CustomerGroupAclEvents::ACL_UPDATE, $updateEvent);
     $finalAcl = AclQuery::create()->findOneByCode($testAclCode);
     $this->assertNotNull($finalAcl);
     $this->assertEquals($finalAcl->getModuleId(), $anotherModuleId);
     $finalAcl->setLocale("en_US");
     $this->assertEquals($finalAcl->getTitle(), "New title");
     $this->assertEquals($finalAcl->getDescription(), "New description");
 }
コード例 #2
0
 /**
  * Check if the current user is granted access to a ressource.
  *
  * @param string|array $resources Resource name or resources list.
  * @param string|array $accesses  Access name or accesses list.
  * @param boolean      $accessOr  Whether to return true if at least one resource/access couple is granted.
  *
  * @return boolean Whether access is granted.
  */
 protected function performCheck($resources, $accesses, $accessOr = false)
 {
     /** @var Session $session */
     $session = $this->request->getSession();
     if ($session->getCustomerUser() === null || $session->has(CustomerGroup::getModuleCode()) === false) {
         return false;
     }
     $accessIdsList = [];
     foreach ($accesses as $access) {
         $accessIdsList[] = CustomerGroupAclAccessManager::getAccessPowsValue(strtoupper(trim($access)));
     }
     $accessIdsList = array_unique($accessIdsList);
     $groupId = $this->request->getSession()->get(CustomerGroup::getModuleCode())['id'];
     // For each acl be sure that the current customer has the right access
     $query = CustomerGroupAclQuery::create()->filterByActivate(1)->filterByCustomerGroupId($groupId)->filterByType($accessIdsList, Criteria::IN)->useAclQuery()->filterByCode($resources, Criteria::IN)->endUse();
     $rights = $query->count();
     $askedRights = count($resources) * count($accessIdsList);
     return $accessOr === true && $rights > 0 || $rights === $askedRights;
 }