/** * Get the issue attachment with the specified id. * * @param string $p_username The name of the user trying to access the filters. * @param string $p_password The password of the user. * @param integer $p_attachment_id The id of the attachment to be retrieved. * @return Base64 encoded data that represents the attachment. */ function mc_issue_attachment_get($p_username, $p_password, $p_issue_attachment_id) { $t_user_id = mci_check_login($p_username, $p_password); if ($t_user_id === false) { return mci_soap_fault_login_failed(); } $t_file = mci_file_get($p_issue_attachment_id, 'bug', $t_user_id); if (SoapObjectsFactory::isSoapFault($t_file)) { return $t_file; } return SoapObjectsFactory::encodeBinary($t_file); }
/** * Get the custom field id given an object ref. The id is set based on the following algorithm: * - id from objectref (if not zero). * - id corresponding to name in object ref. * - 0, if object ref doesn't contain an id or a name. * * @param ObjectRef $p_object_ref An associate array with "id" and "name" keys. */ function mci_get_custom_field_id_from_objectref($p_object_ref) { $p_object_ref = SoapObjectsFactory::unwrapObject($p_object_ref); if ((int) $p_object_ref['id'] != 0) { $t_id = (int) $p_object_ref['id']; } else { if (!is_blank($p_object_ref['name'])) { $t_id = custom_field_get_id_from_name($p_object_ref['name']); } else { $t_id = 0; } } return $t_id; }
function mc_config_get_string($p_username, $p_password, $p_config_var) { $t_user_id = mci_check_login($p_username, $p_password); if ($t_user_id === false) { return mci_soap_fault_login_failed(); } if (!mci_has_readonly_access($t_user_id)) { return mci_soap_fault_access_denied($t_user_id); } if (config_is_private($p_config_var)) { return SoapObjectsFactory::newSoapFault('Client', "Access to '{$p_config_var}' is denied"); } if (!config_is_set($p_config_var)) { return SoapObjectsFactory::newSoapFault('Client', "Config '{$p_config_var}' is undefined"); } return config_get($p_config_var); }
/** * Add an attachment to an existing project. * * @param string $p_username The name of the user trying to add an attachment to an issue. * @param string $p_password The password of the user. * @param integer $p_project_id The id of the project to add the attachment to. * @param string $p_name The name of the file. * @param string $p_title The title for the attachment. * @param string $p_description The description for the attachment. * @param string $p_file_type The mime type of the file. * @param base64Binary $p_content The attachment to add. * @return integer The id of the added attachment. */ function mc_project_attachment_add($p_username, $p_password, $p_project_id, $p_name, $p_title, $p_description, $p_file_type, $p_content) { $t_user_id = mci_check_login($p_username, $p_password); if ($t_user_id === false) { return mci_soap_fault_login_failed(); } # Check if project documentation feature is enabled. if (OFF == config_get('enable_project_documentation')) { return mci_soap_fault_access_denied($t_user_id); } if (!access_has_project_level(config_get('upload_project_file_threshold'), $p_project_id, $t_user_id)) { return mci_soap_fault_access_denied($t_user_id); } if (is_blank($p_title)) { return SoapObjectsFactory::newSoapFault('Client', 'Title must not be empty.'); } return mci_file_add($p_project_id, $p_name, $p_content, $p_file_type, 'project', $p_title, $p_description, $t_user_id); }
/** * Returns a soap_fault signalling that the user does not have * access rights for the specific action. * * @param integer $p_user_id A user id, optional. * @param string $p_detail The optional details to append to the error message. * @return soap_fault */ function mci_soap_fault_access_denied($p_user_id = 0, $p_detail = '') { if ($p_user_id) { $t_user_name = user_get_name($p_user_id); $t_reason = 'Access denied for user ' . $t_user_name . '.'; } else { $t_reason = 'Access denied'; } if (!is_blank($p_detail)) { $t_reason .= ' Reason: ' . $p_detail . '.'; } return SoapObjectsFactory::newSoapFault('Client', $t_reason); }
function mci_tag_set_for_issue($p_issue_id, $p_tags, $p_user_id) { $t_tag_ids_to_attach = array(); $t_tag_ids_to_detach = array(); $t_submitted_tag_ids = array(); $t_attached_tags = tag_bug_get_attached($p_issue_id); $t_attached_tag_ids = array(); foreach ($t_attached_tags as $t_attached_tag) { $t_attached_tag_ids[] = $t_attached_tag['id']; } foreach ($p_tags as $t_tag) { $t_tag = SoapObjectsFactory::unwrapObject($t_tag); $t_submitted_tag_ids[] = $t_tag['id']; if (in_array($t_tag['id'], $t_attached_tag_ids)) { continue; } else { $t_tag_ids_to_attach[] = $t_tag['id']; } } foreach ($t_attached_tag_ids as $t_attached_tag_id) { if (in_array($t_attached_tag_id, $t_submitted_tag_ids)) { continue; } else { $t_tag_ids_to_detach[] = $t_attached_tag_id; } } foreach ($t_tag_ids_to_detach as $t_tag_id) { if (access_has_bug_level(config_get('tag_detach_threshold'), $p_issue_id, $p_user_id)) { tag_bug_detach($t_tag_id, $p_issue_id); } } foreach ($t_tag_ids_to_attach as $t_tag_id) { if (access_has_bug_level(config_get('tag_attach_threshold'), $p_issue_id, $p_user_id)) { tag_bug_attach($t_tag_id, $p_issue_id); } } }
/** * Get the enumeration id given an object ref. The id is set based on the following algorithm: * - id from objectref. * - id corresponding to name in object ref. * - default value for the specified enumeration, if exists in configuration. * - first id, if object ref doesn't contain an id or a name. * * @param string $p_enum The name of the enumeration as in the MantisBT configuration file * @param ObjectRef $p_object_ref An associate array with "id" and "name" keys. * @return enum id */ function mci_get_enum_id_from_objectref($p_enum, $p_object_ref) { $p_object_ref = SoapObjectsFactory::unwrapObject($p_object_ref); if (!is_null($p_object_ref) && isset($p_object_ref['id']) && (int) $p_object_ref['id'] != 0) { $t_id = (int) $p_object_ref['id']; } else { $t_enum = config_get($p_enum . '_enum_string'); if (!is_null($p_object_ref) && isset($p_object_ref['name']) && !is_blank($p_object_ref['name'])) { $t_id = mci_get_enum_value_from_label($t_enum, $p_object_ref['name']); if ($t_id == 0) { $t_id = config_get('mc_' . $p_enum . '_enum_default_when_not_found'); } } else { $t_default_id = config_get('default_bug_' . $p_enum, 0); if ($t_default_id == 0) { $t_array = mci_explode_to_objectref($p_enum); $t_id = (int) $t_array[0]['id']; } else { $t_id = $t_default_id; } } } return $t_id; }
/** * Returns an array for SOAP encoding from a BugData object * * @param BugData $p_issue_data A BugData object to process. * @return array The issue header data as an array */ function mci_issue_data_as_header_array(BugData $p_issue_data) { $t_issue = array(); $t_id = $p_issue_data->id; $t_issue['id'] = $t_id; $t_issue['view_state'] = $p_issue_data->view_state; $t_issue['last_updated'] = SoapObjectsFactory::newDateTimeVar($p_issue_data->last_updated); $t_issue['project'] = $p_issue_data->project_id; $t_issue['category'] = mci_get_category($p_issue_data->category_id); $t_issue['priority'] = $p_issue_data->priority; $t_issue['severity'] = $p_issue_data->severity; $t_issue['status'] = $p_issue_data->status; $t_issue['reporter'] = $p_issue_data->reporter_id; $t_issue['summary'] = mci_sanitize_xml_string($p_issue_data->summary); if (!empty($p_issue_data->handler_id)) { $t_issue['handler'] = $p_issue_data->handler_id; } else { $t_issue['handler'] = null; } $t_issue['resolution'] = $p_issue_data->resolution; $t_issue['attachments_count'] = count(mci_issue_get_attachments($p_issue_data->id)); $t_issue['notes_count'] = count(mci_issue_get_notes($p_issue_data->id)); return $t_issue; }
/** * Get the issue headers that match the specified filter and paging details. * * @param string $p_username The name of the user trying to access the filters. * @param string $p_password The password of the user. * @param integer $p_project_id The id of the project to retrieve filters for. * @param integer $p_filter_id The id of the filter to apply. * @param integer $p_page_number Start with the given page number (zero-based). * @param integer $p_per_page Number of issues to display per page. * @return array that represents an IssueDataArray structure */ function mc_filter_get_issue_headers($p_username, $p_password, $p_project_id, $p_filter_id, $p_page_number, $p_per_page) { $t_user_id = mci_check_login($p_username, $p_password); if ($t_user_id === false) { return mci_soap_fault_login_failed(); } if (!mci_has_readonly_access($t_user_id, $p_project_id)) { return mci_soap_fault_access_denied($t_user_id); } $t_orig_page_number = $p_page_number < 1 ? 1 : $p_page_number; $t_page_count = 0; $t_bug_count = 0; $t_filter = filter_db_get_filter($p_filter_id); $t_filter_detail = explode('#', $t_filter, 2); if (!isset($t_filter_detail[1])) { return SoapObjectsFactory::newSoapFault('Server', 'Invalid Filter'); } $t_filter = json_decode($t_filter_detail[1], true); $t_filter = filter_ensure_valid_filter($t_filter); $t_result = array(); $t_rows = filter_get_bug_rows($p_page_number, $p_per_page, $t_page_count, $t_bug_count, $t_filter, $p_project_id); # the page number was moved back, so we have exceeded the actual page number, see bug #12991 if ($t_orig_page_number > $p_page_number) { return $t_result; } foreach ($t_rows as $t_issue_data) { $t_result[] = mci_issue_data_as_header_array($t_issue_data); } return $t_result; }
/** * Get Issue Headers * @param string $p_username The name of the user trying to access the versions. * @param string $p_password The password of the user. * @param integer $p_project_id The id of the project to retrieve the attachments for. * @param integer $p_page_number Page number. * @param integer $p_per_page Per page. * @return mixed */ function mc_project_get_issue_headers($p_username, $p_password, $p_project_id, $p_page_number, $p_per_page) { global $g_project_override; $t_user_id = mci_check_login($p_username, $p_password); if ($t_user_id === false) { return mci_soap_fault_login_failed(); } if ($p_project_id != ALL_PROJECTS && !project_exists($p_project_id)) { return SoapObjectsFactory::newSoapFault('Client', 'Project \'' . $p_project_id . '\' does not exist.'); } $g_project_override = $p_project_id; if (!mci_has_readonly_access($t_user_id, $p_project_id)) { return mci_soap_fault_access_denied($t_user_id); } $t_orig_page_number = $p_page_number < 1 ? 1 : $p_page_number; $t_page_count = 0; $t_bug_count = 0; $t_rows = filter_get_bug_rows($p_page_number, $p_per_page, $t_page_count, $t_bug_count, null, $p_project_id); $t_result = array(); # the page number was moved back, so we have exceeded the actual page number, see bug #12991 if ($t_orig_page_number > $p_page_number) { return $t_result; } foreach ($t_rows as $t_issue_data) { $t_result[] = mci_issue_data_as_header_array($t_issue_data); } return $t_result; }
/** * Returns the attachment contents * * @param int $p_file_id * @param string $p_type The file type, bug or doc * @param int $p_user_id * @return string|soap_fault the string contents, or a soap_fault */ function mci_file_get($p_file_id, $p_type, $p_user_id) { # we handle the case where the file is attached to a bug # or attached to a project as a project doc. $t_query = ''; switch ($p_type) { case 'bug': $t_bug_file_table = db_get_table('mantis_bug_file_table'); $t_query = "SELECT * FROM {$t_bug_file_table} WHERE id=" . db_param(); break; case 'doc': $t_project_file_table = db_get_table('mantis_project_file_table'); $t_query = "SELECT * FROM {$t_project_file_table} WHERE id=" . db_param(); break; default: return SoapObjectsFactory::newSoapFault('Server', 'Invalid file type ' . $p_type . ' .'); } $result = db_query_bound($t_query, array($p_file_id)); if ($result->EOF) { return SoapObjectsFactory::newSoapFault('Client', 'Unable to find an attachment with type ' . $p_type . ' and id ' . $p_file_id . ' .'); } $row = db_fetch_array($result); if ($p_type == 'doc') { $t_project_id = $row['project_id']; } else { if ($p_type == 'bug') { $t_bug_id = $row['bug_id']; $t_project_id = bug_get_field($t_bug_id, 'project_id'); } } $t_diskfile = file_normalize_attachment_path($row['diskfile'], $t_project_id); $t_content = $row['content']; # Check access rights switch ($p_type) { case 'bug': if (!mci_file_can_download_bug_attachments($t_bug_id, $p_user_id)) { return mci_soap_fault_access_denied($p_user_id); } break; case 'doc': # Check if project documentation feature is enabled. if (OFF == config_get('enable_project_documentation')) { return mci_soap_fault_access_denied($p_user_id); } if (!access_has_project_level(config_get('view_proj_doc_threshold'), $t_project_id, $p_user_id)) { return mci_soap_fault_access_denied($p_user_id); } break; } # dump file content to the connection. switch (config_get('file_upload_method')) { case DISK: if (file_exists($t_diskfile)) { return mci_file_read_local($t_diskfile); } else { return SoapObjectsFactory::newSoapFault('Client', 'Unable to find an attachment with type ' . $p_type . ' and id ' . $p_file_id . ' .'); } case FTP: if (file_exists($t_diskfile)) { return mci_file_read_local($t_diskfile); } else { $ftp = file_ftp_connect(); file_ftp_get($ftp, $t_diskfile, $t_diskfile); file_ftp_disconnect($ftp); return mci_file_read_local($t_diskfile); } default: return $t_content; } }
/** * Set tag(s) for a given issue id * @param integer $p_issue_id Issue id. * @param array $p_tags Array of tags. * @param integer $p_user_id User id. * @return void */ function mci_tag_set_for_issue($p_issue_id, array $p_tags, $p_user_id) { $t_tag_ids_to_attach = array(); $t_tag_ids_to_detach = array(); $t_submitted_tag_ids = array(); $t_attached_tags = tag_bug_get_attached($p_issue_id); $t_attached_tag_ids = array(); foreach ($t_attached_tags as $t_attached_tag) { $t_attached_tag_ids[] = $t_attached_tag['id']; } foreach ($p_tags as $t_tag) { $t_tag = SoapObjectsFactory::unwrapObject($t_tag); $t_submitted_tag_ids[] = $t_tag['id']; if (in_array($t_tag['id'], $t_attached_tag_ids)) { continue; } else { $t_tag_ids_to_attach[] = $t_tag['id']; } } foreach ($t_attached_tag_ids as $t_attached_tag_id) { if (in_array($t_attached_tag_id, $t_submitted_tag_ids)) { continue; } else { $t_tag_ids_to_detach[] = $t_attached_tag_id; } } foreach ($t_tag_ids_to_detach as $t_tag_id) { if (access_has_bug_level(config_get('tag_detach_threshold'), $p_issue_id, $p_user_id)) { log_event(LOG_WEBSERVICE, 'detaching tag id \'' . $t_tag_id . '\' from issue \'' . $p_issue_id . '\''); tag_bug_detach($t_tag_id, $p_issue_id); } } foreach ($t_tag_ids_to_attach as $t_tag_id) { if (access_has_bug_level(config_get('tag_attach_threshold'), $p_issue_id, $p_user_id)) { log_event(LOG_WEBSERVICE, 'attaching tag id \'' . $t_tag_id . '\' to issue \'' . $p_issue_id . '\''); tag_bug_attach($t_tag_id, $p_issue_id); } } }