Ejemplo n.º 1
0
 /**
  * Delete a tree and all the sub-itemes.
  *
  * @param Phprojekt_ActiveRecord_Abstract $model Model to delete.
  *
  * @throws Exception If validation fails.
  *
  * @return boolean True for a sucessful delete.
  */
 protected static function _deleteTree(Phprojekt_ActiveRecord_Abstract $model)
 {
     $id = $model->id;
     // Checks
     if ($id == 1) {
         throw new Zend_Controller_Action_Exception('You can not delete the root project', 422);
     } else {
         if (!self::_checkItemRights($model, 'Project')) {
             throw new Zend_Controller_Action_Exception('You do not have access to do this action', 403);
         } else {
             $relations = new Project_Models_ProjectModulePermissions();
             $where = sprintf('project_id = %d', (int) $id);
             // Delete related items
             $modules = $relations->getProjectModulePermissionsById($id);
             $tag = new Phprojekt_Tags();
             foreach ($modules['data'] as $moduleData) {
                 if ($moduleData['inProject']) {
                     $module = Phprojekt_Loader::getModel($moduleData['name'], $moduleData['name']);
                     if ($module instanceof Phprojekt_ActiveRecord_Abstract) {
                         $records = $module->fetchAll($where);
                         if (is_array($records)) {
                             foreach ($records as $record) {
                                 $tag->deleteTagsByItem($moduleData['id'], $record->id);
                                 self::delete($record);
                             }
                         }
                     }
                 }
             }
             // Delete module-project relaton
             $records = $relations->fetchAll($where);
             if (is_array($records)) {
                 foreach ($records as $record) {
                     $record->delete();
                 }
             }
             // Delete user-role-projetc relation
             $relations = new Project_Models_ProjectRoleUserPermissions();
             $records = $relations->fetchAll($where);
             if (is_array($records)) {
                 foreach ($records as $record) {
                     $record->delete();
                 }
             }
             // Delete the project itself
             return null === $model->delete();
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Setter for UserRole,
  * the Role of ther user is fetched from the db.
  *
  * @return void
  */
 private function _setUserRole()
 {
     $project = new Project_Models_ProjectRoleUserPermissions();
     $this->_role = $project->fetchUserRole($this->getUser(), $this->getProject());
 }
Ejemplo n.º 3
0
 /**
  * Returns all the role-user relation with the project.
  *
  * Returns a list of all the roles related to the users under the project with:
  * <pre>
  *  - id    => id of the role.
  *  - name  => Name of the role.
  *  - users => id and display of the users with the role.
  * </pre>
  *
  * OPTIONAL request parameters:
  * <pre>
  *  - integer <b>id</b>     The project id for consult.
  *  - integer <b>nodeId</b> The id of the parent project.
  * </pre>
  *
  * The return is in JSON format.
  *
  * @return void
  */
 public function jsonGetProjectRoleUserRelationAction()
 {
     $projectId = (int) $this->getRequest()->getParam('id');
     $parentId = (int) $this->getRequest()->getParam('nodeId');
     // On new entries, get the parent data
     if (empty($projectId)) {
         $projectId = $parentId;
     }
     $project = new Project_Models_ProjectRoleUserPermissions();
     $roles = $project->getProjectRoleUserPermissions($projectId);
     Phprojekt_Converter_Json::echoConvert($roles);
 }
Ejemplo n.º 4
0
 /**
  * Save a tree.
  *
  * @param Phprojekt_Tree_Node_Database $node     The project to save.
  * @param array                        $params   The parameters used to feed the model.
  * @param integer|null                 $parentId The parent ID.
  *
  * @throws Exception If validation of parameters fails.
  *
  * @return boolean True for a sucessful save.
  */
 protected static function _saveTree(Phprojekt_Tree_Node_Database $node, array $params, $parentId = null)
 {
     $node = $node->setup();
     if (null === $parentId) {
         $parentId = $node->getParentNode()->id;
     }
     $parentNode = new Phprojekt_Tree_Node_Database($node->getActiveRecord(), $parentId);
     $parentNode = $parentNode->setup();
     $node = self::parameterToModel($node, $params);
     if (empty($node->getActiveRecord()->id)) {
         $newItem = true;
     } else {
         $newItem = false;
     }
     // Parent Project
     if (!isset($node->projectId)) {
         $node->projectId = 1;
     }
     if (!$node->getActiveRecord()->recordValidate()) {
         $errors = $node->getActiveRecord()->getError();
         $error = array_pop($errors);
         throw new Zend_Controller_Action_Exception($error['label'] . ': ' . $error['message'], 400);
     }
     if (!self::_checkModule(1, $node->projectId)) {
         throw new Zend_Controller_Action_Exception('You do not have access to add projects on the parent project', 403);
     }
     $setRights = isset($params['dataAccess']);
     $userId = Phprojekt_Auth_Proxy::getEffectiveUserId();
     $model = $node->getActiveRecord();
     $rights = Default_Helpers_Right::getRights($params);
     if ($newItem) {
         if (!$parentNode->getActiveRecord()->hasRight($userId, Phprojekt_Acl::CREATE)) {
             throw new Zend_Controller_Action_Exception('You do not have the necessary create right', 403);
         }
         $rights[$userId] = Phprojekt_Acl::ALL;
         $parentNode->appendNode($node);
     } else {
         if (!$model->hasRight($userId, Phprojekt_Acl::WRITE, $model->id)) {
             throw new Zend_Controller_Action_Exception('You do not have the necessary write right', 403);
         }
     }
     if ($newItem || $model->hasRight($userId, Phprojekt_Acl::ADMIN, $model->id)) {
         /* ensure we have at least one right */
         if ($setRights) {
             if (count($rights) <= 0) {
                 throw new Zend_Controller_Action_Exception('At least one person must have access to this item', 400);
             }
             $model->saveRights($rights);
         }
         // Save the module-project relation
         if (isset($params['moduleRelation'])) {
             if (!isset($params['checkModuleRelation'])) {
                 $params['checkModuleRelation'] = array();
             }
             $saveModules = array();
             foreach ($params['checkModuleRelation'] as $checkModule => $checkValue) {
                 if ($checkValue == 1) {
                     $saveModules[] = $checkModule;
                 }
             }
             $model->saveModules($saveModules);
         }
         // Save the role-user-project relation
         if (isset($params['userRelation'])) {
             $pru = new Project_Models_ProjectRoleUserPermissions();
             $pru->saveRelation($params['roleRelation'], array_keys($params['userRelation']), $node->getActiveRecord()->id);
         }
     }
     //FIXME: This hurts. It is needed to make Node_Database save everything.
     $node->projectId = 0;
     $node->setParentNode($parentNode);
     return $model;
 }