/** * 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(); } } }
/** * Check if the parent project has this module enabled. * * @param integer $projectId The project ID to check. * * @return boolean False if not. */ private static function _checkModule($moduleId, $projectId) { if ($projectId <= 0 || !Phprojekt_Module::saveTypeIsNormal($moduleId)) { return true; } $relation = new Project_Models_ProjectModulePermissions(); $modules = $relation->getProjectModulePermissionsById($projectId); return !empty($modules['data'][$moduleId]['inProject']); }
/** * Returns all the active modules that have the project. * * Returns a list of all the modules with: * <pre> * - id => id of the module. * - name => Name of the module. * - label => Display for the module. * - inProject => True or false if the project have the module. * </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 jsonGetModulesProjectRelationAction() { $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_ProjectModulePermissions(); $modules = $project->getProjectModulePermissionsById($projectId); Phprojekt_Converter_Json::echoConvert($modules); }
/** * Returns project-module && user-role-project permissions. * * Returns the permissions, * ("none", "read", "write", "access", "create", "copy", "delete", "download", "admin") * for each module that have the project, * for the current logged user, * depending on their role and access, in the project. * * REQUIRES request parameters: * <pre> * - integer <b>nodeId</b> The projectId for consult. * </pre> * * The return is in JSON format. * * @return void */ public function jsonGetModulesPermissionAction() { $projectId = (int) $this->getRequest()->getParam('nodeId'); $relation = new Project_Models_ProjectModulePermissions(); $modules = $relation->getProjectModulePermissionsById($projectId); if ($projectId == 0) { $data = array(); // there is no rights or invalid project } else { $allowedModules = array(); $rights = new Phprojekt_RoleRights($projectId); foreach ($modules['data'] as $module) { if ($module['inProject']) { $tmpPermission = Phprojekt_Acl::NONE; if ($rights->hasRight('admin', $module['id'])) { $tmpPermission = $tmpPermission | Phprojekt_Acl::ADMIN; } if ($rights->hasRight('create', $module['id'])) { $tmpPermission = $tmpPermission | Phprojekt_Acl::CREATE; } if ($rights->hasRight('write', $module['id'])) { $tmpPermission = $tmpPermission | Phprojekt_Acl::WRITE; } if ($rights->hasRight('read', $module['id'])) { $tmpPermission = $tmpPermission | Phprojekt_Acl::READ; } // Return modules with at least one access if ($tmpPermission != Phprojekt_Acl::NONE || Phprojekt_Auth::isAdminUser()) { $module['rights'] = Phprojekt_Acl::convertBitmaskToArray($tmpPermission); $allowedModules[] = $module; } } } $data = $allowedModules; } Phprojekt_Converter_Json::echoConvert($data); }