View Issue Details

IDProjectCategoryView StatusLast Update
0012946mantisbtapi soappublic2013-04-06 08:23
Reporterrnelson Assigned Torombert  
PrioritynormalSeverityfeatureReproducibilityN/A
Status closedResolutionfixed 
Product Versiongit trunk 
Target Version1.2.6Fixed in Version1.2.6 
Summary0012946: mc_user_pref_get_pref, user_pref_get_pref API call
Description

The submitted patch adds function mc_user_pref_get_pref to the SOAP API as a frontend to user_pref_get_pref. With it, a developer can access things such as a user's default project via the API.

TagsNo tags attached.
Attached Files
mcuserpref.patch (3,011 bytes)   
From 05cfdda64e7945b3b7c45eb99a28040c11cee700 Mon Sep 17 00:00:00 2001
From: Ross Nelson <ross.nelson@gmail.com>
Date: Mon, 18 Apr 2011 10:57:12 -0500
Subject: [PATCH] Added function mc_user_pref_get_pref to the API to allow
 read access to user preferences

---
 api/soap/mantisconnect.php    |   20 ++++++++++++++++++++
 api/soap/mc_core.php          |    1 +
 api/soap/mc_user_pref_api.php |   30 ++++++++++++++++++++++++++++++
 3 files changed, 51 insertions(+), 0 deletions(-)
 create mode 100644 api/soap/mc_user_pref_api.php

diff --git a/api/soap/mantisconnect.php b/api/soap/mantisconnect.php
index efd1545..270ff72 100644
--- a/api/soap/mantisconnect.php
+++ b/api/soap/mantisconnect.php
@@ -1428,6 +1428,26 @@ $l_oServer->register( 'mc_config_get_string',
 );
 
 ###
+###  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',
+		'pref_name'		=>	'xsd:string',
+		'project_id'	=>	'xsd:integer'
+	),
+	array(
+		'return'	=>	'xsd:string'
+	),
+	$t_namespace,
+	false, false, false,
+	'Get the value for the specified user preference.'
+);
+
+###
 ###  IMPLEMENTATION
 ###
 
diff --git a/api/soap/mc_core.php b/api/soap/mc_core.php
index b637c3d..4369c06 100644
--- a/api/soap/mc_core.php
+++ b/api/soap/mc_core.php
@@ -40,3 +40,4 @@ require_once( $t_current_dir . 'mc_project_attachment_api.php' );
 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' );
diff --git a/api/soap/mc_user_pref_api.php b/api/soap/mc_user_pref_api.php
new file mode 100644
index 0000000..ae00f96
--- /dev/null
+++ b/api/soap/mc_user_pref_api.php
@@ -0,0 +1,30 @@
+<?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 (optional)
+ * @return string  $t_user_pref   The requested preference value
+ */
+function mc_user_pref_get_pref( $p_username, $p_password, $p_pref_name, $p_project_id = ALL_PROJECTS ) {
+	$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_user_pref = user_pref_get_pref( $t_user_id, $p_pref_name, $p_project_id );
+	return $t_user_pref;
+}
+
-- 
1.7.4.4

mcuserpref.patch (3,011 bytes)   
mcuserpref-v2.patch (5,401 bytes)   
From bd2105d87cb20f16a7513ff32b55bf5fa0f8f630 Mon Sep 17 00:00:00 2001
From: Ross Nelson <ross.nelson@gmail.com>
Date: Mon, 18 Apr 2011 10:57:12 -0500
Subject: [PATCH] Added function mc_user_pref_get_pref to the API to allow
 read access to user preferences

---
 api/soap/mantisconnect.php    |   20 +++++++++++++++++++
 api/soap/mc_core.php          |    1 +
 api/soap/mc_user_pref_api.php |   29 +++++++++++++++++++++++++++
 tests/soap/AllTests.php       |    2 +
 tests/soap/UserTest.php       |   43 +++++++++++++++++++++++++++++++++++++++++
 5 files changed, 95 insertions(+), 0 deletions(-)
 create mode 100644 api/soap/mc_user_pref_api.php
 create mode 100644 tests/soap/UserTest.php

diff --git a/api/soap/mantisconnect.php b/api/soap/mantisconnect.php
index efd1545..0c99df5 100644
--- a/api/soap/mantisconnect.php
+++ b/api/soap/mantisconnect.php
@@ -1428,6 +1428,26 @@ $l_oServer->register( 'mc_config_get_string',
 );
 
 ###
+###  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
 ###
 
diff --git a/api/soap/mc_core.php b/api/soap/mc_core.php
index b637c3d..4369c06 100644
--- a/api/soap/mc_core.php
+++ b/api/soap/mc_core.php
@@ -40,3 +40,4 @@ require_once( $t_current_dir . 'mc_project_attachment_api.php' );
 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' );
diff --git a/api/soap/mc_user_pref_api.php b/api/soap/mc_user_pref_api.php
new file mode 100644
index 0000000..744f2cd
--- /dev/null
+++ b/api/soap/mc_user_pref_api.php
@@ -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 );
+}
diff --git a/tests/soap/AllTests.php b/tests/soap/AllTests.php
index 002b4a1..f93740f 100644
--- a/tests/soap/AllTests.php
+++ b/tests/soap/AllTests.php
@@ -39,6 +39,7 @@ require_once 'CompressionTest.php';
 require_once 'ProjectTest.php';
 require_once 'VersionTest.php';
 require_once 'RelationshipTest.php';
+require_once 'UserTest.php';
 
 /**
  * @package    Tests
@@ -75,6 +76,7 @@ class Soap_AllTests extends PHPUnit_Framework_TestSuite
 	    $suite->addTestSuite('ProjectTest');
 	    $suite->addTestSuite('VersionTest');
 	    $suite->addTestSuite('RelationshipTest');
+	    $suite->addTestSuite('UserTest');
 
         return $suite;
     }
diff --git a/tests/soap/UserTest.php b/tests/soap/UserTest.php
new file mode 100644
index 0000000..d316109
--- /dev/null
+++ b/tests/soap/UserTest.php
@@ -0,0 +1,43 @@
+<?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, 'language' );
+        
+        $this->assertNotNull( $language );
+        
+        $this->assertEquals( 'english', $language );
+        
+    }
+}
-- 
1.7.4.4

mcuserpref-v2.patch (5,401 bytes)   

Relationships

related to 0015721 closedgrangeway Functionality to consider porting to master-2.0.x 

Activities

rombert

rombert

2011-04-20 16:45

reporter   ~0028686

Thanks for the patch. I only have two minor comments:

  • the ordering of the parameters should be 'project_id', 'pref_name', as we should go from general to specific;
  • there is an unneeded assignment of $t_user_pref in the implementation; please return the value from the function call.

Also it would be nice to have a test, although it's not mandatory. I can assist if needed.

rnelson

rnelson

2011-04-25 13:01

reporter   ~0028693

I've uploaded an amended patch that includes those two changes and a test.

rombert

rombert

2011-04-26 17:24

reporter   ~0028696

Thanks! Committed to both branches, with minor modifications to tests.

grangeway

grangeway

2013-04-05 17:57

reporter   ~0036438

Marking as 'acknowledged' not resolved/closed to track that change gets ported to master-2.0.x branch

Related Changesets

MantisBT: master 286c1afa

2011-04-26 17:15

rnelson

Committer: rombert


Details Diff
Added function mc_user_pref_get_pref to the API to allow read access to user preferences.

Fixes 0012946: mc_user_pref_get_pref, user_pref_get_pref API call

Signed-off-by: Robert Munteanu <robert.munteanu@gmail.com>
Affected Issues
0012946
mod - api/soap/mantisconnect.php Diff File
add - tests/soap/UserTest.php Diff File
mod - api/soap/mc_core.php Diff File
add - api/soap/mc_user_pref_api.php Diff File
mod - tests/soap/AllTests.php Diff File

MantisBT: master-1.2.x f7bf43fc

2011-04-26 17:15

rnelson

Committer: rombert


Details Diff
Added function mc_user_pref_get_pref to the API to allow read access to user preferences.

Fixes 0012946: mc_user_pref_get_pref, user_pref_get_pref API call

Signed-off-by: Robert Munteanu <robert.munteanu@gmail.com>
Affected Issues
0012946
add - tests/soap/UserTest.php Diff File
mod - api/soap/mc_core.php Diff File
add - api/soap/mc_user_pref_api.php Diff File
mod - api/soap/mantisconnect.php Diff File
mod - tests/soap/AllTests.php Diff File