Skip to content

Commit

Permalink
Added function mc_user_pref_get_pref to the API to allow read access …
Browse files Browse the repository at this point in the history
…to user preferences.

Fixes #12946: mc_user_pref_get_pref, user_pref_get_pref API call

Signed-off-by: Robert Munteanu <robert.munteanu@gmail.com>
  • Loading branch information
rnelson authored and rombert committed Apr 26, 2011
1 parent acf78fa commit 286c1af
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 0 deletions.
20 changes: 20 additions & 0 deletions api/soap/mantisconnect.php
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,26 @@
'Get the value for the specified configuration variable.'
);

###
### PUBLIC METHODS (defined in mc_user_pref_api.php)
###

### mc_user_pref_get_pref
$l_oServer->register( 'mc_user_pref_get_pref',
array(
'username' => 'xsd:string',
'password' => 'xsd:string',
'project_id' => 'xsd:integer',
'pref_name' => 'xsd:string'
),
array(
'return' => 'xsd:string'
),
$t_namespace,
false, false, false,
'Get the value for the specified user preference.'
);

###
### IMPLEMENTATION
###
Expand Down
1 change: 1 addition & 0 deletions api/soap/mc_core.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@
require_once( $t_current_dir . 'mc_file_api.php' );
require_once( $t_current_dir . 'mc_config_api.php' );
require_once( $t_current_dir . 'mc_custom_field_api.php' );
require_once( $t_current_dir . 'mc_user_pref_api.php' );
29 changes: 29 additions & 0 deletions api/soap/mc_user_pref_api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
# MantisConnect - A webservice interface to Mantis Bug Tracker
# Copyright (C) 2004-2011 Victor Boctor - vboctor@users.sourceforge.net
# This program is distributed under dual licensing. These include
# GPL and a commercial licenses. Victor Boctor reserves the right to
# change the license of future releases.
# See docs/ folder for more details

/**
* Get the value for the specified user preference.
*
* @param string $p_username The user's username
* @param string $p_password The user's password
* @param int $p_project_id Project ID (0 = ALL_PROJECTS (mantisbt/core/constant_inc.php))
* @param string $p_pref_name The name of the preference
* @return string $t_user_pref The requested preference value
*/
function mc_user_pref_get_pref( $p_username, $p_password, $p_project_id, $p_pref_name ) {
$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 );
}

return user_pref_get_pref( $t_user_id, $p_pref_name, $p_project_id );
}
2 changes: 2 additions & 0 deletions tests/soap/AllTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
require_once 'ProjectTest.php';
require_once 'VersionTest.php';
require_once 'RelationshipTest.php';
require_once 'UserTest.php';

/**
* @package Tests
Expand Down Expand Up @@ -75,6 +76,7 @@ public static function suite()
$suite->addTestSuite('ProjectTest');
$suite->addTestSuite('VersionTest');
$suite->addTestSuite('RelationshipTest');
$suite->addTestSuite('UserTest');

return $suite;
}
Expand Down
41 changes: 41 additions & 0 deletions tests/soap/UserTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
# MantisBT - A PHP based bugtracking system

# MantisBT is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# MantisBT is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with MantisBT. If not, see <http://www.gnu.org/licenses/>.

/**
* @package Tests
* @subpackage UnitTests
* @copyright Copyright (C) 2002 - 2011 MantisBT Team - mantisbt-dev@lists.sourceforge.net
* @link http://www.mantisbt.org
*/

require_once 'SoapBase.php';

/**
* Test fixture for non-login user methods
*/
class UserTest extends SoapBase {

/**
* Tests getting a user preference
*/
public function testGetPreference() {

$language = $this->client->mc_user_pref_get_pref( $this->userName, $this->password, 0 /*ALL_PROJECTS*/, 'language' );

$this->assertEquals( 'auto', $language );

}
}

0 comments on commit 286c1af

Please sign in to comment.