From 8460749f5d6252e67c7b91bf4ce0af0992a03ef4 Mon Sep 17 00:00:00 2001
From: Robert Munteanu <robert.munteanu@gmail.com>
Date: Fri, 30 Oct 2009 14:38:00 +0200
Subject: [PATCH] Issue #11081: Username not printed correctly when failing to enter a bug via SOAP API

Adds two utility functions for reporting login failed and
access denied errors.
---
 api/soap/mc_api.php |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/api/soap/mc_api.php b/api/soap/mc_api.php
index dae2345..3d105f0 100644
--- a/api/soap/mc_api.php
+++ b/api/soap/mc_api.php
@@ -436,3 +436,30 @@ function error_get_stack_trace() {
 
 	return $t_trace;
 }
+
+/**
+ * Returns a soap_fault signalling corresponding to a failed login 
+ * situation
+ * 
+ * @return soap_fault
+ */
+function mci_soap_fault_login_failed() {
+	return new soap_fault('Client', '', 'Access denied.');
+}
+
+/**
+ * Returns a soap_fault signalling that the user does not have
+ * access rights for the specific action.
+ * 
+ * @param int $p_user_id a valid user id
+ * @param string $p_detail The optional details to append to the error message
+ * @return soap_fault
+ */
+function mci_soap_fault_access_denied( $p_user_id, $p_detail = '' ) {
+	$t_user_name = user_get_name( $p_user_id );
+	$t_reason = 'Access denied for user '. $t_user_name . '.';
+	if ( !is_blank( $p_detail ))
+		$t_reason .= ' Reason: ' . $p_detail . '.';
+	
+	return new soap_fault( 'Client', '',  $t_reason );
+}
-- 
1.6.4.2

