コード例 #1
0
ファイル: mc_config_api.php プロジェクト: fur81/zofaxiopeu
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);
}
コード例 #2
0
/**
 * 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);
}
コード例 #3
0
ファイル: mc_api.php プロジェクト: elmarculino/mantisbt
/**
 * 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);
}
コード例 #4
0
ファイル: mc_tag_api.php プロジェクト: fur81/zofaxiopeu
/**
 * 
 * Deletes a tag
 * 
 * @param string   $p_username        The user's username
 * @param string   $p_password        The user's password * @param unknown_type $p_tag_id
 * @param int      $p_tag_id          The id of the tag
 * @return soap_fault|boolean
 */
function mc_tag_delete($p_username, $p_password, $p_tag_id)
{
    $t_user_id = mci_check_login($p_username, $p_password);
    if ($t_user_id === false) {
        return mci_soap_fault_login_failed();
    }
    if (!access_has_global_level(config_get('tag_edit_threshold'))) {
        return mci_soap_fault_access_denied($t_user_id);
    }
    if (!tag_exists($p_tag_id)) {
        return SoapObjectsFactory::newSoapFault('Client', 'No tag with id ' . $p_tag_id);
    }
    return tag_delete($p_tag_id);
}
コード例 #5
0
ファイル: mc_issue_api.php プロジェクト: elmarculino/mantisbt
/**
 * Submit a new relationship.
 *
 * @param string   $p_username     The name of the user trying to add a note to an issue.
 * @param string   $p_password     The password of the user.
 * @param integer  $p_issue_id     The id of the issue of the source issue.
 * @param stdClass $p_relationship The relationship to add (RelationshipData SOAP object).
 * @return integer The id of the added relationship.
 */
function mc_issue_relationship_add($p_username, $p_password, $p_issue_id, stdClass $p_relationship)
{
    global $g_project_override;
    $t_user_id = mci_check_login($p_username, $p_password);
    $p_relationship = SoapObjectsFactory::unwrapObject($p_relationship);
    $t_dest_issue_id = $p_relationship['target_id'];
    $t_rel_type = SoapObjectsFactory::unwrapObject($p_relationship['type']);
    if ($t_user_id === false) {
        return mci_soap_fault_login_failed();
    }
    $t_project_id = bug_get_field($p_issue_id, 'project_id');
    $g_project_override = $t_project_id;
    if (!mci_has_readwrite_access($t_user_id, $t_project_id)) {
        return mci_soap_fault_access_denied($t_user_id);
    }
    # user has access to update the bug...
    if (!access_has_bug_level(config_get('update_bug_threshold'), $p_issue_id, $t_user_id)) {
        return mci_soap_fault_access_denied($t_user_id, 'Active user does not have access level required to add a relationship to this issue');
    }
    # source and destination bugs are the same bug...
    if ($p_issue_id == $t_dest_issue_id) {
        return SoapObjectsFactory::newSoapFault('Client', 'An issue can\'t be related to itself.');
    }
    # the related bug exists...
    if (!bug_exists($t_dest_issue_id)) {
        return SoapObjectsFactory::newSoapFault('Client', 'Issue \'' . $t_dest_issue_id . '\' not found.');
    }
    # bug is not read-only...
    if (bug_is_readonly($p_issue_id)) {
        return mci_soap_fault_access_denied($t_user_id, 'Issue \'' . $p_issue_id . '\' is readonly');
    }
    # user can access to the related bug at least as viewer...
    if (!access_has_bug_level(config_get('view_bug_threshold', null, null, $t_project_id), $t_dest_issue_id, $t_user_id)) {
        return mci_soap_fault_access_denied($t_user_id, 'The issue \'' . $t_dest_issue_id . '\' requires higher access level');
    }
    $t_old_id_relationship = relationship_same_type_exists($p_issue_id, $t_dest_issue_id, $t_rel_type['id']);
    if ($t_old_id_relationship == 0) {
        log_event(LOG_WEBSERVICE, 'adding relationship type \'' . $t_rel_type['id'] . '\' between \'' . $p_issue_id . '\' and \'' . $t_dest_issue_id . '\'');
        relationship_add($p_issue_id, $t_dest_issue_id, $t_rel_type['id']);
        # The above function call into MantisBT does not seem to return a valid BugRelationshipData object.
        # So we call db_insert_id in order to find the id of the created relationship.
        $t_relationship_id = db_insert_id(db_get_table('bug_relationship'));
        # Add log line to the history (both bugs)
        history_log_event_special($p_issue_id, BUG_ADD_RELATIONSHIP, $t_rel_type['id'], $t_dest_issue_id);
        history_log_event_special($t_dest_issue_id, BUG_ADD_RELATIONSHIP, relationship_get_complementary_type($t_rel_type['id']), $p_issue_id);
        # update bug last updated for both bugs
        bug_update_date($p_issue_id);
        bug_update_date($t_dest_issue_id);
        # send email notification to the users addressed by both the bugs
        email_relationship_added($p_issue_id, $t_dest_issue_id, $t_rel_type['id']);
        email_relationship_added($t_dest_issue_id, $p_issue_id, relationship_get_complementary_type($t_rel_type['id']));
        return $t_relationship_id;
    } else {
        return SoapObjectsFactory::newSoapFault('Client', 'Relationship already exists.');
    }
}
コード例 #6
0
/**
 * 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;
}
コード例 #7
0
/**
 * 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;
}
コード例 #8
0
/**
 * 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;
    }
}
コード例 #9
0
/**
 * Log a checkin event on the issue
 *
 * @param string $p_username  The name of the user trying to access the issue.
 * @param string $p_password  The password of the user.
 * @param integer $p_issue_id The id of the issue to log a checkin.
 * @param string $p_comment   The comment to add
 * @param boolean $p_fixed    True if the issue is to be set to fixed
 * @return boolean  true success, false otherwise.
 */
function mc_issue_checkin($p_username, $p_password, $p_issue_id, $p_comment, $p_fixed)
{
    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 (!bug_exists($p_issue_id)) {
        return SoapObjectsFactory::newSoapFault('Client', "Issue '{$p_issue_id}' not found.");
    }
    $t_project_id = bug_get_field($p_issue_id, 'project_id');
    $g_project_override = $t_project_id;
    if (!mci_has_readwrite_access($t_user_id, $t_project_id)) {
        return mci_soap_fault_access_denied($t_user_id);
    }
    helper_call_custom_function('checkin', array($p_issue_id, $p_comment, '', '', $p_fixed));
    return true;
}