/**
  * Produces the json to feed the dynamic dropdown
  * Used by pimcore.object.tags.dynamicDropdown
  */
 public function optionsAction()
 {
     $filter = new \Zend_Filter_PregReplace(array("match" => "@[^a-zA-Z0-9/\\-_]@", "replace" => ""));
     $parentFolderPath = $filter->filter($this->_getParam("source_parent"));
     if ($parentFolderPath) {
         // remove trailing slash
         if ($parentFolderPath != "/") {
             $parentFolderPath = rtrim($parentFolderPath, "/ ");
         }
         // correct wrong path (root-node problem)
         $parentFolderPath = str_replace("//", "/", $parentFolderPath);
         $folder = Object_Folder::getByPath($parentFolderPath);
         if ($folder) {
             $options = $this->walk_path($folder);
         } else {
             Logger::warning("The folder submitted for could not be found: \"" . $this->_getParam("source_parent") . "\"");
         }
     } else {
         Logger::warning("The folder submitted for source_parent is not valid: \"" . $this->_getParam("source_parent") . "\"");
     }
     $sort = $this->_getParam("sort_by");
     usort($options, function ($a, $b) use($sort) {
         $field = "id";
         if ($sort == "byvalue") {
             $field = "key";
         }
         if ($a[$field] == $b[$field]) {
             return 0;
         }
         return $a[$field] < $b[$field] ? 0 : 1;
     });
     $this->_helper->json($options);
 }
Exemplo n.º 2
0
 /**
  * makes sure, that the creation of objects with duplicate paths is not possible
  * @expectedException Exception
  * @depends testObjectFolderCreate
  */
 public function testDuplicateObjectPath()
 {
     $id = uniqid();
     $folder = Object_Folder::create(array("o_parentId" => 1, "o_creationDate" => time(), "o_key" => $id));
     $folder->save();
     $folder = Object_Folder::create(array("o_parentId" => 1, "o_creationDate" => time(), "o_key" => $id));
     $folder->save();
 }
Exemplo n.º 3
0
 public function getFolderAlpha($name)
 {
     $fdata["o_key"] = strtolower(substr($name, 0, 1));
     $root = $this->getFolderRoot();
     $data = $this->db->fetchRow(sprintf("SELECT o.* FROM objects o WHERE o.o_key ='%s' and o.o_type='folder' and o.o_parentId=%s", array($fdata['o_key'], $root->getId())));
     if ($data["o_id"]) {
         $folder = Object_Folder::getById($data["o_id"]);
         return $folder;
     } else {
         $fdata["o_parentId"] = $root->getId();
         $folder = Object_Folder::create($fdata);
         return $folder;
     }
 }
Exemplo n.º 4
0
 /**
  * change general user permissions
  * @depends testModifyUserToAdmin
  * @var User $user
  */
 public function testPermissionChanges()
 {
     $userGroup = User::getByName("unitTestUserGroup");
     $username = $userGroup->getUsername();
     $userGroup->setAdmin(false);
     $userGroup->save();
     unset($userGroup);
     $userGroup = User::getByName($username);
     //test if admin is allowed all
     $permissionList = new User_Permission_Definition_List();
     $permissionList->load();
     $permissions = $permissionList->getDefinitions();
     $setPermissions = array();
     //gradually set all system permissions
     foreach ($permissions as $permission) {
         $userGroup->setPermission($permission->getKey());
         $setPermissions[] = $permission->getKey();
         $userGroup->save();
         unset($userGroup);
         $userGroup = User::getByName($username);
         foreach ($setPermissions as $p) {
             $this->assertTrue($userGroup->isAllowed($p));
         }
     }
     //remove system permissions
     $userGroup->setAllAclToFalse();
     foreach ($setPermissions as $p) {
         $this->assertFalse($userGroup->isAllowed($p));
     }
     //cannot list documents, assts, objects because no permissions by now
     $documentRoot = Document::getById(1);
     $documentRoot->getPermissionsForUser($userGroup);
     $this->assertFalse($documentRoot->isAllowed("list"));
     $objectRoot = Object_Abstract::getById(1);
     $objectRoot->getPermissionsForUser($userGroup);
     $this->assertFalse($objectRoot->isAllowed("list"));
     $assetRoot = Asset::getById(1);
     $assetRoot->getPermissionsForUser($userGroup);
     $this->assertFalse($assetRoot->isAllowed("list"));
     $objectFolder = new Object_Folder();
     $objectFolder->setParentId(1);
     $objectFolder->setUserOwner(1);
     $objectFolder->setUserModification(1);
     $objectFolder->setCreationDate(time());
     $objectFolder->setKey(uniqid() . rand(10, 99));
     $objectFolder->save();
     $documentFolder = Document_Folder::create(1, array("userOwner" => 1, "key" => uniqid() . rand(10, 99)));
     $assetFolder = Asset_Folder::create(1, array("filename" => uniqid() . "_data", "type" => "folder", "userOwner" => 1));
     $user = User::getByName("unitTestUser");
     $user->setAdmin(false);
     $user->save();
     $userGroup->setPermission("objects");
     $userGroup->setPermission("documents");
     $userGroup->setPermission("assets");
     $userGroup->save();
     //test permissions with user group and user
     $this->permissionTest($objectRoot, $objectFolder, $userGroup, $user, $user, "object");
     $this->permissionTest($assetRoot, $assetFolder, $userGroup, $user, $user, "asset");
     $this->permissionTest($documentRoot, $documentFolder, $userGroup, $user, $user, "document");
     //test permissions when there is no user group permissions
     $user = User::create(array("parentId" => 0, "username" => "unitTestUser2", "password" => md5("unitTestUser2"), "hasCredentials" => true, "active" => true));
     unset($user);
     $user = User::getByName("unitTestUser2");
     $user->setPermission("objects");
     $user->setPermission("documents");
     $user->setPermission("assets");
     $user->save();
     $this->assertTrue($user instanceof User and $user->getUsername() == "unitTestUser2");
     $this->permissionTest($objectRoot, $objectFolder, null, $user, $user, "object");
     $this->permissionTest($assetRoot, $assetFolder, null, $user, $user, "asset");
     $this->permissionTest($documentRoot, $documentFolder, null, $user, $user, "document");
     //test permissions when there is only user group permissions
     $user = User::create(array("parentId" => $userGroup->getId(), "username" => "unitTestUser3", "password" => md5("unitTestUser3"), "hasCredentials" => true, "active" => true));
     unset($user);
     $user = User::getByName("unitTestUser3");
     $this->assertTrue($user instanceof User and $user->getUsername() == "unitTestUser3");
     $this->permissionTest($objectRoot, $objectFolder, $userGroup, null, $user, "object");
     $this->permissionTest($assetRoot, $assetFolder, $userGroup, null, $user, "asset");
     $this->permissionTest($documentRoot, $documentFolder, $userGroup, null, $user, "document");
 }
 public function addFolderAction()
 {
     $success = false;
     $parent = Object_Abstract::getById($this->_getParam("parentId"));
     if ($parent->isAllowed("create")) {
         if (!Object_Service::pathExists($parent->getFullPath() . "/" . $this->_getParam("key"))) {
             $folder = Object_Folder::create(array("o_parentId" => $this->_getParam("parentId"), "o_creationDate" => time(), "o_userOwner" => $this->user->getId(), "o_userModification" => $this->user->getId(), "o_key" => $this->_getParam("key"), "o_published" => true));
             $folder->setCreationDate(time());
             $folder->setUserOwner($this->getUser()->getId());
             $folder->setUserModification($this->getUser()->getId());
             try {
                 $folder->save();
                 $success = true;
             } catch (Exception $e) {
                 $this->_helper->json(array("success" => false, "message" => $e->getMessage()));
             }
         }
     } else {
         Logger::debug("prevented creating object id because of missing permissions");
     }
     $this->_helper->json(array("success" => $success));
 }
Exemplo n.º 6
0
 public function removeFolders()
 {
     $blogFolder = Object_Folder::getByPath('/blog');
     if ($blogFolder) {
         $blogFolder->delete();
     }
 }
 /**
  * @param $folderPath
  *
  * @return mixed
  * @throws Exception
  *
  * Runs each level of the folder-path and checks if it is already existing in pimcore
  */
 protected function checkFolderPath($folderPath)
 {
     $folderObject = Object_Folder::getByPath($folderPath);
     if (!is_object($folderObject)) {
         $folderPathArray = explode('/', $folderPath);
         $growingPath = '';
         foreach ($folderPathArray as $folderName) {
             $folderObject = Object_Folder::getByPath($growingPath . '/' . $folderName);
             if (!is_object($folderObject) && !method_exists($folderObject, 'getId')) {
                 try {
                     $parentFolder = Object_Folder::getByPath($growingPath);
                     if (is_object($parentFolder)) {
                         $parentId = $parentFolder->getId();
                         $parentFolder = Object_Folder::create(array('type' => 'folder', 'key' => $folderName, 'parentId' => $parentId));
                     }
                 } catch (Exception $e) {
                     throw $e;
                 }
             }
             $growingPath .= '/' . $folderName;
         }
     }
     if (is_object($folderObject)) {
         return $folderObject;
     } else {
         return $parentFolder;
     }
 }