[Fusionforge-commits] r12424 - in trunk/src/plugins/mantisbt: action view www

Franck VILLAUME nerville at fusionforge.org
Mon Feb 28 16:00:41 CET 2011


Author: nerville
Date: 2011-02-28 16:00:41 +0100 (Mon, 28 Feb 2011)
New Revision: 12424

Modified:
   trunk/src/plugins/mantisbt/action/addAttachment.php
   trunk/src/plugins/mantisbt/view/viewAttachment.php
   trunk/src/plugins/mantisbt/www/getAttachment.php
Log:
make attachment to work... still need workaround due to mantisbt unfixed known bug....

Modified: trunk/src/plugins/mantisbt/action/addAttachment.php
===================================================================
--- trunk/src/plugins/mantisbt/action/addAttachment.php	2011-02-28 14:25:56 UTC (rev 12423)
+++ trunk/src/plugins/mantisbt/action/addAttachment.php	2011-02-28 15:00:41 UTC (rev 12424)
@@ -1,7 +1,10 @@
 <?php
 /*
- * Copyright 2010, Franck Villaume - Capgemini
+ * MantisBT plugin
  *
+ * Copyright 2010-2011, Franck Villaume - Capgemini
+ * http://fusionforge.org
+ *
  * This file is part of FusionForge.
  *
  * FusionForge is free software; you can redistribute it and/or modify
@@ -19,15 +22,24 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  */
 
+global $mantisbt;
+global $mantisbtConf;
+global $username;
+global $password;
+global $group_id;
+global $idBug;
+
 $data = file_get_contents($_FILES['attachment']['tmp_name'] );
 $content = base64_encode($data);
 try {
-	$clientSOAP = new SoapClient(forge_get_config('server_url','mantisbt')."/api/soap/mantisconnect.php?wsdl", array('trace'=>true, 'exceptions'=>true));
+	if (!isset($clientSOAP))
+		$clientSOAP = new SoapClient($mantisbtConf['url']."/api/soap/mantisconnect.php?wsdl", array('trace'=>true, 'exceptions'=>true));
+
 	$clientSOAP->__soapCall('mc_issue_attachment_add', array("username" => $username, "password" => $password, "issue_id" => $idBug, "name" => $_FILES['attachment']['name'], "file_type" => $_FILES['attachment']['type'], "content" => $content ));
 	$feedback = _('Task Successed');
 } catch (SoapFault $soapFault) {
 	$error_msg = _('Task failed:').' '.$soapFault->faultstring;
-	session_redirect('plugins/mantisbt/?type=group&id='.$id.'&pluginname=mantisbt&idBug='.$idBug.'&view=viewIssue&error_msg='.urlencode($error_msg));
+	session_redirect('plugins/mantisbt/?type=group&group_id='.$group_id.'&pluginname='.$mantisbt->name.'&idBug='.$idBug.'&view=viewIssue&error_msg='.urlencode($error_msg));
 }
-session_redirect('plugins/mantisbt/?type=group&id='.$id.'&pluginname=mantisbt&idBug='.$idBug.'&view=viewIssue&feedback='.urlencode($feedback));
+session_redirect('plugins/mantisbt/?type=group&group_id='.$group_id.'&pluginname='.$mantisbt->name.'&idBug='.$idBug.'&view=viewIssue&feedback='.urlencode($feedback));
 ?>

Modified: trunk/src/plugins/mantisbt/view/viewAttachment.php
===================================================================
--- trunk/src/plugins/mantisbt/view/viewAttachment.php	2011-02-28 14:25:56 UTC (rev 12423)
+++ trunk/src/plugins/mantisbt/view/viewAttachment.php	2011-02-28 15:00:41 UTC (rev 12424)
@@ -53,7 +53,7 @@
 				echo	'<tr>';
 				echo		'<td class="FullBox">'.$attachement->filename.'</td>';
 				echo 		'<td class="FullBox">';
-				echo			'<input type=button value="'._('Download').'" onclick="window.location.href=\'getAttachment.php/'.$attachement->id.'/'.$attachement->filename.'\'">';
+				echo			'<input type=button value="'._('Download').'" onclick="window.location.href=\'getAttachment.php/'.$group_id.'/'.$attachement->id.'/'.$attachement->filename.'\'">';
 				echo			'<input type=button value="'._('Delete').'" onclick="window.location.href=\'?type='.$type.'&group_id='.$group_id.'&pluginname='.$mantisbt->name.'&idBug='.$idBug.'&idAttachment='.$attachement->id.'&action=deleteAttachment&view=viewIssue\'">';
 				echo		'</td>';
 				echo 	'</tr>';

Modified: trunk/src/plugins/mantisbt/www/getAttachment.php
===================================================================
--- trunk/src/plugins/mantisbt/www/getAttachment.php	2011-02-28 14:25:56 UTC (rev 12423)
+++ trunk/src/plugins/mantisbt/www/getAttachment.php	2011-02-28 15:00:41 UTC (rev 12424)
@@ -26,39 +26,67 @@
 
 require_once('../../env.inc.php');
 require_once $gfcommon.'include/pre.php';
-require_once $gfcommon.'ldap/ldapUtils.php';
 require_once $gfconfig.'plugins/mantisbt/config.php';
 
-
 $arr=explode('/',getStringFromServer('REQUEST_URI'));
-$idAttachment=$arr[4];
+$group_id = $arr[4];
+$idAttachment=$arr[5];
 
 $user = session_get_user(); // get the session user
 
 if (!$user || !is_object($user)) {
-        exit_error(_('Invalid User'),'mantisbt');
+        exit_error(_('Invalid User'), 'mantisbt');
 } else if ( $user->isError() ) {
-        exit_error($user->isError(),'mantisbt');
+        exit_error($user->isError(), 'mantisbt');
 } else if ( !$user->isActive()) {
-        exit_error(_('Invalid User not active'),'mantisbt');
+        exit_error(_('Invalid User not active'), 'mantisbt');
 }
 
-$password = getPasswordFromLDAP($user);
-$username = $user->getUnixName();
+$group = group_get_object($group_id);
+$mantisbt = plugin_get_object('mantisbt');
 
+if (!$group) {
+	exit_no_group();
+}
+if (!$group->usesPlugin($mantisbt->name)) {//check if the group has the MantisBT plugin active
+	exit_error(sprintf(_('First activate the %s plugin through the Project\'s Admin Interface'), $mantisbt->name), 'home');
+}
+if ( $group->isError()) {
+	$error_msg .= $group->getErrorMessage();
+}
+
+$userperm = $group->getPermission($user);//we'll check if the user belongs to the group (optional)
+if ( !$userperm->IsMember()) {
+	exit_permission_denied(_('You are not a member of this project'), 'home');
+}
+
+
+$mantisbtConf = $mantisbt->getMantisBTConf();
+
+if (!$mantisbtConf['sync_users']) {
+	$username = $mantisbtConf['soap_user'];
+	$password = $mantisbtConf['soap_password'];
+}
+
 if ($idAttachment) {
 	try {
-		$clientSOAP = new SoapClient("http://".forge_get_config('server','mantisbt')."/api/soap/mantisconnect.php?wsdl", array('trace'=>true, 'exceptions'=>true));
+		$clientSOAP = new SoapClient($mantisbtConf['url']."/api/soap/mantisconnect.php?wsdl", array('trace'=>true, 'exceptions'=>true));
 		$content = $clientSOAP->__soapCall('mc_issue_attachment_get', array("username" => $username, "password" => $password, "issue_attachment_id" => $idAttachment));
 	} catch (SoapFault $soapFault) {
-		session_redirect('plugins/mantisbt/?type=group&id='.$id.'&pluginname=mantisbt&error_msg='.urlencode($soapFault->faultstring));
+		session_redirect('plugins/mantisbt/?type=group&group_id='.$group_id.'&pluginname=mantisbt&error_msg='.urlencode($soapFault->faultstring));
 	}
 
-	$data = unserialize($content);
-	header( 'Content-Type: ' . $data['file_type'] );
-	header( 'Content-Disposition: filename="'.urlencode($data['filename']).'"' );
-	echo base64_decode($data['payload']);
+	header( 'Content-Disposition: filename="'.urlencode($arr[6]).'"' );
+	// filetype is missing.... now.... so we force application/binary
+	header('Content-type: application/binary');
+	echo base64_decode($content);
 } else {
-	exit_missing_params($_SERVER['HTTP_REFERER'],array(_('No idAttachment')),'mantisbt');
+	if (forge_get_config('use_ssl'))
+		$url = "https://";
+	else
+		$url = "http://";
+
+	$url .= forge_get_config('web_host');
+	exit_missing_param(substr($_SERVER['HTTP_REFERER'], strlen($url)), array(_('No idAttachment')), 'mantisbt');
 }
 ?>




More information about the Fusionforge-commits mailing list