Example #1
0
 public static function mergeWithRole($moduleId, $projectId, $userId, $itemRights)
 {
     /* there is currently only an implementation for standard modules with
      * save type NORMAL */
     if (Phprojekt_Module::getSaveType($moduleId) == Phprojekt_Module::TYPE_NORMAL) {
         $roleRights = new Phprojekt_RoleRights($projectId, $moduleId, 0, $userId);
         $roleRightRead = $roleRights->hasRight('read');
         $roleRightWrite = $roleRights->hasRight('write');
         $roleRightCreate = $roleRights->hasRight('create');
         $roleRightAdmin = $roleRights->hasRight('admin');
         // Map roles with item rights and make one array
         foreach ($itemRights as $itemId => $accessMask) {
             $access = Phprojekt_Acl::NONE;
             if ($roleRightAdmin) {
                 $access |= $accessMask & Phprojekt_Acl::ADMIN;
             }
             if ($roleRightRead || $roleRightWrite || $roleRightAdmin) {
                 $access |= $accessMask & Phprojekt_Acl::DOWNLOAD;
             }
             if ($roleRightWrite || $roleRightAdmin) {
                 $access |= $accessMask & Phprojekt_Acl::DELETE;
             }
             if ($roleRightWrite || $roleRightCreate || $roleRightAdmin) {
                 $access |= $accessMask & Phprojekt_Acl::COPY;
             }
             if ($roleRightWrite || $roleRightCreate || $roleRightAdmin) {
                 $access |= $accessMask & Phprojekt_Acl::CREATE;
             }
             if ($roleRightRead || $roleRightWrite || $roleRightCreate || $roleRightAdmin) {
                 $access |= $accessMask & Phprojekt_Acl::ACCESS;
             }
             if ($roleRightWrite || $roleRightCreate || $roleRightAdmin) {
                 $access |= $accessMask & Phprojekt_Acl::WRITE;
             }
             if ($roleRightRead || $roleRightWrite || $roleRightAdmin) {
                 $access |= $accessMask & Phprojekt_Acl::READ;
             }
             $itemRights[$itemId] = $access;
         }
     }
     return $itemRights;
 }
Example #2
0
 /**
  * Return a list of projects with the necessary info to make the gantt chart.
  *
  * OPTIONAL request parameters:
  * <pre>
  *  - integer <b>nodeId</b> List all the items with projectId == nodeId.
  * </pre>
  *
  * The return have:
  * <pre>
  *  - projects => A list of projects.
  *  - rights   => Write access only if all the projects have write access.
  *  - min      => First startDate of all the projects.
  *  - max      => Last endDate of all the projects.
  *  - step     => Number of days in the year of the min value.
  * </pre>
  *
  * For each project in the list, the data have:
  * <pre>
  *  - id      => id of the project.
  *  - level   => Child level * 10.
  *  - parent  => id of the parent project.
  *  - childs  => Number of children.
  *  - caption => Title of the project.
  *  - start   => Timestamp of the startDate.
  *  - end     => Timestamp of the endDate.
  *  - startD  => Day of startDate.
  *  - startM  => Month of startDate.
  *  - startY  => Year of startDate.
  *  - endD    => Day of endDate.
  *  - endM    => Month of endDate.
  *  - endY    => Year of endDate.
  * </pre>
  *
  * The return is in JSON format.
  *
  * @return void
  */
 public function jsonGetProjectsAction()
 {
     $projectId = (int) $this->getRequest()->getParam('nodeId', null);
     $data['data'] = array();
     $activeRecord = Phprojekt_Loader::getModel('Project', 'Project');
     $tree = new Phprojekt_Tree_Node_Database($activeRecord, $projectId);
     $tree = $tree->setup();
     $min = gmmktime(0, 0, 0, 12, 31, 2030);
     $max = gmmktime(0, 0, 0, 1, 1, 1970);
     $ids = array();
     foreach ($tree as $node) {
         if ($node->id != self::INVISIBLE_ROOT) {
             $key = $node->id;
             $parent = $node->getParentNode() ? $node->getParentNode()->id : 0;
             if (strstr($node->startDate, '-') && strstr($node->endDate, '-')) {
                 list($startYear, $startMonth, $startDay) = explode("-", $node->startDate);
                 list($endYear, $endMonth, $endDay) = explode("-", $node->endDate);
                 $start = gmmktime(10, 0, 0, $startMonth, $startDay, $startYear);
                 $end = gmmktime(0, 0, 0, $endMonth, $endDay, $endYear);
                 if ($start < $min) {
                     $min = $start;
                 }
                 if ($end > $max) {
                     $max = $end;
                 }
                 $key = (int) $key;
                 $ids[] = $key;
                 $data['data']["projects"][$key] = array('id' => $key, 'level' => (int) $node->getDepth() * 10, 'parent' => (int) $parent, 'childs' => (int) count($node->getChildren()), 'caption' => $node->title, 'start' => (int) $start, 'end' => (int) $end, 'startD' => $startDay, 'startM' => $startMonth, 'startY' => $startYear, 'endD' => $endDay, 'endM' => $endMonth, 'endY' => $endYear);
             }
         }
     }
     // Define right access for each project
     // Also define the general write access for display the save button
     // (only if at least one project different than the parent have write or hight access)
     $data['data']['rights']["currentUser"]["write"] = false;
     if (count($ids) > 0) {
         $rights = Phprojekt_Loader::getLibraryClass('Phprojekt_Item_Rights');
         $where = sprintf('user_id = %d AND item_id IN (%s) AND module_id = 1', Phprojekt_Auth::getUserId(), implode(", ", $ids));
         $access = $rights->fetchAll($where)->toArray();
         foreach ($access as $right) {
             $itemRights = Phprojekt_Acl::convertBitmaskToArray($right['access']);
             $itemRight = $itemRights['write'] === true;
             // Mix the item_right with the role
             if ($itemRight) {
                 $roleRights = new Phprojekt_RoleRights($data['data']["projects"][$right['item_id']]['parent'], 1, $right['item_id']);
                 $roleRightWrite = $roleRights->hasRight('write');
                 $roleRightCreate = $roleRights->hasRight('create');
                 $roleRightAdmin = $roleRights->hasRight('admin');
                 $mixedRight = $roleRightWrite || $roleRightCreate || $roleRightAdmin;
             } else {
                 $mixedRight = false;
             }
             $data['data']['rights']["currentUser"][$right['item_id']] = $mixedRight;
             if ($data['data']['rights']["currentUser"]["write"] === false && $projectId != $right['item_id'] && $mixedRight) {
                 $data['data']['rights']["currentUser"]["write"] = true;
             }
         }
     }
     $data['data']['min'] = gmmktime(0, 0, 0, 1, 1, date("Y", $min));
     $data['data']['max'] = gmmktime(0, 0, 0, 12, 31, date("Y", $max));
     $data['data']['step'] = date("L", $min) ? 366 : 365;
     if (date("Y", $min) < date("Y", $max)) {
         while (date("Y", $min) != date("Y", $max)) {
             $data['data']['step'] += date("L", $max) ? 366 : 365;
             $max = gmmktime(0, 0, 0, 5, 5, date("Y", $max) - 1);
         }
     }
     // Remove index for the json data
     $data['data']["projects"] = array_values($data['data']["projects"]);
     Phprojekt_Converter_Json::echoConvert($data);
 }
 /**
  *  testGetUserRole().
  */
 public function testGetUserRole()
 {
     $this->assertEquals(1, $this->_object->getUserRole());
 }
Example #4
0
 /**
  * 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 = Phprojekt_Loader::getModel('Project', '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) {
                     $module['rights'] = Phprojekt_Acl::convertBitmaskToArray($tmpPermission);
                     $allowedModules[] = $module;
                 }
             }
         }
         $data = $allowedModules;
     }
     Phprojekt_Converter_Json::echoConvert($data);
 }
Example #5
0
 /**
  * Returns the right merged with the role for each user has on a Phprojekt item.
  *
  * @param array $rights Array of rights per user.
  *
  * @return array Array of rights per user.
  */
 public function _mergeRightsAndRole($rights)
 {
     $moduleId = Phprojekt_Module::getId($this->getModelName());
     $saveType = Phprojekt_Module::getSaveType($moduleId);
     switch ($saveType) {
         case Phprojekt_Module::TYPE_NORMAL:
             $roleRights = new Phprojekt_RoleRights($this->projectId, $moduleId, $this->id);
             $roleRightRead = $roleRights->hasRight('read');
             $roleRightWrite = $roleRights->hasRight('write');
             $roleRightCreate = $roleRights->hasRight('create');
             $roleRightAdmin = $roleRights->hasRight('admin');
             // Map roles with item rights and make one array
             foreach ($rights as $userId => $access) {
                 foreach ($access as $name => $value) {
                     switch ($name) {
                         case 'admin':
                             $rights[$userId]['admin'] = $roleRightAdmin && $value;
                             break;
                         case 'download':
                             $rights[$userId]['download'] = ($roleRightRead || $roleRightWrite || $roleRightAdmin) && $value;
                             break;
                         case 'delete':
                             $rights[$userId]['delete'] = ($roleRightWrite || $roleRightAdmin) && $value;
                             break;
                         case 'copy':
                             $rights[$userId]['copy'] = ($roleRightWrite || $roleRightCreate || $roleRightAdmin) && $value;
                             break;
                         case 'create':
                             $rights[$userId]['create'] = ($roleRightWrite || $roleRightCreate || $roleRightAdmin) && $value;
                             break;
                         case 'access':
                             $rights[$userId]['access'] = ($roleRightRead || $roleRightWrite || $roleRightCreate || $roleRightAdmin) && $value;
                             break;
                         case 'write':
                             $rights[$userId]['write'] = ($roleRightWrite || $roleRightCreate || $roleRightAdmin) && $value;
                             break;
                         case 'read':
                             $rights[$userId]['read'] = ($roleRightRead || $roleRightWrite || $roleRightAdmin) && $value;
                             break;
                         case 'none':
                             $rights[$userId]['none'] = $value;
                             break;
                     }
                 }
             }
             break;
         case Phprojekt_Module::TYPE_GLOBAL:
             break;
         case Phprojekt_Module::TYPE_MIX:
             // Implement saveType 2
             break;
     }
     return $rights;
 }