/**
  * Update (or create) an ACL.
  *
  * @param AclEvent $event ACL event.
  *
  * @throws PropelException
  */
 public function aclUpdate(AclEvent $event)
 {
     // create the ACL if it does not exists
     if (null == ($acl = AclQuery::create()->findPk($event->getId()))) {
         $acl = new Acl();
     }
     $acl->setCode($event->getCode())->setModuleId($event->getModuleId())->setLocale($event->getLocale())->setTitle($event->getTitle())->setDescription($event->getDescription())->save();
 }
 public function preActivation(ConnectionInterface $con = null)
 {
     try {
         // Try find Acl DB Model
         AclQuery::create()->findOne();
         CustomerGroupAclQuery::create()->findOne();
     } catch (\Exception $e) {
         $database = new Database($con);
         $database->insertSql(null, [__DIR__ . DS . 'Config' . DS . 'thelia.sql']);
     }
     return true;
 }
 /**
  * @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");
 }
 /**
  * Performs an INSERT on the database, given a Acl or Criteria object.
  *
  * @param mixed               $criteria Criteria or Acl object containing data that is used to create the INSERT statement.
  * @param ConnectionInterface $con the ConnectionInterface connection to use
  * @return mixed           The new primary key.
  * @throws PropelException Any exceptions caught during processing will be
  *         rethrown wrapped into a PropelException.
  */
 public static function doInsert($criteria, ConnectionInterface $con = null)
 {
     if (null === $con) {
         $con = Propel::getServiceContainer()->getWriteConnection(AclTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from Acl object
     }
     if ($criteria->containsKey(AclTableMap::ID) && $criteria->keyContainsValue(AclTableMap::ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . AclTableMap::ID . ')');
     }
     // Set the correct dbName
     $query = AclQuery::create()->mergeWith($criteria);
     try {
         // use transaction because $criteria could contain info
         // for more than one table (I guess, conceivably)
         $con->beginTransaction();
         $pk = $query->doInsert($con);
         $con->commit();
     } catch (PropelException $e) {
         $con->rollBack();
         throw $e;
     }
     return $pk;
 }
 /**
  * Return the given acl code, or change it so that it is unique.
  * @param string $aclCode Acl code to make unique.
  * @return string
  */
 protected function makeUniqueAclCode($aclCode)
 {
     while (null !== AclQuery::create()->findOneByCode($aclCode)) {
         $aclCode .= rand(0, 9);
     }
     return $aclCode;
 }
Пример #6
0
 /**
  * Get the associated ChildAcl object
  *
  * @param      ConnectionInterface $con Optional Connection object.
  * @return                 ChildAcl The associated ChildAcl object.
  * @throws PropelException
  */
 public function getAcl(ConnectionInterface $con = null)
 {
     if ($this->aAcl === null && $this->id !== null) {
         $this->aAcl = ChildAclQuery::create()->findPk($this->id, $con);
         /* The following can be used additionally to
               guarantee the related object contains a reference
               to this object.  This level of coupling may, however, be
               undesirable since it could result in an only partially populated collection
               in the referenced object.
               $this->aAcl->addAclI18ns($this);
            */
     }
     return $this->aAcl;
 }
Пример #7
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see Acl::setDeleted()
  * @see Acl::isDeleted()
  */
 public function delete(ConnectionInterface $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getServiceContainer()->getWriteConnection(AclTableMap::DATABASE_NAME);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = ChildAclQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
 /**
  * Get an ACL by its code.
  * @param string $code ACL code.
  * @return Acl
  */
 public static function getAclByCode($code)
 {
     return AclQuery::create()->findOneByCode($code);
 }
 /**
  * Parse one customergroupacl
  *
  * @param SimpleXMLElement $customerGroupAcl A customergroupacl
  * @param CustomerGroup $customerGroupModel CustomerGroup propel object for who the access have to be created
  *
  * @throws \Exception When an error is detected on xml file (customer group or acl don't exist)
  */
 protected function parseCustomerGroupAcl(SimpleXMLElement $customerGroupAcl, CustomerGroup $customerGroupModel)
 {
     $acl = AclQuery::create()->findOneByCode($customerGroupAcl->getAttributeAsPhp('aclcode'));
     if (null === $customerGroupModel) {
         throw new \Exception($this->translator->trans("Error in %a file the customer group '%s' doesn't exist", ['%a' => $this->xmlFilePath, '%s' => $customerGroupModel->getCode()], CustomerGroupAcl::DOMAIN_MESSAGE));
     }
     if (null === $acl) {
         throw new \Exception($this->translator->trans("Error in %a file the acl '%s' doesn't exist", ['%a' => $this->xmlFilePath, '%s' => $customerGroupAcl->getAttributeAsPhp('aclcode')], CustomerGroupAcl::DOMAIN_MESSAGE));
     }
     $this->parseAccesses($customerGroupAcl->children(), $acl, $customerGroupModel);
 }
 /**
  * @covers AclXmlFileloader::load()
  */
 public function testLoadModuleWithValidConfigFile()
 {
     // get the acl and group acl state
     $initialAcls = AclQuery::create()->find();
     $initialCustomerGroupAcls = CustomerGroupAclQuery::create()->find();
     // load a test module with a valid ACL configuration
     $this->aclXmlFileloader->load($this->getStubModule("ModuleValidConfigFile"));
     // assert that the initial acl and group acl are still here
     $finalAcls = AclQuery::create()->find();
     foreach ($initialAcls as $acl) {
         $this->assertTrue($finalAcls->contains($acl));
     }
     $finalCustomerGroupAcls = CustomerGroupAclQuery::create()->find();
     foreach ($initialCustomerGroupAcls as $customerGroupAcl) {
         $this->assertTrue($finalCustomerGroupAcls->contains($customerGroupAcl));
     }
     // ensure that the new ACL were created
     $this->assertEquals($initialAcls->count() + 2, $finalAcls->count());
     $aclA = AclQuery::create()->findOneByCode("-customer-group-acl-unit-test-acl-a-");
     $this->assertNotNull($aclA);
     $aclA->setLocale("en_US");
     $this->assertEquals("Test ACL A", $aclA->getTitle());
     $this->assertEquals("Test ACL A description.", $aclA->getDescription());
     $aclA->setLocale("fr_FR");
     $this->assertEquals("ACL de test A", $aclA->getTitle());
     $this->assertEquals("Description de l'ACL de test A.", $aclA->getDescription());
     $aclB = AclQuery::create()->findOneByCode("-customer-group-acl-unit-test-acl-b-");
     $this->assertNotNull($aclB);
     $aclB->setLocale("en_US");
     $this->assertEquals("Test ACL B", $aclB->getTitle());
     $this->assertEquals("Test ACL B description.", $aclB->getDescription());
     $aclB->setLocale("fr_FR");
     $this->assertEquals("ACL de test B", $aclB->getTitle());
     $this->assertEquals("Description de l'ACL de test B.", $aclB->getDescription());
     // ensure that the group ACL were created
     $this->assertEquals($initialCustomerGroupAcls->count() + 11, $finalCustomerGroupAcls->count());
     // group a
     $this->assertCustomerGroupAclExistsAndUnique($aclA, self::$testCustomerGroups[0], CustomerGroupAclAccessManager::getAccessPowsValue("VIEW"));
     $this->assertCustomerGroupAclExistsAndUnique($aclA, self::$testCustomerGroups[0], CustomerGroupAclAccessManager::getAccessPowsValue("CREATE"));
     $this->assertCustomerGroupAclExistsAndUnique($aclB, self::$testCustomerGroups[0], CustomerGroupAclAccessManager::getAccessPowsValue("VIEW"));
     // group b
     $this->assertCustomerGroupAclExistsAndUnique($aclB, self::$testCustomerGroups[1], CustomerGroupAclAccessManager::getAccessPowsValue("VIEW"));
     $this->assertCustomerGroupAclExistsAndUnique($aclB, self::$testCustomerGroups[1], CustomerGroupAclAccessManager::getAccessPowsValue("CREATE"));
     $this->assertCustomerGroupAclExistsAndUnique($aclB, self::$testCustomerGroups[1], CustomerGroupAclAccessManager::getAccessPowsValue("UPDATE"));
     $this->assertCustomerGroupAclExistsAndUnique($aclB, self::$testCustomerGroups[1], CustomerGroupAclAccessManager::getAccessPowsValue("DELETE"));
     // group c, uses group a accesses
     $this->assertCustomerGroupAclExistsAndUnique($aclA, self::$testCustomerGroups[2], CustomerGroupAclAccessManager::getAccessPowsValue("VIEW"));
     $this->assertCustomerGroupAclExistsAndUnique($aclA, self::$testCustomerGroups[2], CustomerGroupAclAccessManager::getAccessPowsValue("CREATE"));
     $this->assertCustomerGroupAclExistsAndUnique($aclB, self::$testCustomerGroups[2], CustomerGroupAclAccessManager::getAccessPowsValue("VIEW"));
     // group d, uses group a accesses for acl b
     $this->assertCustomerGroupAclExistsAndUnique($aclB, self::$testCustomerGroups[3], CustomerGroupAclAccessManager::getAccessPowsValue("VIEW"));
 }