Ejemplo n.º 1
0
 /**
  * List all reports the user can access/run (both project reports and personnal reports)
  *
  * @param String  $session_key
  * @param Integer $group_id
  * @param Integer $tracker_id
  *
  * @return Array
  *
  * @throws SoapFault
  */
 public function getTrackerReports($session_key, $group_id, $tracker_id)
 {
     try {
         $current_user = $this->soap_request_validator->continueSession($session_key);
         $tracker = $this->tracker_factory->getTrackerById($tracker_id);
         $this->checkUserCanViewTracker($tracker, $current_user);
         return $this->report_factory->exportToSoap($tracker, $current_user);
     } catch (Exception $e) {
         return new SoapFault((string) $e->getCode(), $e->getMessage());
     }
 }
 public function displayHeader(Tracker_IFetchTrackerSwitcher $layout, Codendi_Request $request, PFUser $current_user, Tracker_Report $report, $report_can_be_modified)
 {
     $link_artifact_id = (int) $request->get('link-artifact-id');
     if ($report_can_be_modified) {
         $title = '';
         $breadcrumbs = array();
         $params = array('body_class' => array('in_tracker_report'));
         $toolbar = null;
         $report->getTracker()->displayHeader($layout, $title, $breadcrumbs, $toolbar, $params);
     }
     if ($request->get('pv')) {
         return;
     }
     $reports = $this->report_factory->getReportsByTrackerId($report->tracker_id, $current_user->getId());
     if ($link_artifact_id) {
         $this->displayHeaderInArtifactLinkModal($layout, $request, $current_user, $report, $reports, $link_artifact_id);
     } else {
         $this->displayHeaderInReport($request, $current_user, $report, $reports, $report_can_be_modified);
     }
 }
 /**
  * @param int $id the id of the report renderer to retrieve
  * @param Report $report the report of the renderer
  * @return ReportRenderer identified by id (null if not found)
  */
 public function getReportRendererById($id, $report, $store_in_session = true)
 {
     $row = $this->getDao()->searchById($id)->getRow();
     if ($row) {
         if (!$report) {
             //try to dynamically load it
             $arf = Tracker_ReportFactory::instance();
             $report = $arf->getReportById($row['report_id'], UserManager::instance()->getCurrentUser()->getId());
         }
         if ($report) {
             return $this->getInstanceFromRow($row, $report, $store_in_session);
         }
     }
     return null;
 }
 /**
  * Creates a Tracker Object
  *
  * @param SimpleXMLElement $xml containing the structure of the imported tracker
  * @param int $groupId - id of the project into which the tracker is imported
  * @param string $name of the tracker given by the user
  * @param string $description of the tracker given by the user
  * @param string $itemname - short_name of the tracker given by the user
  *
  * @return Tracker Object
  */
 protected function getInstanceFromXML($xml, $groupId, $name, $description, $itemname)
 {
     // set general settings
     // real id will be set during Database update
     $att = $xml->attributes();
     $row = array('id' => 0, 'name' => $name, 'group_id' => $groupId, 'description' => $description, 'item_name' => $itemname, 'submit_instructions' => (string) $xml->submit_instructions, 'browse_instructions' => (string) $xml->browse_instructions, 'status' => '', 'deletion_date' => '', 'color' => (string) $xml->color);
     $row['allow_copy'] = isset($att['allow_copy']) ? (int) $att['allow_copy'] : 0;
     $row['instantiate_for_new_projects'] = isset($att['instantiate_for_new_projects']) ? (int) $att['instantiate_for_new_projects'] : 0;
     $row['log_priority_changes'] = isset($att['log_priority_changes']) ? (int) $att['log_priority_changes'] : 0;
     $row['stop_notification'] = isset($att['stop_notification']) ? (int) $att['stop_notification'] : 0;
     $tracker = $this->tracker_factory->getInstanceFromRow($row);
     // set canned responses
     if (isset($xml->cannedResponses)) {
         foreach ($xml->cannedResponses->cannedResponse as $index => $response) {
             $tracker->cannedResponses[] = $this->canned_response_factory->getInstanceFromXML($response);
         }
     }
     // set formElements
     foreach ($xml->formElements->formElement as $index => $elem) {
         $tracker->formElements[] = $this->formelement_factory->getInstanceFromXML($tracker, $elem, $this->xmlFieldsMapping);
     }
     // set semantics
     if (isset($xml->semantics)) {
         foreach ($xml->semantics->semantic as $xml_semantic) {
             $semantic = $this->semantic_factory->getInstanceFromXML($xml_semantic, $this->xmlFieldsMapping, $tracker);
             if ($semantic) {
                 $tracker->semantics[] = $semantic;
             }
         }
     }
     /*
      * Legacy compatibility
      *
      * All new Tuleap versions will not export dependencies but rules instead.
      * However, we still want to be able to import old xml files.
      *
      * SimpleXML does not allow for nodes to be moved so have to recursively
      * generate rules from the dependencies data.
      */
     if (isset($xml->dependencies)) {
         $list_rules = null;
         if (!isset($xml->rules)) {
             $list_rules = $xml->addChild('rules')->addChild('list_rules');
         } elseif (!isset($xml->rules->list_rules)) {
             $list_rules = $xml->rules->addChild('list_rules', $xml->dependencies);
         }
         if ($list_rules !== null) {
             foreach ($xml->dependencies->rule as $old_rule) {
                 $source_field_attributes = $old_rule->source_field->attributes();
                 $target_field_attributes = $old_rule->target_field->attributes();
                 $source_value_attributes = $old_rule->source_value->attributes();
                 $target_value_attributes = $old_rule->target_value->attributes();
                 $new_rule = $list_rules->addChild('rule', $old_rule);
                 $new_rule->addChild('source_field')->addAttribute('REF', $source_field_attributes['REF']);
                 $new_rule->addChild('target_field')->addAttribute('REF', $target_field_attributes['REF']);
                 $new_rule->addChild('source_value')->addAttribute('REF', $source_value_attributes['REF']);
                 $new_rule->addChild('target_value')->addAttribute('REF', $target_value_attributes['REF']);
             }
         }
     }
     //set field rules
     if (isset($xml->rules)) {
         $tracker->rules = $this->rule_factory->getInstanceFromXML($xml->rules, $this->xmlFieldsMapping, $tracker);
     }
     // set report
     if (isset($xml->reports)) {
         foreach ($xml->reports->report as $report) {
             $tracker->reports[] = $this->report_factory->getInstanceFromXML($report, $this->xmlFieldsMapping, $groupId);
         }
     }
     //set workflow
     if (isset($xml->workflow->field_id)) {
         $tracker->workflow = $this->workflow_factory->getInstanceFromXML($xml->workflow, $this->xmlFieldsMapping, $tracker);
     }
     //set permissions
     if (isset($xml->permissions->permission)) {
         $allowed_tracker_perms = array(Tracker::PERMISSION_ADMIN, Tracker::PERMISSION_FULL, Tracker::PERMISSION_SUBMITTER, Tracker::PERMISSION_ASSIGNEE, Tracker::PERMISSION_SUBMITTER_ONLY);
         $allowed_field_perms = array('PLUGIN_TRACKER_FIELD_READ', 'PLUGIN_TRACKER_FIELD_UPDATE', 'PLUGIN_TRACKER_FIELD_SUBMIT');
         foreach ($xml->permissions->permission as $permission) {
             switch ((string) $permission['scope']) {
                 case 'tracker':
                     //tracker permissions
                     $ugroup = (string) $permission['ugroup'];
                     $type = (string) $permission['type'];
                     if (isset($GLOBALS['UGROUPS'][$ugroup]) && in_array($type, $allowed_tracker_perms)) {
                         $tracker->setCachePermission($GLOBALS['UGROUPS'][$ugroup], $type);
                     }
                     break;
                 case 'field':
                     //field permissions
                     $ugroup = (string) $permission['ugroup'];
                     $REF = (string) $permission['REF'];
                     $type = (string) $permission['type'];
                     if (isset($this->xmlFieldsMapping[$REF]) && isset($GLOBALS['UGROUPS'][$ugroup]) && in_array($type, $allowed_field_perms)) {
                         $this->xmlFieldsMapping[$REF]->setCachePermission($GLOBALS['UGROUPS'][$ugroup], $type);
                     }
                     break;
                 default:
                     break;
             }
         }
     }
     return $tracker;
 }
 /**
  * Process the request
  * 
  * @param Tracker_IDisplayTrackerLayout  $layout          Displays the page header and footer
  * @param Codendi_Request                $request         The data coming from the user
  * @param User                           $current_user    The user who mades the request
  *
  * @return void
  */
 public function process(Tracker_IDisplayTrackerLayout $layout, $request, $current_user)
 {
     switch ($request->get('func')) {
         case 'fetch-artifacts':
             $read_only = false;
             $prefill_removed_values = array();
             $only_rows = true;
             $this_project_id = $this->getTracker()->getProject()->getGroupId();
             $hp = Codendi_HTMLPurifier::instance();
             $ugroups = $current_user->getUgroups($this_project_id, array());
             $ids = $request->get('ids');
             //2, 14, 15
             $tracker = array();
             $result = array();
             //We must retrieve the last changeset ids of each artifact id.
             $dao = new Tracker_ArtifactDao();
             foreach ($dao->searchLastChangesetIds($ids, $ugroups, $current_user->isSuperUser()) as $matching_ids) {
                 $tracker_id = $matching_ids['tracker_id'];
                 $tracker = $this->getTrackerFactory()->getTrackerById($tracker_id);
                 $project = $tracker->getProject();
                 if ($tracker->userCanView()) {
                     $trf = Tracker_ReportFactory::instance();
                     $report = $trf->getDefaultReportsByTrackerId($tracker->getId());
                     if ($report) {
                         $renderers = $report->getRenderers();
                         // looking for the first table renderer
                         foreach ($renderers as $renderer) {
                             if ($renderer->getType() === Tracker_Report_Renderer::TABLE) {
                                 $key = $this->id . '_' . $report->id . '_' . $renderer->getId();
                                 $result[$key] = $renderer->fetchAsArtifactLink($matching_ids, $this->getId(), $read_only, $prefill_removed_values, $only_rows);
                                 $head = '<div>';
                                 $project_name = '';
                                 if ($project->getGroupId() != $this_project_id) {
                                     $project_name = ' (<abbr title="' . $hp->purify($project->getPublicName(), CODENDI_PURIFIER_CONVERT_HTML) . '">';
                                     $project_name .= $hp->purify($project->getUnixName(), CODENDI_PURIFIER_CONVERT_HTML);
                                     $project_name .= '</abbr>)';
                                 }
                                 $head .= '<h2 class="tracker-form-element-artifactlink-tracker_' . $tracker->getId() . '">';
                                 $head .= $hp->purify($tracker->getName(), CODENDI_PURIFIER_CONVERT_HTML) . $project_name;
                                 $head .= '</h2>';
                                 //if ($artifact) {
                                 //    $title = $hp->purify('link a '. $tracker->getItemName(), CODENDI_PURIFIER_CONVERT_HTML);
                                 //    $head .= '<a href="'.TRACKER_BASE_URL.'/?tracker='.$tracker_id.'&func=new-artifact-link&id='.$artifact->getId().'" class="tracker-form-element-artifactlink-link-new-artifact">'. 'create a new '.$hp->purify($tracker->getItemName(), CODENDI_PURIFIER_CONVERT_HTML)  .'</a>';
                                 //}
                                 $result[$key]['head'] = $head . $result[$key]['head'];
                                 break;
                             }
                         }
                     }
                 }
             }
             if ($result) {
                 $head = array();
                 $rows = array();
                 foreach ($result as $key => $value) {
                     $head[$key] = $value["head"];
                     $rows[$key] = $value["rows"];
                 }
                 header('Content-type: application/json');
                 echo json_encode(array('head' => $head, 'rows' => $rows));
             }
             exit;
             break;
         case 'fetch-aggregates':
             $read_only = false;
             $prefill_removed_values = array();
             $only_rows = true;
             $only_one_column = false;
             $extracolumn = Tracker_Report_Renderer_Table::EXTRACOLUMN_UNLINK;
             $read_only = true;
             $use_data_from_db = false;
             $ugroups = $current_user->getUgroups($this->getTracker()->getGroupId(), array());
             $ids = $request->get('ids');
             //2, 14, 15
             $tracker = array();
             $json = array('tabs' => array());
             $dao = new Tracker_ArtifactDao();
             foreach ($dao->searchLastChangesetIds($ids, $ugroups, $current_user->isSuperUser()) as $matching_ids) {
                 $tracker_id = $matching_ids['tracker_id'];
                 $tracker = $this->getTrackerFactory()->getTrackerById($tracker_id);
                 $project = $tracker->getProject();
                 if ($tracker->userCanView()) {
                     $trf = Tracker_ReportFactory::instance();
                     $report = $trf->getDefaultReportsByTrackerId($tracker->getId());
                     if ($report) {
                         $renderers = $report->getRenderers();
                         // looking for the first table renderer
                         foreach ($renderers as $renderer) {
                             if ($renderer->getType() === Tracker_Report_Renderer::TABLE) {
                                 $key = $this->id . '_' . $report->id . '_' . $renderer->getId();
                                 $columns = $renderer->getTableColumns($only_one_column, $use_data_from_db);
                                 $extracted_fields = $renderer->extractFieldsFromColumns($columns);
                                 $json['tabs'][] = array('key' => $key, 'src' => $renderer->fetchAggregates($matching_ids, $extracolumn, $only_one_column, $columns, $extracted_fields, $use_data_from_db, $read_only));
                                 break;
                             }
                         }
                     }
                 }
             }
             header('Content-type: application/json');
             echo json_encode($json);
             exit;
             break;
         default:
             parent::process($layout, $request, $current_user);
             break;
     }
 }
Ejemplo n.º 6
0
 public function toggle($params)
 {
     if ($params['id'] === 'tracker_report_query_0') {
         Toggler::togglePreference($params['user'], $params['id']);
         $params['done'] = true;
     } else {
         if (strpos($params['id'], 'tracker_report_query_') === 0) {
             $report_id = (int) substr($params['id'], strlen('tracker_report_query_'));
             $report_factory = Tracker_ReportFactory::instance();
             if (($report = $report_factory->getReportById($report_id, $params['user']->getid())) && $report->userCanUpdate($params['user'])) {
                 $report->toggleQueryDisplay();
                 $report_factory->save($report);
             }
             $params['done'] = true;
         }
     }
 }
Ejemplo n.º 7
0
 protected function getArtifactReportFactory()
 {
     return Tracker_ReportFactory::instance();
 }
Ejemplo n.º 8
0
 /**
  * Saves a Tracker object into the DataBase
  *
  * @param Tracker $tracker object to save
  * @return int id of the newly created tracker
  */
 public function saveObject($tracker)
 {
     // create tracker
     $tracker_id = $this->getDao()->create($tracker->group_id, $tracker->name, $tracker->description, $tracker->item_name, $tracker->allow_copy, $tracker->submit_instructions, $tracker->browse_instructions, '', '', $tracker->instantiate_for_new_projects, $tracker->stop_notification);
     if ($tracker_id) {
         $trackerDB = $this->getTrackerById($tracker_id);
         //create cannedResponses
         $response_factory = $tracker->getCannedResponseFactory();
         foreach ($tracker->cannedResponses as $response) {
             $response_factory->saveObject($tracker_id, $response);
         }
         //create formElements
         foreach ($tracker->formElements as $formElement) {
             // these fields have no parent
             Tracker_FormElementFactory::instance()->saveObject($trackerDB, $formElement, 0);
         }
         //create report
         foreach ($tracker->reports as $report) {
             Tracker_ReportFactory::instance()->saveObject($tracker_id, $report);
         }
         //create semantics
         if (isset($tracker->semantics)) {
             foreach ($tracker->semantics as $semantic) {
                 Tracker_SemanticFactory::instance()->saveObject($semantic, $trackerDB);
             }
         }
         //create workflow
         if (isset($tracker->workflow)) {
             WorkflowFactory::instance()->saveObject($tracker->workflow, $trackerDB);
         }
         //tracker permissions
         if ($tracker->permissionsAreCached()) {
             $pm = PermissionsManager::instance();
             foreach ($tracker->getPermissions() as $ugroup => $permissions) {
                 foreach ($permissions as $permission) {
                     $pm->addPermission($permission, $tracker_id, $ugroup);
                 }
             }
         } else {
             $this->saveTrackerDefaultPermission($tracker_id);
         }
         $this->postCreateActions($trackerDB);
     }
     return $tracker_id;
 }
 /**
  * Create new default report in the DataBase
  * 
  * @param int trackerId of the created tracker
  * @param Object report
  * 
  * @return id of the newly created Report
  */
 public function saveObject($trackerId, $report)
 {
     $reportId = $this->getDao()->create($report->name, $report->description, $report->current_renderer_id, $report->parent_report_id, $report->user_id, $report->is_default, $trackerId, $report->is_query_displayed);
     //create criterias
     $reportDB = Tracker_ReportFactory::instance()->getReportById($reportId, null);
     if ($report->criterias) {
         foreach ($report->criterias as $criteria) {
             $reportDB->addCriteria($criteria);
         }
     }
     //create renderers
     if ($report->renderers) {
         foreach ($report->renderers as $renderer) {
             if ($renderer) {
                 $rendererId = $reportDB->addRenderer($renderer->name, $renderer->description, $renderer->getType());
                 $rendererDB = Tracker_Report_RendererFactory::instance()->getReportRendererById($rendererId, $reportDB);
                 $rendererDB->afterSaveObject($renderer);
             }
         }
     }
     return $reportDB->id;
 }
Ejemplo n.º 10
0
 public function itHasTwoReports()
 {
     $this->assertCount($this->report_factory->getReportsByTrackerId(self::$task_tracker_id, null), 2);
 }
 /**
  * Fetch the html code to display the field value in card
  *
  * @param Tracker_Artifact $artifact
  *
  * @return string
  */
 public function fetchCardValue(Tracker_Artifact $artifact, Tracker_CardDisplayPreferences $display_preferences = null)
 {
     //return $this->fetchTooltipValue($artifact, $artifact->getLastChangeset()->getValue($this));
     $artifact_id = $artifact->getId();
     $changeset_id = $artifact->getLastChangeset()->getId();
     $value = $artifact->getLastChangeset()->getValue($this);
     $report = Tracker_ReportFactory::instance()->getDefaultReportsByTrackerId($artifact->getTracker()->getId());
     $request = HTTPRequest::instance();
     if ($request->exist('report')) {
         $report = Tracker_ReportFactory::instance()->getReportById($request->get('report'), UserManager::instance()->getCurrentUser()->getId());
     }
     return $this->fetchChangesetValue($artifact_id, $changeset_id, $value, $report);
 }
Ejemplo n.º 12
0
 /**
  * Delete the report and its renderers
  */
 protected function delete()
 {
     //Delete user preferences
     $dao = new UserPreferencesDao();
     $dao->deleteByPreferenceNameAndValue('tracker_' . $this->tracker_id . '_last_report', $this->id);
     //Delete criteria
     foreach ($this->getCriteria() as $criteria) {
         $this->removeCriteria($criteria->field->id);
     }
     //Delete renderers
     foreach ($this->getRenderers() as $renderer) {
         $this->deleteRenderer($renderer);
     }
     //clean session
     $this->report_session->cleanNamespace();
     //Delete me
     return Tracker_ReportFactory::instance()->delete($this->id);
 }
Ejemplo n.º 13
0
    $protocol = "http";
}
$server_uri = $protocol . '://' . ForgeConfig::get('sys_default_domain');
$uri = $server_uri . TRACKER_BASE_URL . '/soap';
if ($request->exist('wsdl')) {
    // Use a static wsdl file
    //$wsdl = file_get_contents(TRACKER_BASE_DIR .'/tracker.wsdl');
    //header('Content-type: text/xml');
    //echo str_replace('https://tuleap.example.com', $server_uri, $wsdl);
    //die();
    // Use nusoap to generate the wsdl
    require_once 'nusoap.php';
    require_once 'utils_soap.php';
    $server = new soap_server();
    $server->configureWSDL('TuleapTrackerV5API', $uri, false, 'rpc', 'http://schemas.xmlsoap.org/soap/http', $uri);
    require_once TRACKER_BASE_DIR . '/wsdl.php';
    // Call the service method to initiate the transaction and send the response
    $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
    $server->service($HTTP_RAW_POST_DATA);
} else {
    require_once TRACKER_BASE_DIR . '/Tracker/SOAPServer.class.php';
    $soap_options = array();
    if (ForgeConfig::get('DEBUG_MODE')) {
        $soap_options['cache_wsdl'] = WSDL_CACHE_NONE;
    }
    $formelement_factory = Tracker_FormElementFactory::instance();
    $artifact_factory = Tracker_ArtifactFactory::instance();
    $server = new TuleapSOAPServer($uri . '/?wsdl', $soap_options);
    $server->setClass('Tracker_SOAPServer', new SOAP_RequestValidator(ProjectManager::instance(), UserManager::instance()), TrackerFactory::instance(), PermissionsManager::instance(), new Tracker_ReportDao(), $formelement_factory, Tracker_ArtifactFactory::instance(), Tracker_ReportFactory::instance(), new Tracker_FileInfoFactory(new Tracker_FileInfoDao(), $formelement_factory, $artifact_factory), new TrackerManager());
    $server->handle();
}