Example #1
0
/**
 * Get username, realname and email from for a set of given user ids
 * @param array $p_user_ids An array of user identifiers.
 * @return array
 */
function mci_account_get_array_by_ids(array $p_user_ids)
{
    $t_result = array();
    foreach ($p_user_ids as $t_user_id) {
        $t_result[] = mci_account_get_array_by_id($t_user_id);
    }
    return $t_result;
}
Example #2
0
/**
 * Given an id, this method returns the user.
 * When calling this method make sure that the caller has the right to retrieve
 * information about the target user.
 */
function mci_user_get($p_username, $p_password, $p_user_id)
{
    $t_user_data = array();
    // if user doesn't exist, then mci_account_get_array_by_id() will throw.
    $t_user_data['account_data'] = mci_account_get_array_by_id($p_user_id);
    $t_user_data['access_level'] = access_get_global_level($p_user_id);
    $t_user_data['timezone'] = user_pref_get_pref($p_user_id, 'timezone');
    return $t_user_data;
}
Example #3
0
/**
 * Retrieves all tags, unless the users 
 *
 * @param string   $p_username    The user's username
 * @param string   $p_password    The user's password
 * @param int      $p_page_number The page number to return data for
 * @param string   $p_per_page    The number of issues to return per page
 * @return array The tag data
 */
function mc_tag_get_all($p_username, $p_password, $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 (!access_has_global_level(config_get('tag_view_threshold'))) {
        return mci_soap_fault_access_denied($t_user_id, 'No rights to view tags');
    }
    if ($p_per_page == 0) {
        $p_per_page = 1;
    }
    $t_results = array();
    $t_total_results = tag_count('');
    foreach (tag_get_all('', $p_per_page, $p_per_page * ($p_page_number - 1)) as $t_tag_row) {
        $t_results[] = array('id' => $t_tag_row['id'], 'name' => $t_tag_row['name'], 'description' => $t_tag_row['description'], 'user_id' => mci_account_get_array_by_id($t_tag_row['user_id']), 'date_created' => SoapObjectsFactory::newDateTimeVar($t_tag_row['date_created']), 'date_updated' => SoapObjectsFactory::newDateTimeVar($t_tag_row['date_updated']));
    }
    return array('results' => $t_results, 'total_results' => $t_total_results);
}
Example #4
0
/**
 * Get all user defined issue filters for the given project.
 *
 * @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.
 * @return Array that represents a FilterDataArray structure
 */
function mc_filter_get($p_username, $p_password, $p_project_id)
{
    $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_result = array();
    foreach (mci_filter_db_get_available_queries($p_project_id, $t_user_id) as $t_filter_row) {
        $t_filter = array();
        $t_filter['id'] = $t_filter_row['id'];
        $t_filter['owner'] = mci_account_get_array_by_id($t_filter_row['user_id']);
        $t_filter['project_id'] = $t_filter_row['project_id'];
        $t_filter['is_public'] = $t_filter_row['is_public'];
        $t_filter['name'] = $t_filter_row['name'];
        $t_filter['filter_string'] = $t_filter_row['filter_string'];
        $t_result[] = $t_filter;
    }
    return $t_result;
}
Example #5
0
/**
 * Returns all the profiles for the user, including the global ones
 *
 * @param string  $p_username    The user's username.
 * @param string  $p_password    The user's password.
 * @param integer $p_page_number Page number.
 * @param integer $p_per_page    Results per page.
 * @return mixed
 */
function mc_user_profiles_get_all($p_username, $p_password, $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)) {
        return mci_soap_fault_access_denied($t_user_id);
    }
    $t_results = array();
    $t_start = max(array(0, $p_page_number - 1)) * $p_per_page;
    foreach (profile_get_all_for_user($t_user_id) as $t_profile_row) {
        $t_result = array('id' => $t_profile_row['id'], 'description' => $t_profile_row['description'], 'os' => $t_profile_row['os'], 'os_build' => $t_profile_row['os_build'], 'platform' => $t_profile_row['platform']);
        if ($t_profile_row['user_id'] != 0) {
            $t_result['user_id'] = mci_account_get_array_by_id($t_profile_row['user_id']);
        }
        $t_results[] = $t_result;
    }
    # the profile_api does not implement pagination in the backend, so we emulate it here
    # we can always push the pagination in the database, but this seems unlikely in the
    # near future, as the number of profiles is expected to be small
    $t_paged_results = array_slice($t_results, $t_start, $p_per_page);
    return array('total_results' => count($t_results), 'results' => $t_paged_results);
}
Example #6
0
/**
 * Retrieves all tags, unless the users
 *
 * @param string   $p_username    The user's username
 * @param string   $p_password    The user's password
 * @param int      $p_page_number The page number to return data for
 * @param string   $p_per_page    The number of issues to return per page
 * @return array The tag data
 */
function mc_tag_get_all($p_username, $p_password, $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 (!access_has_global_level(config_get('tag_view_threshold'))) {
        return mci_soap_fault_access_denied($t_user_id, 'No rights to view tags');
    }
    if ($p_per_page == 0) {
        $p_per_page = 1;
    }
    $t_results = array();
    $t_total_results = tag_count('');
    $t_tags = tag_get_all('', $p_per_page, $p_per_page * ($p_page_number - 1));
    while ($t_tag = db_fetch_array($t_tags)) {
        $t_tag['user_id'] = mci_account_get_array_by_id($t_tag['user_id']);
        $t_tag['date_created'] = SoapObjectsFactory::newDateTimeVar($t_tag['date_created']);
        $t_tag['date_updated'] = SoapObjectsFactory::newDateTimeVar($t_tag['date_updated']);
        $t_results[] = $t_tag;
    }
    log_event(LOG_WEBSERVICE, "retrieved " . count($t_results) . "/{$t_total_results} tags (page #{$p_page_number})");
    return array('results' => $t_results, 'total_results' => $t_total_results);
}
Example #7
0
/**
 * Get appropriate users assigned to a project by access level.
 *
 * @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 users for.
 * @param integer $p_access Minimum access level.
 * @return Array  representing a ProjectAttachmentDataArray structure.
 */
function mc_project_get_users($p_username, $p_password, $p_project_id, $p_access)
{
    $t_user_id = mci_check_login($p_username, $p_password);
    if ($t_user_id === false) {
        return mci_soap_fault_login_failed();
    }
    $t_users = array();
    $t_users = project_get_all_user_rows($p_project_id, $p_access);
    # handles ALL_PROJECTS case
    $t_display = array();
    $t_sort = array();
    $t_show_realname = ON == config_get('show_realname');
    $t_sort_by_last_name = ON == config_get('sort_by_last_name');
    foreach ($t_users as $t_user) {
        $t_user_name = string_attribute($t_user['username']);
        $t_sort_name = strtolower($t_user_name);
        if ($t_show_realname && $t_user['realname'] != "") {
            $t_user_name = string_attribute($t_user['realname']);
            if ($t_sort_by_last_name) {
                $t_sort_name_bits = explode(' ', strtolower($t_user_name), 2);
                $t_sort_name = (isset($t_sort_name_bits[1]) ? $t_sort_name_bits[1] . ', ' : '') . $t_sort_name_bits[0];
            } else {
                $t_sort_name = strtolower($t_user_name);
            }
        }
        $t_display[] = $t_user_name;
        $t_sort[] = $t_sort_name;
    }
    array_multisort($t_sort, SORT_ASC, SORT_STRING, $t_users, $t_display);
    $t_result = array();
    for ($i = 0; $i < count($t_sort); $i++) {
        $t_row = $t_users[$i];
        // This is not very performant - But we have to assure that the data returned is exactly
        // the same as the data that comes with an issue (test for equality - $t_row[] does not
        // contain email fields).
        $t_result[] = mci_account_get_array_by_id($t_row['id']);
    }
    return $t_result;
}
Example #8
0
/**
 * Returns an array for SOAP encoding from a BugData object
 *
 * @param BugData $p_issue_data A BugData object to process.
 * @param integer $p_user_id    A valid user identifier.
 * @param string  $p_lang       A valid language string.
 * @return array The issue as an array
 */
function mci_issue_data_as_array(BugData $p_issue_data, $p_user_id, $p_lang)
{
    $t_id = $p_issue_data->id;
    $t_issue = array();
    $t_issue['id'] = $t_id;
    $t_issue['view_state'] = mci_enum_get_array_by_id($p_issue_data->view_state, 'view_state', $p_lang);
    $t_issue['last_updated'] = SoapObjectsFactory::newDateTimeVar($p_issue_data->last_updated);
    $t_issue['project'] = mci_project_as_array_by_id($p_issue_data->project_id);
    $t_issue['category'] = mci_get_category($p_issue_data->category_id);
    $t_issue['priority'] = mci_enum_get_array_by_id($p_issue_data->priority, 'priority', $p_lang);
    $t_issue['severity'] = mci_enum_get_array_by_id($p_issue_data->severity, 'severity', $p_lang);
    $t_issue['status'] = mci_enum_get_array_by_id($p_issue_data->status, 'status', $p_lang);
    $t_issue['reporter'] = mci_account_get_array_by_id($p_issue_data->reporter_id);
    $t_issue['summary'] = mci_sanitize_xml_string($p_issue_data->summary);
    $t_issue['version'] = mci_null_if_empty($p_issue_data->version);
    $t_issue['build'] = mci_null_if_empty($p_issue_data->build);
    $t_issue['profile_id'] = mci_null_if_empty($p_issue_data->profile_id);
    $t_issue['platform'] = mci_null_if_empty($p_issue_data->platform);
    $t_issue['os'] = mci_null_if_empty($p_issue_data->os);
    $t_issue['os_build'] = mci_null_if_empty($p_issue_data->os_build);
    $t_issue['reproducibility'] = mci_enum_get_array_by_id($p_issue_data->reproducibility, 'reproducibility', $p_lang);
    $t_issue['date_submitted'] = SoapObjectsFactory::newDateTimeVar($p_issue_data->date_submitted);
    $t_issue['sticky'] = $p_issue_data->sticky;
    $t_issue['sponsorship_total'] = $p_issue_data->sponsorship_total;
    if (!empty($p_issue_data->handler_id)) {
        $t_issue['handler'] = mci_account_get_array_by_id($p_issue_data->handler_id);
    }
    $t_issue['projection'] = mci_enum_get_array_by_id($p_issue_data->projection, 'projection', $p_lang);
    $t_issue['eta'] = mci_enum_get_array_by_id($p_issue_data->eta, 'eta', $p_lang);
    $t_issue['resolution'] = mci_enum_get_array_by_id($p_issue_data->resolution, 'resolution', $p_lang);
    $t_issue['fixed_in_version'] = mci_null_if_empty($p_issue_data->fixed_in_version);
    $t_issue['target_version'] = mci_null_if_empty($p_issue_data->target_version);
    $t_issue['description'] = mci_sanitize_xml_string(bug_get_text_field($t_id, 'description'));
    $t_steps_to_reproduce = bug_get_text_field($t_id, 'steps_to_reproduce');
    $t_issue['steps_to_reproduce'] = mci_null_if_empty(mci_sanitize_xml_string($t_steps_to_reproduce));
    $t_additional_information = bug_get_text_field($t_id, 'additional_information');
    $t_issue['additional_information'] = mci_null_if_empty(mci_sanitize_xml_string($t_additional_information));
    $t_issue['due_date'] = SoapObjectsFactory::newDateTimeVar($p_issue_data->due_date);
    $t_issue['attachments'] = mci_issue_get_attachments($p_issue_data->id);
    $t_issue['relationships'] = mci_issue_get_relationships($p_issue_data->id, $p_user_id);
    $t_issue['notes'] = mci_issue_get_notes($p_issue_data->id);
    $t_issue['custom_fields'] = mci_issue_get_custom_fields($p_issue_data->id);
    $t_issue['tags'] = mci_issue_get_tags_for_bug_id($p_issue_data->id, $p_user_id);
    $t_issue['monitors'] = mci_account_get_array_by_ids(bug_get_monitors($p_issue_data->id));
    return $t_issue;
}
/**
 * Get all issues matching the specified filter.
 *
 * @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_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_issues($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);
    $t_lang = mci_get_user_lang($t_user_id);
    if ($t_user_id === false) {
        return new soap_fault('Client', '', 'Access Denied');
    }
    if (!mci_has_readonly_access($t_user_id, $p_project_id)) {
        return new soap_fault('Client', '', 'Access Denied');
    }
    $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 new soap_fault('Server', '', 'Invalid Filter');
    }
    $t_filter = unserialize($t_filter_detail[1]);
    $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);
    foreach ($t_rows as $t_issue_data) {
        $t_id = $t_issue_data['id'];
        $t_issue = array();
        $t_issue['id'] = $t_id;
        $t_issue['view_state'] = mci_enum_get_array_by_id($t_issue_data['view_state'], 'view_state', $t_lang);
        $t_issue['last_updated'] = timestamp_to_iso8601($t_issue_data['last_updated']);
        $t_issue['project'] = mci_project_as_array_by_id($t_issue_data['project_id']);
        $t_issue['category'] = mci_null_if_empty($t_issue_data['category']);
        $t_issue['priority'] = mci_enum_get_array_by_id($t_issue_data['priority'], 'priority', $t_lang);
        $t_issue['severity'] = mci_enum_get_array_by_id($t_issue_data['severity'], 'severity', $t_lang);
        $t_issue['status'] = mci_enum_get_array_by_id($t_issue_data['status'], 'status', $t_lang);
        $t_issue['reporter'] = mci_account_get_array_by_id($t_issue_data['reporter_id']);
        $t_issue['summary'] = $t_issue_data['summary'];
        $t_issue['version'] = mci_null_if_empty($t_issue_data['version']);
        $t_issue['build'] = mci_null_if_empty($t_issue_data['build']);
        $t_issue['platform'] = mci_null_if_empty($t_issue_data['platform']);
        $t_issue['os'] = mci_null_if_empty($t_issue_data['os']);
        $t_issue['os_build'] = mci_null_if_empty($t_issue_data['os_build']);
        $t_issue['reproducibility'] = mci_enum_get_array_by_id($t_issue_data['reproducibility'], 'reproducibility', $t_lang);
        $t_issue['date_submitted'] = timestamp_to_iso8601($t_issue_data['date_submitted']);
        $t_issue['sponsorship_total'] = $t_issue_data['sponsorship_total'];
        if (!empty($t_issue_data['handler_id'])) {
            $t_issue['handler'] = mci_account_get_array_by_id($t_issue_data['handler_id']);
        }
        $t_issue['projection'] = mci_enum_get_array_by_id($t_issue_data['projection'], 'projection', $t_lang);
        $t_issue['eta'] = mci_enum_get_array_by_id($t_issue_data['eta'], 'eta', $t_lang);
        $t_issue['resolution'] = mci_enum_get_array_by_id($t_issue_data['resolution'], 'resolution', $t_lang);
        $t_issue['fixed_in_version'] = mci_null_if_empty($t_issue_data['fixed_in_version']);
        $t_issue['description'] = bug_get_text_field($t_id, 'description');
        $t_steps_to_reproduce = bug_get_text_field($t_id, 'steps_to_reproduce');
        $t_issue['steps_to_reproduce'] = mci_null_if_empty($t_steps_to_reproduce);
        $t_additional_information = bug_get_text_field($t_id, 'additional_information');
        $t_issue['additional_information'] = mci_null_if_empty($t_additional_information);
        $t_issue['attachments'] = mci_issue_get_attachments($t_issue_data['id']);
        $t_issue['relationships'] = mci_issue_get_relationships($t_issue_data['id'], $t_user_id);
        $t_issue['notes'] = mci_issue_get_notes($t_issue_data['id']);
        $t_issue['custom_fields'] = mci_issue_get_custom_fields($t_issue_data['id']);
        $t_result[] = $t_issue;
    }
    return $t_result;
}
Example #10
0
/**
 * Get all visible notes for a specific issue
 *
 * @param integer $p_issue_id  The id of the issue to retrieve the notes for
 * @return Array that represents an IssueNoteData structure
 */
function mci_issue_get_notes($p_issue_id)
{
    $t_user_id = auth_get_current_user_id();
    $t_lang = mci_get_user_lang($t_user_id);
    $t_project_id = bug_get_field($p_issue_id, 'project_id');
    $t_user_access_level = user_get_access_level($t_user_id, $t_project_id);
    $t_user_bugnote_order = 'ASC';
    // always get the notes in ascending order for consistency to the calling application.
    $t_result = array();
    foreach (bugnote_get_all_visible_bugnotes($p_issue_id, $t_user_access_level, $t_user_bugnote_order, 0) as $t_value) {
        $t_bugnote = array();
        $t_bugnote['id'] = $t_value->id;
        $t_bugnote['reporter'] = mci_account_get_array_by_id($t_value->reporter_id);
        $t_bugnote['date_submitted'] = timestamp_to_iso8601($t_value->date_submitted);
        $t_bugnote['last_modified'] = timestamp_to_iso8601($t_value->last_modified);
        $t_bugnote['text'] = $t_value->note;
        $t_bugnote['view_state'] = mci_enum_get_array_by_id($t_value->view_state, 'view_state', $t_lang);
        $t_result[] = $t_bugnote;
    }
    return $t_result;
}