View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0010349 | mantisbt | api soap | public | 2009-04-20 16:18 | 2014-01-23 17:51 |
Reporter | Wepl | Assigned To | |||
Priority | normal | Severity | feature | Reproducibility | N/A |
Status | confirmed | Resolution | open | ||
Product Version | 1.2.0a3 | ||||
Summary | 0010349: additions to api soap, user add, sub projects | ||||
Description | for importing a lot of bugs collected in plain text files the api soap should be used to get them info mantisbt this is a request that the changes made could be included into next mantisbt release the following changes were made (with files modified):
the attached file contains a diff, a list of changes and all changed files derived from release 1.2.0a3 | ||||
Tags | patch | ||||
Attached Files | mantisbt-1.2.1-wepl-10349.diff (16,253 bytes)
diff -rU5 mantisbt-1.2.1/api/soap/mantisconnect.php mantisbt-1.2.1-wepl/api/soap/mantisconnect.php --- mantisbt-1.2.1/api/soap/mantisconnect.php 2010-04-23 20:28:34.000000000 +0200 +++ mantisbt-1.2.1-wepl/api/soap/mantisconnect.php 2010-05-01 20:11:00.000000000 +0200 @@ -82,11 +82,12 @@ '', array( 'id' => array( 'name' => 'id', 'type' => 'xsd:integer', 'minOccurs' => '0'), 'name' => array( 'name' => 'name', 'type' => 'xsd:string', 'minOccurs' => '0'), 'real_name' => array( 'name' => 'real_name', 'type' => 'xsd:string', 'minOccurs' => '0'), - 'email' => array( 'name' => 'email', 'type' => 'xsd:string', 'minOccurs' => '0') + 'email' => array( 'name' => 'email', 'type' => 'xsd:string', 'minOccurs' => '0'), + 'access' => array( 'name' => 'access', 'type' => 'xsd:integer','minOccurs' => '0') ) ); ### AccountDataArray $l_oServer->wsdl->addComplexType( @@ -347,10 +348,11 @@ 'struct', 'all', '', array( 'id' => array( 'name' => 'id', 'type' => 'xsd:integer', 'minOccurs' => '0' ), + 'parent_id' => array( 'name' => 'parent_id', 'type' => 'xsd:integer', 'minOccurs' => '0' ), 'name' => array( 'name' => 'name', 'type' => 'xsd:string', 'minOccurs' => '0' ), 'status' => array( 'name' => 'status', 'type' => 'tns:ObjectRef', 'minOccurs' => '0' ), 'enabled' => array( 'name' => 'enabled', 'type' => 'xsd:boolean', 'minOccurs' => '0' ), 'view_state' => array( 'name' => 'view_state', 'type' => 'tns:ObjectRef', 'minOccurs' => '0' ), 'access_min' => array( 'name' => 'access_min', 'type' => 'tns:ObjectRef', 'minOccurs' => '0' ), @@ -960,10 +962,30 @@ false, false, false, 'Get the data for the specified issue attachment.' ); ### +### PUBLIC METHODS (defined in mc_account_api.php) +### + +### mc_account_add +$l_oServer->register( 'mc_account_add', + array( + 'username' => 'xsd:string', + 'password' => 'xsd:string', + 'account' => 'tns:AccountData', + 'account_password' => 'xsd:string' + ), + array( + 'return' => 'xsd:integer' + ), + $t_namespace, + false, false, false, + 'Add a new user to the tracker (must have admin privileges)' +); + +### ### PUBLIC METHODS (defined in mc_project_api.php) ### ### mc_project_add $l_oServer->register( 'mc_project_add', @@ -1027,10 +1049,27 @@ $t_namespace, false, false, false, 'Get the issue headers that match the specified project id and paging details.' ); +### mc_project_add_user +$l_oServer->register( 'mc_project_add_user', + array( + 'username' => 'xsd:string', + 'password' => 'xsd:string', + 'project_id' => 'xsd:integer', + 'user_id' => 'xsd:integer', + 'access' => 'xsd:integer' + ), + array( + 'return' => 'xsd:integer' + ), + $t_namespace, + false, false, false, + 'Add a user to a project with access level.' +); + ### mc_project_get_users $l_oServer->register( 'mc_project_get_users', array( 'username' => 'xsd:string', 'password' => 'xsd:string', @@ -1057,10 +1096,24 @@ $t_namespace, false, false, false, 'Get the list of projects that are accessible to the logged in user.' ); +### mc_projects_get_names_user_accessible +$l_oServer->register( 'mc_projects_get_names_user_accessible', + array( + 'username' => 'xsd:string', + 'password' => 'xsd:string' + ), + array( + 'return' => 'tns:ProjectDataArray' + ), + $t_namespace, + false, false, false, + 'Get the list of name/id of projects that are accessible to the logged in user.' +); + ### mc_project_get_categories $l_oServer->register( 'mc_project_get_categories', array( 'username' => 'xsd:string', 'password' => 'xsd:string', diff -rU5 mantisbt-1.2.1/api/soap/mc_account_api.php mantisbt-1.2.1-wepl/api/soap/mc_account_api.php --- mantisbt-1.2.1/api/soap/mc_account_api.php 2010-04-23 20:28:33.000000000 +0200 +++ mantisbt-1.2.1-wepl/api/soap/mc_account_api.php 2010-05-01 20:11:00.000000000 +0200 @@ -24,5 +24,46 @@ $t_result['email'] = $t_dummy; } } return $t_result; } + +/** +* Add a new user. +* +* @param string $p_username The name of the user trying to create an account. +* @param string $p_password The password of the user. +* @param Array $p_user A new AccountData structure +* @return integer the new users's users_id +*/ +function mc_account_add( $p_username, $p_password, $p_user, $p_pass ) { + $t_user_id = mci_check_login( $p_username, $p_password ); + if ( $t_user_id === false ) { + return new soap_fault( 'Client', '', 'Access Denied', 'Username/password combination was incorrect'); + } + + if ( !mci_has_administrator_access( $t_user_id ) ) { + return new soap_fault( 'Client', '', 'Access Denied', 'User does not have administrator access'); + } + + extract( $p_user, EXTR_PREFIX_ALL, 'v'); + + // validate user object + if ( is_blank($v_name) ) return new soap_fault('Client', '', 'Mandatory field "name" was missing'); + if ( is_blank($v_real_name) ) return new soap_fault('Client', '', 'Mandatory field "real_name" was missing'); + if ( is_blank($v_email) ) return new soap_fault('Client', '', 'Mandatory field "email" was missing'); + + if ( !user_is_name_valid( $v_name ) ) return new soap_fault( 'Client', '', 'user name invalid'); + if ( !user_is_name_unique( $v_name ) ) return new soap_fault( 'Client', '', 'user name exists'); + if ( !user_is_realname_valid( $v_real_name ) ) return new soap_fault( 'Client', '', 'real name invalid'); + + // set defaults + if ( is_null( $v_access ) ) $v_access = VIEWER; + + // create user account and get it's id + user_create($v_name, $p_pass, $v_email, $v_access, false, true, $v_real_name); + $t_user_id = user_get_id_by_name($v_name); + + // return id of new user back to caller + return $t_user_id; +} + diff -rU5 mantisbt-1.2.1/api/soap/mc_api.php mantisbt-1.2.1-wepl/api/soap/mc_api.php --- mantisbt-1.2.1/api/soap/mc_api.php 2010-04-23 20:28:34.000000000 +0200 +++ mantisbt-1.2.1-wepl/api/soap/mc_api.php 2010-05-01 20:11:00.000000000 +0200 @@ -215,10 +215,24 @@ } return $t_result; } +# Gets the name/id of all sub-projects that are accessible to the specified user / project. +function mci_user_get_names_accessible_subprojects( $p_user_id, $p_parent_project_id ) { + $t_result = array(); + foreach( user_get_accessible_subprojects( $p_user_id, $p_parent_project_id ) as $t_subproject_id ) { + $t_subproject_row = project_cache_row( $t_subproject_id ); + $t_subproject = array(); + $t_subproject['id'] = $t_subproject_id; + $t_subproject['name'] = $t_subproject_row['name']; + $t_subproject['subprojects'] = mci_user_get_names_accessible_subprojects( $p_user_id, $t_subproject_id ); + $t_result[] = $t_subproject; + } + return $t_result; +} + function translate_category_name_to_id( $p_category_name, $p_project_id ) { if ( !isset( $p_category_name ) ) { return 0; } diff -rU5 mantisbt-1.2.1/api/soap/mc_issue_api.php mantisbt-1.2.1-wepl/api/soap/mc_issue_api.php --- mantisbt-1.2.1/api/soap/mc_issue_api.php 2010-04-23 20:28:34.000000000 +0200 +++ mantisbt-1.2.1-wepl/api/soap/mc_issue_api.php 2010-05-01 20:11:00.000000000 +0200 @@ -515,11 +515,12 @@ return new soap_fault( 'Client', '', "Category '" . $p_issue['category'] . "' not found for project '$t_project_id'." ); } } if ( isset( $p_issue['version'] ) && !is_blank( $p_issue['version'] ) && !version_get_id( $p_issue['version'], $t_project_id ) ) { - $t_version = $p_issue['version']; + $t_date_submitted = $p_issue['date_submitted']; + $t_version = isset($p_issue['version']) ? $p_issue['version'] : ''; $t_error_when_version_not_found = config_get( 'mc_error_when_version_not_found' ); if( $t_error_when_version_not_found == ON ) { $t_project_name = project_get_name( $t_project_id ); return new soap_fault( 'Client', '', "Version '$t_version' does not exist in project '$t_project_name'." ); @@ -581,11 +582,14 @@ $t_bug_data->additional_information = isset( $p_issue['additional_information'] ) ? $p_issue['additional_information'] : ''; # submit the issue $t_issue_id = $t_bug_data->create(); - mci_issue_set_custom_fields( $t_issue_id, $p_issue['custom_fields'], false ); + $t_fault = mci_issue_set_custom_fields( $t_issue_id, $p_issue['custom_fields'], false ); + if ($t_fault) { + return new soap_fault( 'Client', '', "mci_issue_set_custom_fields failed" . $t_fault ); + } if( isset( $t_notes ) && is_array( $t_notes ) ) { foreach( $t_notes as $t_note ) { if( isset( $t_note['view_state'] ) ) { $t_view_state = $t_note['view_state']; @@ -725,11 +729,11 @@ $t_bug_data->reproducibility = $t_reproducibility_id; $t_bug_data->status = $t_status_id; $t_bug_data->resolution = $t_resolution_id; $t_bug_data->projection = $t_projection_id; $t_bug_data->category_id = $t_category_id; - $t_bug_data->date_submitted = isset( $v_date_submitted ) ? $v_date_submitted : ''; + $t_bug_data->date_submitted = $t_date_submitted; $t_bug_data->last_updated = isset( $v_last_updated ) ? $v_last_updated : ''; $t_bug_data->eta = $t_eta_id; $t_bug_data->os = $t_os; $t_bug_data->os_build = $t_os_build; $t_bug_data->platform = $t_platform; diff -rU5 mantisbt-1.2.1/api/soap/mc_project_api.php mantisbt-1.2.1-wepl/api/soap/mc_project_api.php --- mantisbt-1.2.1/api/soap/mc_project_api.php 2010-04-23 20:28:34.000000000 +0200 +++ mantisbt-1.2.1-wepl/api/soap/mc_project_api.php 2010-05-01 20:11:00.000000000 +0200 @@ -72,10 +72,42 @@ return $t_result; } /** + * Get (only) the id and name for all projects accessible by the given user. + * + * @param string $p_username The name of the user trying to access the project list. + * @param string $p_password The password of the user. + * @return Array suitable to be converted into a ProjectDataArray + */ +function mc_projects_get_names_user_accessible( $p_username, $p_password ) { + $t_user_id = mci_check_login( $p_username, $p_password ); + if( $t_user_id === false ) { + return new soap_fault( 'Client', '', 'Access Denied' ); + } + + if( !mci_has_readonly_access( $t_user_id ) ) { + return new soap_fault( 'Client', '', 'Access Denied' ); + } + + $t_lang = mci_get_user_lang( $t_user_id ); + + $t_result = array(); + foreach( user_get_accessible_projects( $t_user_id ) as $t_project_id ) { + $t_project_row = project_cache_row( $t_project_id ); + $t_project = array(); + $t_project['id'] = $t_project_id; + $t_project['name'] = $t_project_row['name']; + $t_project['subprojects'] = mci_user_get_names_accessible_subprojects( $t_user_id, $t_project_id, $t_lang ); + $t_result[] = $t_project; + } + + return $t_result; +} + +/** * Get all categories of a project. * * @param string $p_username The name of the user trying to access the categories. * @param string $p_password The password of the user. * @param integer $p_project_id The id of the project to retrieve the categories for. @@ -616,20 +648,42 @@ $t_inherit_global = $p_project['inherit_global']; } else { $t_inherit_global = true; } + if ( isset( $p_project['parent_id'] ) ) { + $t_parent_id = $p_project['parent_id']; + if ( !project_exists( $t_parent_id ) ) { + return new soap_fault( 'Client', '', 'Parent project does not exist', ''); + } + } else { + $t_parent_id = false; + } + // check to make sure project doesn't already exist if( !project_is_name_unique( $t_name ) ) { return new soap_fault( 'Client', '', 'Project name exists', 'The project name you attempted to add exists already' ); } $t_project_status = mci_get_project_status_id( $t_status ); $t_project_view_state = mci_get_project_view_state_id( $t_view_state ); - // project_create returns the new project's id, spit that out to webservice caller - return project_create( $t_name, $t_description, $t_project_status, $t_project_view_state, $t_file_path, $t_enabled, $t_inherit_global ); + // project_create returns the new project's id + $t_project_id = project_create( $t_name, $t_description, $t_project_status, $t_project_view_state, $t_file_path, $t_enabled, $t_inherit_global ); + + // link new project to a parent project, if one has been specified + if ( $t_parent_id ) { + // link to parent + project_hierarchy_add($t_project_id, $t_parent_id); + + // copy custom fields from parent + project_copy_custom_fields($t_project_id, $t_parent_id); + } + + // return id of new project back to caller + return $t_project_id; + } /** * Delete a project. * @@ -704,10 +758,42 @@ return $t_result; } /** + * Link a user to a project with a specified access level. + * + * @param string $p_username The name of the user trying to add the user (must be administrator) + * @param string $p_password The password of the user. + * @param integer $p_project_id The id of the project to link user to. + * @param integer $p_user_id The id of the user to link to the project. + * @param integer $p_access access level. + * @return bool returns true or false depending on the success of the action + */ +function mc_project_add_user( $p_username, $p_password, $p_project_id, $p_user_id, $p_access ) { + $t_user_id = mci_check_login( $p_username, $p_password ); + if ( $t_user_id === false ) { + return new soap_fault( 'Client', '', 'Access Denied' ); + } + if ( !mci_has_administrator_access( $t_user_id ) ) { + return new soap_fault( 'Client', '', 'Access Denied', 'User does not have administrator access'); + } + + if ( !project_exists( $p_project_id ) ) { + return new soap_fault( 'Client', '', "Project '$p_project_id' does not exist." ); + } + if ( !user_exists( $p_user_id ) ) { + return new soap_fault( 'Client', '', "User '$p_user_id' does not exist." ); + } + + // add the user to the project + $t_status = project_set_user_access( $p_project_id, $p_user_id, $p_access ); + + return $t_status; +} + +/** * 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. diff -rU5 mantisbt-1.2.1/core/bug_api.php mantisbt-1.2.1-wepl/core/bug_api.php --- mantisbt-1.2.1/core/bug_api.php 2010-04-23 20:28:34.000000000 +0200 +++ mantisbt-1.2.1-wepl/core/bug_api.php 2010-05-01 20:11:00.000000000 +0200 @@ -345,10 +345,12 @@ $t_status = config_get( 'bug_assigned_status' ); } else { $t_status = $this->status; } + $c_date_submitted = !is_blank( $this->date_submitted ) ? $this->date_submitted : db_now(); + # Insert the rest of the data $query = "INSERT INTO $t_bug_table ( project_id,reporter_id, handler_id,duplicate_id, priority,severity, reproducibility,status, resolution,projection, category_id,date_submitted, @@ -364,11 +366,11 @@ " . db_param() . ',' . db_param() . ',' . db_param() . ',' . db_param() . ", " . db_param() . ',' . db_param() . ',' . db_param() . ',' . db_param() . ", " . db_param() . ',' . db_param() . ',' . db_param() . ',' . db_param() . ", " . db_param() . ',' . db_param() . ',' . db_param() . ',' . db_param() . ')'; - db_query_bound( $query, Array( $this->project_id, $this->reporter_id, $this->handler_id, $this->duplicate_id, $this->priority, $this->severity, $this->reproducibility, $t_status, $this->resolution, $this->projection, $this->category_id, db_now(), db_now(), $this->eta, $t_text_id, $this->os, $this->os_build, $this->platform, $this->version, $this->build, $this->profile_id, $this->summary, $this->view_state, $this->sponsorship_total, $this->sticky, $this->fixed_in_version, $this->target_version, $this->due_date ) ); + db_query_bound( $query, Array( $this->project_id, $this->reporter_id, $this->handler_id, $this->duplicate_id, $this->priority, $this->severity, $this->reproducibility, $t_status, $this->resolution, $this->projection, $this->category_id, $c_date_submitted, db_now(), $this->eta, $t_text_id, $this->os, $this->os_build, $this->platform, $this->version, $this->build, $this->profile_id, $this->summary, $this->view_state, $this->sponsorship_total, $this->sticky, $this->fixed_in_version, $this->target_version, $this->due_date ) ); $this->id = db_insert_id( $t_bug_table ); # log new bug history_log_event_special( $this->id, NEW_BUG ); mantisbt-1.2.5-wepl-10349.diff (16,323 bytes)
diff -rU5 mantisbt-1.2.5/api/soap/mantisconnect.php mantisbt-1.2.5-wepl/api/soap/mantisconnect.php --- mantisbt-1.2.5/api/soap/mantisconnect.php 2011-04-05 20:24:17.000000000 +0200 +++ mantisbt-1.2.5-wepl/api/soap/mantisconnect.php 2011-04-12 09:17:29.000000000 +0200 @@ -88,11 +88,12 @@ '', array( 'id' => array( 'name' => 'id', 'type' => 'xsd:integer', 'minOccurs' => '0'), 'name' => array( 'name' => 'name', 'type' => 'xsd:string', 'minOccurs' => '0'), 'real_name' => array( 'name' => 'real_name', 'type' => 'xsd:string', 'minOccurs' => '0'), - 'email' => array( 'name' => 'email', 'type' => 'xsd:string', 'minOccurs' => '0') + 'email' => array( 'name' => 'email', 'type' => 'xsd:string', 'minOccurs' => '0'), + 'access' => array( 'name' => 'access', 'type' => 'xsd:integer','minOccurs' => '0') ) ); ### AccountDataArray $l_oServer->wsdl->addComplexType( @@ -354,10 +355,11 @@ 'struct', 'all', '', array( 'id' => array( 'name' => 'id', 'type' => 'xsd:integer', 'minOccurs' => '0' ), + 'parent_id' => array( 'name' => 'parent_id', 'type' => 'xsd:integer', 'minOccurs' => '0' ), 'name' => array( 'name' => 'name', 'type' => 'xsd:string', 'minOccurs' => '0' ), 'status' => array( 'name' => 'status', 'type' => 'tns:ObjectRef', 'minOccurs' => '0' ), 'enabled' => array( 'name' => 'enabled', 'type' => 'xsd:boolean', 'minOccurs' => '0' ), 'view_state' => array( 'name' => 'view_state', 'type' => 'tns:ObjectRef', 'minOccurs' => '0' ), 'access_min' => array( 'name' => 'access_min', 'type' => 'tns:ObjectRef', 'minOccurs' => '0' ), @@ -968,10 +970,30 @@ false, false, false, 'Get the data for the specified issue attachment.' ); ### +### PUBLIC METHODS (defined in mc_account_api.php) +### + +### mc_account_add +$l_oServer->register( 'mc_account_add', + array( + 'username' => 'xsd:string', + 'password' => 'xsd:string', + 'account' => 'tns:AccountData', + 'account_password' => 'xsd:string' + ), + array( + 'return' => 'xsd:integer' + ), + $t_namespace, + false, false, false, + 'Add a new user to the tracker (must have admin privileges)' +); + +### ### PUBLIC METHODS (defined in mc_project_api.php) ### ### mc_project_add $l_oServer->register( 'mc_project_add', @@ -1066,10 +1088,27 @@ $t_namespace, false, false, false, 'Get the issue headers that match the specified project id and paging details.' ); +### mc_project_add_user +$l_oServer->register( 'mc_project_add_user', + array( + 'username' => 'xsd:string', + 'password' => 'xsd:string', + 'project_id' => 'xsd:integer', + 'user_id' => 'xsd:integer', + 'access' => 'xsd:integer' + ), + array( + 'return' => 'xsd:integer' + ), + $t_namespace, + false, false, false, + 'Add a user to a project with access level.' +); + ### mc_project_get_users $l_oServer->register( 'mc_project_get_users', array( 'username' => 'xsd:string', 'password' => 'xsd:string', @@ -1096,10 +1135,24 @@ $t_namespace, false, false, false, 'Get the list of projects that are accessible to the logged in user.' ); +### mc_projects_get_names_user_accessible +$l_oServer->register( 'mc_projects_get_names_user_accessible', + array( + 'username' => 'xsd:string', + 'password' => 'xsd:string' + ), + array( + 'return' => 'tns:ProjectDataArray' + ), + $t_namespace, + false, false, false, + 'Get the list of name/id of projects that are accessible to the logged in user.' +); + ### mc_project_get_categories $l_oServer->register( 'mc_project_get_categories', array( 'username' => 'xsd:string', 'password' => 'xsd:string', diff -rU5 mantisbt-1.2.5/api/soap/mc_account_api.php mantisbt-1.2.5-wepl/api/soap/mc_account_api.php --- mantisbt-1.2.5/api/soap/mc_account_api.php 2011-04-05 20:24:16.000000000 +0200 +++ mantisbt-1.2.5-wepl/api/soap/mc_account_api.php 2011-04-12 09:17:29.000000000 +0200 @@ -35,5 +35,46 @@ $t_result[] = mci_account_get_array_by_id( $t_user_id ); } return $t_result; } + +/** +* Add a new user. +* +* @param string $p_username The name of the user trying to create an account. +* @param string $p_password The password of the user. +* @param Array $p_user A new AccountData structure +* @return integer the new users's users_id +*/ +function mc_account_add( $p_username, $p_password, $p_user, $p_pass ) { + $t_user_id = mci_check_login( $p_username, $p_password ); + if ( $t_user_id === false ) { + return new soap_fault( 'Client', '', 'Access Denied', 'Username/password combination was incorrect'); + } + + if ( !mci_has_administrator_access( $t_user_id ) ) { + return new soap_fault( 'Client', '', 'Access Denied', 'User does not have administrator access'); + } + + extract( $p_user, EXTR_PREFIX_ALL, 'v'); + + // validate user object + if ( is_blank($v_name) ) return new soap_fault('Client', '', 'Mandatory field "name" was missing'); + if ( is_blank($v_real_name) ) return new soap_fault('Client', '', 'Mandatory field "real_name" was missing'); + if ( is_blank($v_email) ) return new soap_fault('Client', '', 'Mandatory field "email" was missing'); + + if ( !user_is_name_valid( $v_name ) ) return new soap_fault( 'Client', '', 'user name invalid'); + if ( !user_is_name_unique( $v_name ) ) return new soap_fault( 'Client', '', 'user name exists'); + if ( !user_is_realname_valid( $v_real_name ) ) return new soap_fault( 'Client', '', 'real name invalid'); + + // set defaults + if ( is_null( $v_access ) ) $v_access = VIEWER; + + // create user account and get it's id + user_create($v_name, $p_pass, $v_email, $v_access, false, true, $v_real_name); + $t_user_id = user_get_id_by_name($v_name); + + // return id of new user back to caller + return $t_user_id; +} + diff -rU5 mantisbt-1.2.5/api/soap/mc_api.php mantisbt-1.2.5-wepl/api/soap/mc_api.php --- mantisbt-1.2.5/api/soap/mc_api.php 2011-04-05 20:24:17.000000000 +0200 +++ mantisbt-1.2.5-wepl/api/soap/mc_api.php 2011-04-12 09:17:29.000000000 +0200 @@ -207,10 +207,24 @@ } return $t_result; } +# Gets the name/id of all sub-projects that are accessible to the specified user / project. +function mci_user_get_names_accessible_subprojects( $p_user_id, $p_parent_project_id ) { + $t_result = array(); + foreach( user_get_accessible_subprojects( $p_user_id, $p_parent_project_id ) as $t_subproject_id ) { + $t_subproject_row = project_cache_row( $t_subproject_id ); + $t_subproject = array(); + $t_subproject['id'] = $t_subproject_id; + $t_subproject['name'] = $t_subproject_row['name']; + $t_subproject['subprojects'] = mci_user_get_names_accessible_subprojects( $p_user_id, $t_subproject_id ); + $t_result[] = $t_subproject; + } + return $t_result; +} + function translate_category_name_to_id( $p_category_name, $p_project_id ) { if ( !isset( $p_category_name ) ) { return 0; } diff -rU5 mantisbt-1.2.5/api/soap/mc_issue_api.php mantisbt-1.2.5-wepl/api/soap/mc_issue_api.php --- mantisbt-1.2.5/api/soap/mc_issue_api.php 2011-04-05 20:24:17.000000000 +0200 +++ mantisbt-1.2.5-wepl/api/soap/mc_issue_api.php 2011-04-12 09:17:29.000000000 +0200 @@ -576,11 +576,12 @@ return new soap_fault( 'Client', '', "Category '" . $p_issue['category'] . "' not found for project '$t_project_id'." ); } } if ( isset( $p_issue['version'] ) && !is_blank( $p_issue['version'] ) && !version_get_id( $p_issue['version'], $t_project_id ) ) { - $t_version = $p_issue['version']; + $t_date_submitted = $p_issue['date_submitted']; + $t_version = isset($p_issue['version']) ? $p_issue['version'] : ''; $t_error_when_version_not_found = config_get( 'mc_error_when_version_not_found' ); if( $t_error_when_version_not_found == ON ) { $t_project_name = project_get_name( $t_project_id ); return new soap_fault( 'Client', '', "Version '$t_version' does not exist in project '$t_project_name'." ); @@ -642,11 +643,14 @@ $t_bug_data->additional_information = isset( $p_issue['additional_information'] ) ? $p_issue['additional_information'] : ''; # submit the issue $t_issue_id = $t_bug_data->create(); - mci_issue_set_custom_fields( $t_issue_id, $p_issue['custom_fields'], false ); + $t_fault = mci_issue_set_custom_fields( $t_issue_id, $p_issue['custom_fields'], false ); + if ($t_fault) { + return new soap_fault( 'Client', '', "mci_issue_set_custom_fields failed" . $t_fault ); + } if ( isset ( $p_issue['monitors'] ) ) mci_issue_set_monitors( $t_issue_id , $t_user_id, $p_issue['monitors'] ); if( isset( $t_notes ) && is_array( $t_notes ) ) { foreach( $t_notes as $t_note ) { @@ -788,11 +792,11 @@ $t_bug_data->reproducibility = $t_reproducibility_id; $t_bug_data->status = $t_status_id; $t_bug_data->resolution = $t_resolution_id; $t_bug_data->projection = $t_projection_id; $t_bug_data->category_id = $t_category_id; - $t_bug_data->date_submitted = isset( $v_date_submitted ) ? $v_date_submitted : ''; + $t_bug_data->date_submitted = $t_date_submitted; $t_bug_data->last_updated = isset( $v_last_updated ) ? $v_last_updated : ''; $t_bug_data->eta = $t_eta_id; $t_bug_data->os = $t_os; $t_bug_data->os_build = $t_os_build; $t_bug_data->platform = $t_platform; diff -rU5 mantisbt-1.2.5/api/soap/mc_project_api.php mantisbt-1.2.5-wepl/api/soap/mc_project_api.php --- mantisbt-1.2.5/api/soap/mc_project_api.php 2011-04-05 20:24:17.000000000 +0200 +++ mantisbt-1.2.5-wepl/api/soap/mc_project_api.php 2011-04-12 09:17:29.000000000 +0200 @@ -72,10 +72,42 @@ return $t_result; } /** + * Get (only) the id and name for all projects accessible by the given user. + * + * @param string $p_username The name of the user trying to access the project list. + * @param string $p_password The password of the user. + * @return Array suitable to be converted into a ProjectDataArray + */ +function mc_projects_get_names_user_accessible( $p_username, $p_password ) { + $t_user_id = mci_check_login( $p_username, $p_password ); + if( $t_user_id === false ) { + return new soap_fault( 'Client', '', 'Access Denied' ); + } + + if( !mci_has_readonly_access( $t_user_id ) ) { + return new soap_fault( 'Client', '', 'Access Denied' ); + } + + $t_lang = mci_get_user_lang( $t_user_id ); + + $t_result = array(); + foreach( user_get_accessible_projects( $t_user_id ) as $t_project_id ) { + $t_project_row = project_cache_row( $t_project_id ); + $t_project = array(); + $t_project['id'] = $t_project_id; + $t_project['name'] = $t_project_row['name']; + $t_project['subprojects'] = mci_user_get_names_accessible_subprojects( $t_user_id, $t_project_id, $t_lang ); + $t_result[] = $t_project; + } + + return $t_result; +} + +/** * Get all categories of a project. * * @param string $p_username The name of the user trying to access the categories. * @param string $p_password The password of the user. * @param integer $p_project_id The id of the project to retrieve the categories for. @@ -748,20 +780,42 @@ $t_inherit_global = $p_project['inherit_global']; } else { $t_inherit_global = true; } + if ( isset( $p_project['parent_id'] ) ) { + $t_parent_id = $p_project['parent_id']; + if ( !project_exists( $t_parent_id ) ) { + return new soap_fault( 'Client', '', 'Parent project does not exist', ''); + } + } else { + $t_parent_id = false; + } + // check to make sure project doesn't already exist if( !project_is_name_unique( $t_name ) ) { return new soap_fault( 'Client', '', 'Project name exists', 'The project name you attempted to add exists already' ); } $t_project_status = mci_get_project_status_id( $t_status ); $t_project_view_state = mci_get_project_view_state_id( $t_view_state ); - // project_create returns the new project's id, spit that out to webservice caller - return project_create( $t_name, $t_description, $t_project_status, $t_project_view_state, $t_file_path, $t_enabled, $t_inherit_global ); + // project_create returns the new project's id + $t_project_id = project_create( $t_name, $t_description, $t_project_status, $t_project_view_state, $t_file_path, $t_enabled, $t_inherit_global ); + + // link new project to a parent project, if one has been specified + if ( $t_parent_id ) { + // link to parent + project_hierarchy_add($t_project_id, $t_parent_id); + + // copy custom fields from parent + project_copy_custom_fields($t_project_id, $t_parent_id); + } + + // return id of new project back to caller + return $t_project_id; + } /** * Update a project * @@ -914,10 +968,42 @@ return $t_result; } /** + * Link a user to a project with a specified access level. + * + * @param string $p_username The name of the user trying to add the user (must be administrator) + * @param string $p_password The password of the user. + * @param integer $p_project_id The id of the project to link user to. + * @param integer $p_user_id The id of the user to link to the project. + * @param integer $p_access access level. + * @return bool returns true or false depending on the success of the action + */ +function mc_project_add_user( $p_username, $p_password, $p_project_id, $p_user_id, $p_access ) { + $t_user_id = mci_check_login( $p_username, $p_password ); + if ( $t_user_id === false ) { + return new soap_fault( 'Client', '', 'Access Denied' ); + } + if ( !mci_has_administrator_access( $t_user_id ) ) { + return new soap_fault( 'Client', '', 'Access Denied', 'User does not have administrator access'); + } + + if ( !project_exists( $p_project_id ) ) { + return new soap_fault( 'Client', '', "Project '$p_project_id' does not exist." ); + } + if ( !user_exists( $p_user_id ) ) { + return new soap_fault( 'Client', '', "User '$p_user_id' does not exist." ); + } + + // add the user to the project + $t_status = project_set_user_access( $p_project_id, $p_user_id, $p_access ); + + return $t_status; +} + +/** * 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. diff -rU5 mantisbt-1.2.5/core/bug_api.php mantisbt-1.2.5-wepl/core/bug_api.php --- mantisbt-1.2.5/core/bug_api.php 2011-04-05 20:24:17.000000000 +0200 +++ mantisbt-1.2.5-wepl/core/bug_api.php 2011-04-12 09:17:29.000000000 +0200 @@ -345,10 +345,12 @@ $t_status = config_get( 'bug_assigned_status' ); } else { $t_status = $this->status; } + $c_date_submitted = !is_blank( $this->date_submitted ) ? $this->date_submitted : db_now(); + # Insert the rest of the data $query = "INSERT INTO $t_bug_table ( project_id,reporter_id, handler_id,duplicate_id, priority,severity, reproducibility,status, resolution,projection, category_id,date_submitted, @@ -364,11 +366,11 @@ " . db_param() . ',' . db_param() . ',' . db_param() . ',' . db_param() . ", " . db_param() . ',' . db_param() . ',' . db_param() . ',' . db_param() . ", " . db_param() . ',' . db_param() . ',' . db_param() . ',' . db_param() . ", " . db_param() . ',' . db_param() . ',' . db_param() . ',' . db_param() . ')'; - db_query_bound( $query, Array( $this->project_id, $this->reporter_id, $this->handler_id, $this->duplicate_id, $this->priority, $this->severity, $this->reproducibility, $t_status, $this->resolution, $this->projection, $this->category_id, db_now(), db_now(), $this->eta, $t_text_id, $this->os, $this->os_build, $this->platform, $this->version, $this->build, $this->profile_id, $this->summary, $this->view_state, $this->sponsorship_total, $this->sticky, $this->fixed_in_version, $this->target_version, $this->due_date ) ); + db_query_bound( $query, Array( $this->project_id, $this->reporter_id, $this->handler_id, $this->duplicate_id, $this->priority, $this->severity, $this->reproducibility, $t_status, $this->resolution, $this->projection, $this->category_id, $c_date_submitted, db_now(), $this->eta, $t_text_id, $this->os, $this->os_build, $this->platform, $this->version, $this->build, $this->profile_id, $this->summary, $this->view_state, $this->sponsorship_total, $this->sticky, $this->fixed_in_version, $this->target_version, $this->due_date ) ); $this->id = db_insert_id( $t_bug_table ); # log new bug history_log_event_special( $this->id, NEW_BUG ); mantisbt-1.2.8-wepl-10349.diff (14,962 bytes)
diff -rU5 mantisbt-1.2.8/api/soap/mantisconnect.php mantisbt-1.2.8-wepl/api/soap/mantisconnect.php --- mantisbt-1.2.8/api/soap/mantisconnect.php 2011-09-06 16:23:10.000000000 +0200 +++ mantisbt-1.2.8-wepl/api/soap/mantisconnect.php 2011-09-11 19:41:48.000000000 +0200 @@ -88,11 +88,12 @@ '', array( 'id' => array( 'name' => 'id', 'type' => 'xsd:integer', 'minOccurs' => '0'), 'name' => array( 'name' => 'name', 'type' => 'xsd:string', 'minOccurs' => '0'), 'real_name' => array( 'name' => 'real_name', 'type' => 'xsd:string', 'minOccurs' => '0'), - 'email' => array( 'name' => 'email', 'type' => 'xsd:string', 'minOccurs' => '0') + 'email' => array( 'name' => 'email', 'type' => 'xsd:string', 'minOccurs' => '0'), + 'access' => array( 'name' => 'access', 'type' => 'xsd:integer','minOccurs' => '0') ) ); ### AccountDataArray $l_oServer->wsdl->addComplexType( @@ -358,10 +359,11 @@ 'struct', 'all', '', array( 'id' => array( 'name' => 'id', 'type' => 'xsd:integer', 'minOccurs' => '0' ), + 'parent_id' => array( 'name' => 'parent_id', 'type' => 'xsd:integer', 'minOccurs' => '0' ), 'name' => array( 'name' => 'name', 'type' => 'xsd:string', 'minOccurs' => '0' ), 'status' => array( 'name' => 'status', 'type' => 'tns:ObjectRef', 'minOccurs' => '0' ), 'enabled' => array( 'name' => 'enabled', 'type' => 'xsd:boolean', 'minOccurs' => '0' ), 'view_state' => array( 'name' => 'view_state', 'type' => 'tns:ObjectRef', 'minOccurs' => '0' ), 'access_min' => array( 'name' => 'access_min', 'type' => 'tns:ObjectRef', 'minOccurs' => '0' ), @@ -988,10 +990,30 @@ false, false, false, 'Get the data for the specified issue attachment.' ); ### +### PUBLIC METHODS (defined in mc_account_api.php) +### + +### mc_account_add +$l_oServer->register( 'mc_account_add', + array( + 'username' => 'xsd:string', + 'password' => 'xsd:string', + 'account' => 'tns:AccountData', + 'account_password' => 'xsd:string' + ), + array( + 'return' => 'xsd:integer' + ), + $t_namespace, + false, false, false, + 'Add a new user to the tracker (must have admin privileges)' +); + +### ### PUBLIC METHODS (defined in mc_project_api.php) ### ### mc_project_add $l_oServer->register( 'mc_project_add', @@ -1086,10 +1108,27 @@ $t_namespace, false, false, false, 'Get the issue headers that match the specified project id and paging details.' ); +### mc_project_add_user +$l_oServer->register( 'mc_project_add_user', + array( + 'username' => 'xsd:string', + 'password' => 'xsd:string', + 'project_id' => 'xsd:integer', + 'user_id' => 'xsd:integer', + 'access' => 'xsd:integer' + ), + array( + 'return' => 'xsd:integer' + ), + $t_namespace, + false, false, false, + 'Add a user to a project with access level.' +); + ### mc_project_get_users $l_oServer->register( 'mc_project_get_users', array( 'username' => 'xsd:string', 'password' => 'xsd:string', @@ -1116,10 +1155,24 @@ $t_namespace, false, false, false, 'Get the list of projects that are accessible to the logged in user.' ); +### mc_projects_get_names_user_accessible +$l_oServer->register( 'mc_projects_get_names_user_accessible', + array( + 'username' => 'xsd:string', + 'password' => 'xsd:string' + ), + array( + 'return' => 'tns:ProjectDataArray' + ), + $t_namespace, + false, false, false, + 'Get the list of name/id of projects that are accessible to the logged in user.' +); + ### mc_project_get_categories $l_oServer->register( 'mc_project_get_categories', array( 'username' => 'xsd:string', 'password' => 'xsd:string', diff -rU5 mantisbt-1.2.8/api/soap/mc_account_api.php mantisbt-1.2.8-wepl/api/soap/mc_account_api.php --- mantisbt-1.2.8/api/soap/mc_account_api.php 2011-09-06 16:23:09.000000000 +0200 +++ mantisbt-1.2.8-wepl/api/soap/mc_account_api.php 2011-09-11 19:41:48.000000000 +0200 @@ -35,5 +35,46 @@ $t_result[] = mci_account_get_array_by_id( $t_user_id ); } return $t_result; } + +/** +* Add a new user. +* +* @param string $p_username The name of the user trying to create an account. +* @param string $p_password The password of the user. +* @param Array $p_user A new AccountData structure +* @return integer the new users's users_id +*/ +function mc_account_add( $p_username, $p_password, $p_user, $p_pass ) { + $t_user_id = mci_check_login( $p_username, $p_password ); + if ( $t_user_id === false ) { + return new soap_fault( 'Client', '', 'Access Denied', 'Username/password combination was incorrect'); + } + + if ( !mci_has_administrator_access( $t_user_id ) ) { + return new soap_fault( 'Client', '', 'Access Denied', 'User does not have administrator access'); + } + + extract( $p_user, EXTR_PREFIX_ALL, 'v'); + + // validate user object + if ( is_blank($v_name) ) return new soap_fault('Client', '', 'Mandatory field "name" was missing'); + if ( is_blank($v_real_name) ) return new soap_fault('Client', '', 'Mandatory field "real_name" was missing'); + if ( is_blank($v_email) ) return new soap_fault('Client', '', 'Mandatory field "email" was missing'); + + if ( !user_is_name_valid( $v_name ) ) return new soap_fault( 'Client', '', 'user name invalid'); + if ( !user_is_name_unique( $v_name ) ) return new soap_fault( 'Client', '', 'user name exists'); + if ( !user_is_realname_valid( $v_real_name ) ) return new soap_fault( 'Client', '', 'real name invalid'); + + // set defaults + if ( is_null( $v_access ) ) $v_access = VIEWER; + + // create user account and get it's id + user_create($v_name, $p_pass, $v_email, $v_access, false, true, $v_real_name); + $t_user_id = user_get_id_by_name($v_name); + + // return id of new user back to caller + return $t_user_id; +} + diff -rU5 mantisbt-1.2.8/api/soap/mc_api.php mantisbt-1.2.8-wepl/api/soap/mc_api.php --- mantisbt-1.2.8/api/soap/mc_api.php 2011-09-06 16:23:10.000000000 +0200 +++ mantisbt-1.2.8-wepl/api/soap/mc_api.php 2011-09-11 19:41:48.000000000 +0200 @@ -207,10 +207,24 @@ } return $t_result; } +# Gets the name/id of all sub-projects that are accessible to the specified user / project. +function mci_user_get_names_accessible_subprojects( $p_user_id, $p_parent_project_id ) { + $t_result = array(); + foreach( user_get_accessible_subprojects( $p_user_id, $p_parent_project_id ) as $t_subproject_id ) { + $t_subproject_row = project_cache_row( $t_subproject_id ); + $t_subproject = array(); + $t_subproject['id'] = $t_subproject_id; + $t_subproject['name'] = $t_subproject_row['name']; + $t_subproject['subprojects'] = mci_user_get_names_accessible_subprojects( $p_user_id, $t_subproject_id ); + $t_result[] = $t_subproject; + } + return $t_result; +} + function translate_category_name_to_id( $p_category_name, $p_project_id ) { if ( !isset( $p_category_name ) ) { return 0; } diff -rU5 mantisbt-1.2.8/api/soap/mc_issue_api.php mantisbt-1.2.8-wepl/api/soap/mc_issue_api.php --- mantisbt-1.2.8/api/soap/mc_issue_api.php 2011-09-06 16:23:10.000000000 +0200 +++ mantisbt-1.2.8-wepl/api/soap/mc_issue_api.php 2011-09-11 20:13:12.000000000 +0200 @@ -645,11 +645,14 @@ $t_bug_data->additional_information = isset( $p_issue['additional_information'] ) ? $p_issue['additional_information'] : ''; # submit the issue $t_issue_id = $t_bug_data->create(); - mci_issue_set_custom_fields( $t_issue_id, $p_issue['custom_fields'], false ); + $t_fault = mci_issue_set_custom_fields( $t_issue_id, $p_issue['custom_fields'], false ); + if ($t_fault) { + return new soap_fault( 'Client', '', "mci_issue_set_custom_fields failed" . $t_fault ); + } if ( isset ( $p_issue['monitors'] ) ) mci_issue_set_monitors( $t_issue_id , $t_user_id, $p_issue['monitors'] ); if( isset( $t_notes ) && is_array( $t_notes ) ) { foreach( $t_notes as $t_note ) { diff -rU5 mantisbt-1.2.8/api/soap/mc_project_api.php mantisbt-1.2.8-wepl/api/soap/mc_project_api.php --- mantisbt-1.2.8/api/soap/mc_project_api.php 2011-09-06 16:23:10.000000000 +0200 +++ mantisbt-1.2.8-wepl/api/soap/mc_project_api.php 2011-09-11 19:41:48.000000000 +0200 @@ -78,10 +78,42 @@ return $t_result; } /** + * Get (only) the id and name for all projects accessible by the given user. + * + * @param string $p_username The name of the user trying to access the project list. + * @param string $p_password The password of the user. + * @return Array suitable to be converted into a ProjectDataArray + */ +function mc_projects_get_names_user_accessible( $p_username, $p_password ) { + $t_user_id = mci_check_login( $p_username, $p_password ); + if( $t_user_id === false ) { + return new soap_fault( 'Client', '', 'Access Denied' ); + } + + if( !mci_has_readonly_access( $t_user_id ) ) { + return new soap_fault( 'Client', '', 'Access Denied' ); + } + + $t_lang = mci_get_user_lang( $t_user_id ); + + $t_result = array(); + foreach( user_get_accessible_projects( $t_user_id ) as $t_project_id ) { + $t_project_row = project_cache_row( $t_project_id ); + $t_project = array(); + $t_project['id'] = $t_project_id; + $t_project['name'] = $t_project_row['name']; + $t_project['subprojects'] = mci_user_get_names_accessible_subprojects( $t_user_id, $t_project_id, $t_lang ); + $t_result[] = $t_project; + } + + return $t_result; +} + +/** * Get all categories of a project. * * @param string $p_username The name of the user trying to access the categories. * @param string $p_password The password of the user. * @param integer $p_project_id The id of the project to retrieve the categories for. @@ -732,20 +764,42 @@ $t_inherit_global = $p_project['inherit_global']; } else { $t_inherit_global = true; } + if ( isset( $p_project['parent_id'] ) ) { + $t_parent_id = $p_project['parent_id']; + if ( !project_exists( $t_parent_id ) ) { + return new soap_fault( 'Client', '', 'Parent project does not exist', ''); + } + } else { + $t_parent_id = false; + } + // check to make sure project doesn't already exist if( !project_is_name_unique( $t_name ) ) { return new soap_fault( 'Client', '', 'Project name exists', 'The project name you attempted to add exists already' ); } $t_project_status = mci_get_project_status_id( $t_status ); $t_project_view_state = mci_get_project_view_state_id( $t_view_state ); - // project_create returns the new project's id, spit that out to webservice caller - return project_create( $t_name, $t_description, $t_project_status, $t_project_view_state, $t_file_path, $t_enabled, $t_inherit_global ); + // project_create returns the new project's id + $t_project_id = project_create( $t_name, $t_description, $t_project_status, $t_project_view_state, $t_file_path, $t_enabled, $t_inherit_global ); + + // link new project to a parent project, if one has been specified + if ( $t_parent_id ) { + // link to parent + project_hierarchy_add($t_project_id, $t_parent_id); + + // copy custom fields from parent + project_copy_custom_fields($t_project_id, $t_parent_id); + } + + // return id of new project back to caller + return $t_project_id; + } /** * Update a project * @@ -903,10 +957,42 @@ return $t_result; } /** + * Link a user to a project with a specified access level. + * + * @param string $p_username The name of the user trying to add the user (must be administrator) + * @param string $p_password The password of the user. + * @param integer $p_project_id The id of the project to link user to. + * @param integer $p_user_id The id of the user to link to the project. + * @param integer $p_access access level. + * @return bool returns true or false depending on the success of the action + */ +function mc_project_add_user( $p_username, $p_password, $p_project_id, $p_user_id, $p_access ) { + $t_user_id = mci_check_login( $p_username, $p_password ); + if ( $t_user_id === false ) { + return new soap_fault( 'Client', '', 'Access Denied' ); + } + if ( !mci_has_administrator_access( $t_user_id ) ) { + return new soap_fault( 'Client', '', 'Access Denied', 'User does not have administrator access'); + } + + if ( !project_exists( $p_project_id ) ) { + return new soap_fault( 'Client', '', "Project '$p_project_id' does not exist." ); + } + if ( !user_exists( $p_user_id ) ) { + return new soap_fault( 'Client', '', "User '$p_user_id' does not exist." ); + } + + // add the user to the project + $t_status = project_set_user_access( $p_project_id, $p_user_id, $p_access ); + + return $t_status; +} + +/** * 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. diff -rU5 mantisbt-1.2.8/core/bug_api.php mantisbt-1.2.8-wepl/core/bug_api.php --- mantisbt-1.2.8/core/bug_api.php 2011-09-06 16:23:10.000000000 +0200 +++ mantisbt-1.2.8-wepl/core/bug_api.php 2011-09-11 19:41:48.000000000 +0200 @@ -345,10 +345,12 @@ $t_status = config_get( 'bug_assigned_status' ); } else { $t_status = $this->status; } + $c_date_submitted = !is_blank( $this->date_submitted ) ? $this->date_submitted : db_now(); + # Insert the rest of the data $query = "INSERT INTO $t_bug_table ( project_id,reporter_id, handler_id,duplicate_id, priority,severity, reproducibility,status, resolution,projection, category_id,date_submitted, @@ -364,11 +366,11 @@ " . db_param() . ',' . db_param() . ',' . db_param() . ',' . db_param() . ", " . db_param() . ',' . db_param() . ',' . db_param() . ',' . db_param() . ", " . db_param() . ',' . db_param() . ',' . db_param() . ',' . db_param() . ", " . db_param() . ',' . db_param() . ',' . db_param() . ',' . db_param() . ')'; - db_query_bound( $query, Array( $this->project_id, $this->reporter_id, $this->handler_id, $this->duplicate_id, $this->priority, $this->severity, $this->reproducibility, $t_status, $this->resolution, $this->projection, $this->category_id, db_now(), db_now(), $this->eta, $t_text_id, $this->os, $this->os_build, $this->platform, $this->version, $this->build, $this->profile_id, $this->summary, $this->view_state, $this->sponsorship_total, $this->sticky, $this->fixed_in_version, $this->target_version, $this->due_date ) ); + db_query_bound( $query, Array( $this->project_id, $this->reporter_id, $this->handler_id, $this->duplicate_id, $this->priority, $this->severity, $this->reproducibility, $t_status, $this->resolution, $this->projection, $this->category_id, $c_date_submitted, db_now(), $this->eta, $t_text_id, $this->os, $this->os_build, $this->platform, $this->version, $this->build, $this->profile_id, $this->summary, $this->view_state, $this->sponsorship_total, $this->sticky, $this->fixed_in_version, $this->target_version, $this->due_date ) ); $this->id = db_insert_id( $t_bug_table ); # log new bug history_log_event_special( $this->id, NEW_BUG ); mantisbt-1.2.14-wepl-10349.diff (14,670 bytes)
diff -rU5 mantisbt-1.2.14/api/soap/mantisconnect.wsdl mantisbt-1.2.14-wepl/api/soap/mantisconnect.wsdl --- mantisbt-1.2.14/api/soap/mantisconnect.wsdl 2013-01-22 15:07:11.000000000 +0100 +++ mantisbt-1.2.14-wepl/api/soap/mantisconnect.wsdl 2013-02-01 20:12:07.000000000 +0100 @@ -28,10 +28,11 @@ <xsd:all> <xsd:element name="id" type="xsd:integer" minOccurs="0"/> <xsd:element name="name" type="xsd:string" minOccurs="0"/> <xsd:element name="real_name" type="xsd:string" minOccurs="0"/> <xsd:element name="email" type="xsd:string" minOccurs="0"/> + <xsd:element name="access" type="xsd:integer" minOccurs="0"/> </xsd:all> </xsd:complexType> <xsd:complexType name="UserData"> <xsd:all> <xsd:element name="account_data" type="tns:AccountData" minOccurs="0"/> @@ -190,10 +191,11 @@ </xsd:complexContent> </xsd:complexType> <xsd:complexType name="ProjectData"> <xsd:all> <xsd:element name="id" type="xsd:integer" minOccurs="0"/> + <xsd:element name="parent_id" type="xsd:integer" minOccurs="0"/> <xsd:element name="name" type="xsd:string" minOccurs="0"/> <xsd:element name="status" type="tns:ObjectRef" minOccurs="0"/> <xsd:element name="enabled" type="xsd:boolean" minOccurs="0"/> <xsd:element name="view_state" type="tns:ObjectRef" minOccurs="0"/> <xsd:element name="access_min" type="tns:ObjectRef" minOccurs="0"/> @@ -756,10 +758,30 @@ <part name="username" type="xsd:string" /> <part name="password" type="xsd:string" /> <part name="tag_id" type="xsd:integer" /></message> <message name="mc_tag_deleteResponse"> <part name="return" type="xsd:boolean" /></message> +<message name="mc_account_addRequest"> + <part name="username" type="xsd:string" /> + <part name="password" type="xsd:string" /> + <part name="account" type="tns:AccountData" /> + <part name="account_password" type="xsd:string" /></message> +<message name="mc_account_addResponse"> + <part name="return" type="xsd:integer" /></message> +<message name="mc_project_add_userRequest"> + <part name="username" type="xsd:string" /> + <part name="password" type="xsd:string" /> + <part name="project_id" type="xsd:integer" /> + <part name="user_id" type="xsd:integer" /> + <part name="access" type="xsd:integer" /></message> +<message name="mc_project_add_userResponse"> + <part name="return" type="xsd:integer" /></message> +<message name="mc_projects_get_names_user_accessibleRequest"> + <part name="username" type="xsd:string" /> + <part name="password" type="xsd:string" /></message> +<message name="mc_projects_get_names_user_accessibleResponse"> + <part name="return" type="tns:ProjectDataArray" /></message> <portType name="MantisConnectPortType"> <operation name="mc_version"> <input message="tns:mc_versionRequest"/> <output message="tns:mc_versionResponse"/> </operation> @@ -1081,10 +1103,25 @@ <operation name="mc_tag_delete"> <documentation>Deletes a tag.</documentation> <input message="tns:mc_tag_deleteRequest"/> <output message="tns:mc_tag_deleteResponse"/> </operation> + <operation name="mc_account_add"> + <documentation>Add a new user to the tracker (must have admin privileges).</documentation> + <input message="tns:mc_account_addRequest"/> + <output message="tns:mc_account_addResponse"/> + </operation> + <operation name="mc_project_add_user"> + <documentation>Add a user to a project with access level.</documentation> + <input message="tns:mc_project_add_userRequest"/> + <output message="tns:mc_project_add_userResponse"/> + </operation> + <operation name="mc_projects_get_names_user_accessible"> + <documentation>Get the list of name/id of projects that are accessible to the logged in user.</documentation> + <input message="tns:mc_projects_get_names_user_accessibleRequest"/> + <output message="tns:mc_projects_get_names_user_accessibleResponse"/> + </operation> </portType> <binding name="MantisConnectBinding" type="tns:MantisConnectPortType"> <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> <operation name="mc_version"> <soap:operation soapAction="http://www.mantisbt.org/bugs/api/soap/mantisconnect.php/mc_version" style="rpc"/> @@ -1409,12 +1446,27 @@ <operation name="mc_tag_delete"> <soap:operation soapAction="http://www.mantisbt.org/bugs/api/soap/mantisconnect.php/mc_tag_delete" style="rpc"/> <input><soap:body use="encoded" namespace="http://futureware.biz/mantisconnect" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input> <output><soap:body use="encoded" namespace="http://futureware.biz/mantisconnect" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output> </operation> + <operation name="mc_account_add"> + <soap:operation soapAction="http://www.mantisbt.org/bugs/api/soap/mantisconnect.php/mc_account_add" style="rpc"/> + <input><soap:body use="encoded" namespace="http://futureware.biz/mantisconnect" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input> + <output><soap:body use="encoded" namespace="http://futureware.biz/mantisconnect" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output> + </operation> + <operation name="mc_project_add_user"> + <soap:operation soapAction="http://www.mantisbt.org/bugs/api/soap/mantisconnect.php/mc_project_add_user" style="rpc"/> + <input><soap:body use="encoded" namespace="http://futureware.biz/mantisconnect" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input> + <output><soap:body use="encoded" namespace="http://futureware.biz/mantisconnect" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output> + </operation> + <operation name="mc_projects_get_names_user_accessible"> + <soap:operation soapAction="http://www.mantisbt.org/bugs/api/soap/mantisconnect.php/mc_projects_get_names_user_accessible" style="rpc"/> + <input><soap:body use="encoded" namespace="http://futureware.biz/mantisconnect" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input> + <output><soap:body use="encoded" namespace="http://futureware.biz/mantisconnect" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output> + </operation> </binding> <service name="MantisConnect"> <port name="MantisConnectPort" binding="tns:MantisConnectBinding"> <soap:address location="http://www.mantisbt.org/bugs/api/soap/mantisconnect.php"/> </port> </service> -</definitions> \ No newline at end of file +</definitions> diff -rU5 mantisbt-1.2.14/api/soap/mc_account_api.php mantisbt-1.2.14-wepl/api/soap/mc_account_api.php --- mantisbt-1.2.14/api/soap/mc_account_api.php 2013-01-22 15:07:11.000000000 +0100 +++ mantisbt-1.2.14-wepl/api/soap/mc_account_api.php 2013-02-02 12:32:50.000000000 +0100 @@ -35,5 +35,45 @@ $t_result[] = mci_account_get_array_by_id( $t_user_id ); } return $t_result; } + +/** +* Add a new user. +* +* @param string $p_username The name of the user trying to create an account. +* @param string $p_password The password of the user. +* @param Array $p_user A new AccountData structure +* @return integer The new users's users_id +*/ +function mc_account_add( $p_username, $p_password, $p_user, $p_pass ) { + $t_user_id = mci_check_login( $p_username, $p_password ); + if ( $t_user_id === false ) { + return mci_soap_fault_login_failed(); + } + if ( !mci_has_administrator_access( $t_user_id ) ) { + return mci_soap_fault_access_denied( $t_user_id ); + } + + $p_user = SoapObjectsFactory::unwrapObject( $p_user ); + + // validate user attributes + if ( is_blank($p_user['name']) ) return SoapObjectsFactory::newSoapFault('Client', 'Mandatory field "name" was missing'); + if ( is_blank($p_user['real_name']) ) return SoapObjectsFactory::newSoapFault('Client', 'Mandatory field "real_name" was missing'); + if ( is_blank($p_user['email']) ) return SoapObjectsFactory::newSoapFault('Client', 'Mandatory field "email" was missing'); + + if ( !user_is_name_valid( $p_user['name'] ) ) return SoapObjectsFactory::newSoapFault( 'Client', 'user name invalid'); + if ( !user_is_name_unique( $p_user['name'] ) ) return SoapObjectsFactory::newSoapFault( 'Client', 'user name exists'); + if ( !user_is_realname_valid( $p_user['real_name'] ) ) return SoapObjectsFactory::newSoapFault( 'Client', 'real name invalid'); + + // set defaults + if ( is_null( $p_user['access'] ) ) $p_user['access'] = VIEWER; + + // create user account + if ( !user_create($p_user['name'], $p_pass, $p_user['email'], $p_user['access'], false, true, $p_user['real_name'])) + return SoapObjectsFactory::newSoapFault( 'Client', 'user could not be created'); + + // return id of new user back to caller + return user_get_id_by_name($p_user['name']); +} + diff -rU5 mantisbt-1.2.14/api/soap/mc_api.php mantisbt-1.2.14-wepl/api/soap/mc_api.php --- mantisbt-1.2.14/api/soap/mc_api.php 2013-01-22 15:07:11.000000000 +0100 +++ mantisbt-1.2.14-wepl/api/soap/mc_api.php 2013-02-01 18:19:44.000000000 +0100 @@ -351,10 +351,24 @@ } return $t_result; } +# Gets the name/id of all sub-projects that are accessible to the specified user / project. +function mci_user_get_names_accessible_subprojects( $p_user_id, $p_parent_project_id ) { + $t_result = array(); + foreach( user_get_accessible_subprojects( $p_user_id, $p_parent_project_id ) as $t_subproject_id ) { + $t_subproject_row = project_cache_row( $t_subproject_id ); + $t_subproject = array(); + $t_subproject['id'] = $t_subproject_id; + $t_subproject['name'] = $t_subproject_row['name']; + $t_subproject['subprojects'] = mci_user_get_names_accessible_subprojects( $p_user_id, $t_subproject_id ); + $t_result[] = $t_subproject; + } + return $t_result; +} + function translate_category_name_to_id( $p_category_name, $p_project_id ) { if ( !isset( $p_category_name ) ) { return 0; } diff -rU5 mantisbt-1.2.14/api/soap/mc_project_api.php mantisbt-1.2.14-wepl/api/soap/mc_project_api.php --- mantisbt-1.2.14/api/soap/mc_project_api.php 2013-01-22 15:07:11.000000000 +0100 +++ mantisbt-1.2.14-wepl/api/soap/mc_project_api.php 2013-02-01 20:56:52.000000000 +0100 @@ -78,10 +78,42 @@ return $t_result; } /** + * Get (only) the id and name for all projects accessible by the given user. + * + * @param string $p_username The name of the user trying to access the project list. + * @param string $p_password The password of the user. + * @return Array suitable to be converted into a ProjectDataArray + */ +function mc_projects_get_names_user_accessible( $p_username, $p_password ) { + $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_lang = mci_get_user_lang( $t_user_id ); + + $t_result = array(); + foreach( user_get_accessible_projects( $t_user_id ) as $t_project_id ) { + $t_project_row = project_cache_row( $t_project_id ); + $t_project = array(); + $t_project['id'] = $t_project_id; + $t_project['name'] = $t_project_row['name']; + $t_project['subprojects'] = mci_user_get_names_accessible_subprojects( $t_user_id, $t_project_id, $t_lang ); + $t_result[] = $t_project; + } + + return $t_result; +} + +/** * Get all categories of a project. * * @param string $p_username The name of the user trying to access the categories. * @param string $p_password The password of the user. * @param integer $p_project_id The id of the project to retrieve the categories for. @@ -739,20 +771,41 @@ $t_inherit_global = $p_project['inherit_global']; } else { $t_inherit_global = true; } + if ( isset( $p_project['parent_id'] ) ) { + $t_parent_id = $p_project['parent_id']; + if ( !project_exists( $t_parent_id ) ) { + return SoapObjectsFactory::newSoapFault( 'Client', 'Parent project does not exist'); + } + } else { + $t_parent_id = false; + } + // check to make sure project doesn't already exist if( !project_is_name_unique( $t_name ) ) { return SoapObjectsFactory::newSoapFault( 'Client', 'Project name exists'); } $t_project_status = mci_get_project_status_id( $t_status ); $t_project_view_state = mci_get_project_view_state_id( $t_view_state ); // project_create returns the new project's id, spit that out to webservice caller - return project_create( $t_name, $t_description, $t_project_status, $t_project_view_state, $t_file_path, $t_enabled, $t_inherit_global ); + $t_project_id = project_create( $t_name, $t_description, $t_project_status, $t_project_view_state, $t_file_path, $t_enabled, $t_inherit_global ); + + // link new project to a parent project, if one has been specified + if ( $t_parent_id ) { + // link to parent + project_hierarchy_add($t_project_id, $t_parent_id); + + // copy custom fields from parent + project_copy_custom_fields($t_project_id, $t_parent_id); + } + + // return id of new project back to caller + return $t_project_id; } /** * Update a project * @@ -888,10 +941,43 @@ return $t_result; } /** + * Link a user to a project with a specified access level. + * + * @param string $p_username The name of the user trying to add the user (must be administrator) + * @param string $p_password The password of the user. + * @param integer $p_project_id The id of the project to link user to. + * @param integer $p_user_id The id of the user to link to the project. + * @param integer $p_access access level. + * @return bool returns true or false depending on the success of the action + */ +function mc_project_add_user( $p_username, $p_password, $p_project_id, $p_user_id, $p_access ) { + $t_user_id = mci_check_login( $p_username, $p_password ); + if( $t_user_id === false ) { + return mci_soap_fault_login_failed(); + } + + if( !mci_has_administrator_access( $t_user_id ) ) { + return mci_soap_fault_access_denied( $t_user_id ); + } + + if ( !project_exists( $p_project_id ) ) { + return SoapObjectsFactory::newSoapFault( 'Client', "Project '$p_project_id' does not exist." ); + } + if ( !user_exists( $p_user_id ) ) { + return SoapObjectsFactory::newSoapFault( 'Client', "User '$p_user_id' does not exist." ); + } + + // add the user to the project + $t_status = project_set_user_access( $p_project_id, $p_user_id, $p_access ); + + return $t_status; +} + +/** * 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. | ||||
Did not examine the patch (anyway, much appreciated) but I'd like to know whether you noticed/considered to use the new import/export plugin, which is included in 1.2.0a3, and expand its codebase to grok plain text files. |
|
sorry, don't know anything about import/export plugin, where can I find infos? |
|
no, we don't drop the SOAP API, we just implemented an extendable method for exporting issues (right now in XML format) and importing them back. To activate it, browse to the "Manage Plugins" page. Anyway yes, I doubt you can turn it into scriptable stuff. |
|
is there a chance that the changes will go into 1.2.0a4? |
|
I've marked the issue as acknowledged with the plan to go through your changes and take some of them into the core SOAP API. |
|
attached a patch which applies to release 1.2.1 |
|
Any update to the inclusion of this? I really like the add user to project stuff and I will be extending it today for user removal. Would be great to have this upstream. |
|
I'd really love to see this come to a release soon as we'd really like it for our automated software deployment system. |
|
+1 |
|
that this API is compatible with mantis 1.2.10? |
|
Please submit a github pull request for review. |
|
is there a guide how to provide a pull request? |
|
have sent https://github.com/mantisbt/mantisbt/pull/88 |
|