View Issue Details

IDProjectCategoryView StatusLast Update
0007835mantisbtfeaturepublic2017-04-26 06:39
Reportergiallu Assigned To 
PrioritynormalSeverityminorReproducibilityhave not tried
Status newResolutionopen 
Summary0007835: Add "Has patch" flag to improve usefulness of the "Upload File" feature
Description

It would be useful to put an additional field for the "upload file" subsection, where the user can specify if the attached file is a patch for the issue.

If we can implement this, along with the ability to query for bugs with patches
attached, we can give the proper priority to issues with a proposed fix attached.

Just reference, I am attaching the "Create New Attachment" page from
bugzilla, where I "borrowed" the idea

Tagsattachments
Attached Files
Screenshot-NewAttachment.png (36,068 bytes)   
Screenshot-NewAttachment.png (36,068 bytes)   
filehelper_stage1.JPG (111,025 bytes)   
filehelper_stage1.JPG (111,025 bytes)   
filehelper_patch_versus_1.1.6_2009_05_28.txt (23,744 bytes)   
--- core/bug_api.php	Fri Feb 13 10:33:21 2009
+++ core/bug_api.php	Wed May 27 14:27:42 2009
@@ -646,7 +646,7 @@
 				}
 
 				$query = "INSERT INTO $t_mantis_bug_file_table
-						( bug_id, title, description, diskfile, filename, folder, filesize, file_type, date_added, content )
+						( bug_id, title, description, diskfile, filename, folder, filesize, file_type, date_added, content, patch, obsolete, user_id )
 						VALUES ( '$t_new_bug_id',
 								 '" . db_prepare_string( $t_bug_file['title'] ) . "',
 								 '" . db_prepare_string( $t_bug_file['description'] ) . "',
@@ -656,7 +656,10 @@
 								 '" . db_prepare_int( $t_bug_file['filesize'] ) . "',
 								 '" . db_prepare_string( $t_bug_file['file_type'] ) . "',
 								 '" . db_prepare_string( $t_bug_file['date_added'] ) . "',
-								 '" . db_prepare_string( $t_bug_file['content'] ) . "');";
+								 '" . db_prepare_string( $t_bug_file['content'] ) . "',
+								 '" . db_prepare_string( $t_bug_file['patch'] ) . "',
+								 '" . db_prepare_string( $t_bug_file['obsolete'] ) . "',
+								 '" . db_prepare_string( $t_bug_file['user_id'] ) . "');";
 				db_query( $query );
 			}
 		}
@@ -1132,7 +1135,7 @@
 
 		$t_bug_file_table = config_get( 'mantis_bug_file_table' );
 
-		$query = "SELECT id, title, diskfile, filename, filesize, file_type, date_added
+		$query = "SELECT id, title, diskfile, filename, filesize, file_type, date_added, patch, obsolete, user_id, description
 		                FROM $t_bug_file_table
 		                WHERE bug_id='$c_bug_id'
 		                ORDER BY date_added";
--- bug_file_add.php	Fri Feb 13 10:33:25 2009
+++ bug_file_add.php	Wed May 27 13:42:33 2009
@@ -33,6 +33,15 @@
 
 	$f_bug_id	= gpc_get_int( 'bug_id', -1 );
 	$f_file		= gpc_get_file( 'file', -1 );
+	$f_action = gpc_get_int( 'action', -1 );
+	$f_field = gpc_get_string( 'field', '');
+	$f_file_id = gpc_get_int( 'file_id', -1 );
+	$f_description = gpc_get( 'description', '' );
+	$f_patch = gpc_get_bool( 'patch', 0 );
+	$f_obsolete = gpc_get_bool( 'obsolete', 0 );
+	
+	$t_user_id = auth_get_current_user_id();
+	
 
 	if ( $f_bug_id == -1 && $f_file	== -1 ) {
 		# _POST/_FILES does not seem to get populated if you exceed size limit so check if bug_id is -1
@@ -45,6 +54,7 @@
 
 	access_ensure_bug_level( config_get( 'upload_bug_file_threshold' ), $f_bug_id );
 
+	if ( $f_action == -1 || $f_file_id == -1 ) {
 	$t_bug = bug_get( $f_bug_id, true );
 	if( $t_bug->project_id != helper_get_current_project() ) {
 		# in case the current project is not the same project of the bug we are viewing...
@@ -53,8 +63,11 @@
 	}
 
     $f_file_error =  ( isset( $f_file['error'] ) ) ? $f_file['error'] : 0;
-	file_add( $f_bug_id, $f_file['tmp_name'], $f_file['name'], $f_file['type'], 'bug', $f_file_error );
-
+		file_add( $f_bug_id, $f_file['tmp_name'], $f_file['name'], $f_file['type'], 
+		'bug', $f_file_error, '', $f_description, $f_patch, $f_obsolete, $t_user_id );
+	} else {
+		file_mark( $f_file_id, $f_field, $f_action, $f_bug_id );
+	}
 	# Determine which view page to redirect back to.
 	$t_redirect_url = string_get_bug_view_url( $f_bug_id );
 
--- bug_file_upload_inc.php	Fri Feb 13 10:33:24 2009
+++ bug_file_upload_inc.php	Wed May 27 16:14:19 2009
@@ -49,6 +49,34 @@
 		echo lang_get( 'upload_file' ) ?>
 	</td>
 </tr>
+
+<!-- Attachments -->
+<?php
+	$t_show_attachments = ( $t_bug->reporter_id == auth_get_current_user_id() ) || access_has_bug_level( config_get( 'view_attachments_threshold' ), $f_bug_id );
+
+	if ( $t_show_attachments ) {
+?>
+<!--
+<tr <?php echo helper_alternate_class() ?>>
+	<td class="category">
+		<a name="attachments" id="attachments" />
+		<?php echo lang_get( 'attached_files' ) ?>
+	</td>
+	<td colspan="2">
+		<?php file_list_attachments( $f_bug_id ); ?>
+	</td>
+</tr>
+-->
+<tr>
+	<td colspan="2">
+		<?php file_list_attachments( $f_bug_id ); ?>
+	</td>
+</tr>
+
+<?php
+	}
+?>
+
 <tr class="row-1">
 	<td class="category" width="15%">
 		<?php echo lang_get( 'select_file' ) ?><br />
@@ -59,6 +87,22 @@
 		<input type="hidden" name="max_file_size" value="<?php echo $t_max_file_size ?>" />
 		<input name="file" type="file" size="40" />
 		<input type="submit" class="button" value="<?php echo lang_get( 'upload_file_button' ) ?>" />
+	</td>
+</tr>
+<tr class="row-2">
+	<td class="category" width="15%">
+		<?php echo lang_get( 'file_comment' ) ?>
+	</td>
+	<td with="85%">
+		<input type="text" name="description" size="80" />
+	</td>
+</tr>
+<tr class="row-1">
+	<td class="category"> 
+		<?php echo lang_get( 'file_remarks' ) ?>
+	</td>
+	<td with="85%">
+		<input type="checkbox" name="patch" value="1" ><?php echo lang_get( 'file_patch' ) ?></input>
 	</td>
 </tr>
 </table>
--- bug_report.php	Thu Mar 19 16:09:58 2009
+++ bug_report.php	Wed May 27 14:18:15 2009
@@ -54,7 +54,9 @@
 	$t_bug_data->additional_information	= gpc_get_string( 'additional_info', config_get ( 'default_bug_additional_info' ) );
 
 	$f_file					= gpc_get_file( 'file', null ); #@@@ (thraxisp) Note that this always returns a structure
-															# size = 0, if no file
+	
+	$f_file_description			= gpc_get_string( 'file_description', '' );
+	$f_file_patch				= gpc_get_bool( 'patch', 0 );														# size = 0, if no file
 	$f_report_stay			= gpc_get_bool( 'report_stay', false );
 	$t_bug_data->project_id			= gpc_get_int( 'project_id' );
 # Patch to keep the original reporter 
@@ -166,7 +168,9 @@
 	# Handle the file upload
 	if ( !is_blank( $f_file['tmp_name'] ) && ( 0 < $f_file['size'] ) ) {
                 $f_file_error =  ( isset( $f_file['error'] ) ) ? $f_file['error'] : 0;
-		file_add( $t_bug_id, $f_file['tmp_name'], $f_file['name'], $f_file['type'], 'bug', $f_file_error );
+ 		file_add( $t_bug_id, $f_file['tmp_name'], $f_file['name'],
+ 			$f_file['type'], 'bug', $f_file_error,
+ 			'', $f_file_description, $f_file_patch, 0,  $t_bug_data->reporter_id);
 	}
 
 	# Handle custom field submission
--- bug_report_advanced_page.php	Wed Jan 07 20:01:38 2009
+++ bug_report_advanced_page.php	Wed May 27 13:42:33 2009
@@ -517,6 +517,23 @@
 		<input <?php echo helper_get_tab_index() ?> name="file" type="file" size="60" />
 	</td>
 </tr>
+<tr <?php echo helper_alternate_class() ?>>
+        <td class="category" width="15%">
+                <?php echo lang_get( 'file_comment' ) ?>
+        </td>
+        <td with="85%">
+                <input type="text" name="file_description" size="80" />
+        </td>
+</tr>
+<tr <?php echo helper_alternate_class() ?>>
+        <td class="category">
+                <?php echo lang_get( 'file_remarks' ) ?>
+        </td>
+        <td with="85%">
+                <input type="checkbox" name="patch" value="1" ><?php echo lang_get( 'file_patch' ) ?></input>
+        </td>
+</tr>
+
 <?php } ?>
 
 
--- bug_report_page.php	Tue Jan 06 14:29:51 2009
+++ bug_report_page.php	Wed May 27 13:42:33 2009
@@ -427,6 +427,23 @@
 		<input <?php echo helper_get_tab_index() ?> name="file" type="file" size="60" />
 	</td>
 </tr>
+<tr <?php echo helper_alternate_class() ?>>
+        <td class="category" width="15%">
+                <?php echo lang_get( 'file_comment' ) ?>
+        </td>
+        <td with="85%">
+                <input type="text" name="file_description" size="80" />
+        </td>
+</tr>
+<tr <?php echo helper_alternate_class() ?>>
+        <td class="category">
+                <?php echo lang_get( 'file_remarks' ) ?>
+        </td>
+        <td with="85%">
+                <input type="checkbox" name="patch" value="1" ><?php echo lang_get( 'file_patch' ) ?></input>
+        </td>
+</tr>
+
 <?php } ?>
 
 
--- bug_view_advanced_page.php	Fri Feb 13 10:33:24 2009
+++ bug_view_advanced_page.php	Wed May 27 13:42:33 2009
@@ -538,7 +538,7 @@
 <?php } # custom fields found ?>
 
 
-<!-- Attachments -->
+<!-- Attachments 
 <?php
 	$t_show_attachments = ( $t_bug->reporter_id == auth_get_current_user_id() ) || access_has_bug_level( config_get( 'view_attachments_threshold' ), $f_bug_id );
 
@@ -556,7 +556,7 @@
 <?php
 	}
 ?>
-
+-->
 <!-- Buttons -->
 <tr align="center">
 	<td align="center" colspan="6">
--- bug_view_page.php	Fri Feb 13 10:33:25 2009
+++ bug_view_page.php	Wed May 27 13:42:33 2009
@@ -446,7 +446,7 @@
 <?php } # custom fields found ?>
 
 
-<!-- Attachments -->
+<!-- Attachments
 <?php
 	$t_show_attachments = ( $t_bug->reporter_id == auth_get_current_user_id() ) || access_has_bug_level( config_get( 'view_attachments_threshold' ), $f_bug_id );
 
@@ -464,7 +464,7 @@
 <?php
 	}
 ?>
-
+-->
 <!-- Buttons -->
 <tr align="center">
 	<td align="center" colspan="6">
--- config_defaults_inc.php	Thu Jan 22 16:05:38 2009
+++ config_defaults_inc.php	Wed May 27 13:42:33 2009
@@ -848,6 +848,15 @@
 
 	# absolute path to the default upload folder.  Requires trailing / or \
 	$g_absolute_path_default_upload_folder = '';
+	
+	
+	# access level needed to mark file obsolete
+	# reporter can always mark file as an obsolete (aka request for remove)
+	$g_allow_mark_obsolete_threshold = DEVELOPER;
+	
+	# access level needed to mark file patch
+	# reporter can always mark file as a patch
+	$g_allow_mark_patch_threshold = DEVELOPER;
 
 	############################
 	# Mantis HTML Settings
--- config_inc.php	Fri Feb 13 10:33:24 2009
+++ config_inc.php	Tue May 26 16:04:38 2009
@@ -29,9 +29,9 @@
 	# set these values to match your setup
 	$g_hostname      = "localhost";
 	$g_db_type = 'mysql';
-	$g_database_name = "mantis";
-	$g_db_username   = "mantis";
-	$g_db_password   = "mantis";
+	$g_database_name = "mantis111";
+	$g_db_username   = "mantis111";
+	$g_db_password   = "mantis111";
 
 	# --- email variables -------------
 	$g_administrator_email  = 'mantis@cscanada.ca';
@@ -44,7 +44,7 @@
 # Patch to allow real name in FROM field in email notification
 # Mantis Issue 7546
 # start
-	$g_from_name		= 'CS Canada Mantis Bug Tracker';
+	$g_from_name		= 'PC 10 Mantis v1.1.1 branch Test Setup';
 # end
 
 
@@ -83,9 +83,9 @@
 
 	# --- Configuration : Display --------
 	#This is the browser window title (<TITLE> tag).
- 	$g_window_title = "CS Canada Issues Tracker";
+ 	$g_window_title = "PC 10 Mantis v1.1.1 branch Test Setup";
 	#This is a heading that is displayed in the viewing area of the page.
-	$g_page_title = "CS Canada";
+	$g_page_title = "PC 10 Mantis v1.1.1 branch";
 	#This option is used as a default value for user preferences.
 	#This field indicates whether users should get the simple bug report page,
 	#or the advanced bug report page, or both. Possible values are:
--- core/file_api.php	Fri Feb 13 10:33:21 2009
+++ core/file_api.php	Wed May 27 17:26:06 2009
@@ -129,15 +129,24 @@
 
 	# --------------------
 	# Check if the current user can delete attachments from the specified bug.
-	function file_can_delete_bug_attachments( $p_bug_id ) {
+	function file_can_delete_bug_attachments( $p_bug_id, $p_file_id = 0 ) {
 		if ( bug_is_readonly( $p_bug_id ) ) {
 			return false;
 		}
 
 		$t_reported_by_me	= bug_is_user_reporter( $p_bug_id, auth_get_current_user_id() );
 		$t_can_download		= access_has_bug_level( config_get( 'delete_attachments_threshold' ), $p_bug_id );
+		
+		if ( $p_file_id > 0 ) {
+			$t_owned_by_me		= file_is_user_owner( $p_file_id, auth_get_current_user_id() );
+		}
 # @@@ Fix this to be readable
+		if ( $p_file_id > 0 ) {
+			$t_can_download		= $t_can_download || ( $t_owned_by_me && config_get( 'allow_delete_own_attachments' ) );
+		} else {
+			# left due to compatibility reasons. should be removed.
 		$t_can_download		= $t_can_download || ( $t_reported_by_me && config_get( 'allow_delete_own_attachments' ) );
+		}
 
 		return $t_can_download;
 	}
@@ -154,18 +163,32 @@
 		}
 
 		$t_can_download = file_can_download_bug_attachments( $p_bug_id );
-		$t_can_delete   = file_can_delete_bug_attachments( $p_bug_id );
 		$t_preview_text_ext = config_get( 'preview_text_extensions' );
 		$t_preview_image_ext = config_get( 'preview_image_extensions' );
 
+		PRINT "<table width=\"100%\">\n";
+		PRINT "  <tr class=\"row-category\">\n";
+		PRINT "    <td>".lang_get( 'attachments')."</td>\n";
+		PRINT "    <td>".lang_get( 'file_type')."</td>\n";
+		PRINT "    <td>".lang_get( 'file_created')."</td>\n";
+		PRINT "    <td>".lang_get( 'file_size')."</td>\n";
+		PRINT "    <td>".lang_get( 'file_action')."</td>\n";
+		PRINT "</tr>\n";
+		$t_current_background = helper_alternate_class();
+
 		$image_previewed = false;
 		for ( $i = 0 ; $i < $num_files ; $i++ ) {
+ 			print "\n<tr ".$t_current_background.">\n";
 			$row = $t_attachment_rows[$i];
 			extract( $row, EXTR_PREFIX_ALL, 'v' );
 
 			$t_file_display_name = string_display_line( file_get_display_name( $v_filename ) );
 			$t_filesize		= number_format( $v_filesize );
 			$t_date_added	= date( config_get( 'normal_date_format' ), db_unixtimestamp( $v_date_added ) );
+ 			$t_can_delete = file_can_delete_bug_attachments( $p_bug_id, $v_id );
+			$t_description = string_display_line ( $v_description );
+			$t_can_mark_delete = file_can_mark_obsolete( $p_bug_id, $v_id );
+			$t_can_mark_patch = file_can_mark_patch( $p_bug_id, $v_id );
 
 			if ( $image_previewed ) {
 				$image_previewed = false;
@@ -187,22 +210,64 @@
 			$t_exists = config_get( 'file_upload_method' ) != DISK || file_exists( $v_diskfile );
 
 			if ( !$t_exists ) {
+ 				print "\n<td colspan=\"5\">\n";
 				print_file_icon ( $t_file_display_name );
 				PRINT '&nbsp;<span class="strike">' . $t_file_display_name . '</span> (attachment missing)';
+ 				print "\n</td>\n";
 			} else {
+ 				print "\n<td>\n";
+ 				if ( $v_patch )
+ 				    print "<B>P</B>";
 				PRINT $t_href_start;
 				print_file_icon ( $t_file_display_name );
-				PRINT $t_href_end . '&nbsp;' . $t_href_start . $t_file_display_name .
-					$t_href_end . "$t_href_clicket ($t_filesize bytes) <span class=\"italic\">$t_date_added</span>";
+ 				PRINT $t_href_end . '&nbsp;';
+ 				if ( $v_obsolete ) {
+ 				    if ( $t_can_delete || $t_can_mark_delete) {
+ 		    			PRINT $t_href_start . "<span class=\"strike\">" . $t_file_display_name . "</span>" . $t_href_end . $t_href_clicket;
+ 				    } else {
+ 					PRINT "<span class=\"strike\">".$t_file_display_name."</span>";
+ 				    }
+ 				} else {
+ 				    PRINT $t_href_start .  $t_file_display_name . $t_href_end . $t_href_clicket;
+ 				}
+ 				print "</td>";
+ 				print "<td>";
+ 				if ( $t_can_mark_patch && !$v_patch ) {
+ 				    print " [<a class=\"small\" href=\"bug_file_add.php?field=patch&file_id=$v_id&action=1&bug_id=$p_bug_id\">" . lang_get( 'file_patch' ) .'</a>]';
+ 				} else if ( $t_can_mark_patch && $v_patch ) {
+ 				    print " [<a class=\"small\" href=\"bug_file_add.php?field=patch&file_id=$v_id&action=0&bug_id=$p_bug_id\">" . lang_get( 'file_unpatch' ) .'</a>]';
+ 				} else if ( !$t_can_mark_patch && $v_patch ) {
+ 				    print lang_get( 'file_is_patch' );
+ 				} else {
+ 				    print $v_file_type;
+ 				}
+ 				print "</td>";
+ 				print "<td>".$t_date_added."</td>";
+ 				print "<td>".$t_filesize." bytes</td>";
 
+
+ 				print "<td>";
+ 				# if can change patch status
+ 				# if can set to delete
 				if ( $t_can_delete ) {
 					PRINT " [<a class=\"small\" href=\"bug_file_delete.php?file_id=$v_id\">" . lang_get('delete_link') . '</a>]';
 				}
 
+ 				if ( $t_can_mark_delete && !$v_obsolete ) {
+ 					PRINT " [<a class=\"small\" href=\"bug_file_add.php?field=obsolete&file_id=$v_id&action=1&bug_id=$p_bug_id\">" . lang_get( 'file_obsolete' ) . '</a>]';
+ 				}
+ 				if ( $t_can_mark_delete && $v_obsolete ) {
+ 					PRINT " [<a class=\"small\" href=\"bug_file_add.php?field=obsolete&file_id=$v_id&action=0&bug_id=$p_bug_id\">" . lang_get( 'file_unobsolete' ) . '</a>]';
+ 				}
 				if ( ( FTP == config_get( 'file_upload_method' ) ) && file_exists ( $v_diskfile ) ) {
 					PRINT ' (' . lang_get( 'cached' ) . ')';
 				}
 
+ 				print "\n</td>\n</tr>\n";
+ 				if ( strlen( $v_description ) > 0 ) {
+ 					print "<tr ".$t_current_background."><td colspan=\"5\">";
+ 					print $v_description . "</td></tr>";
+ 				}
 				if ( $t_can_download &&
 					( $v_filesize <= config_get( 'preview_attachments_inline_max_size' ) ) &&
 					( $v_filesize != 0 ) &&
@@ -222,6 +287,7 @@
 					PRINT " <span id=\"hideSection_$c_id\">[<a class=\"small\" href='#' id='attmlink_".$c_id."' onclick='swap_content(\"hideSection_".$c_id."\");swap_content(\"showSection_".$c_id."\");return false;'>". lang_get( 'show_content' ) ."</a>]</span>";
 					PRINT " <span style='display:none' id=\"showSection_$c_id\">[<a class=\"small\" href='#' id='attmlink_".$c_id."' onclick='swap_content(\"hideSection_".$c_id."\");swap_content(\"showSection_".$c_id."\");return false;'>". lang_get( 'hide_content' ) ."</a>]";
 
+					print "\n<tr ".$t_current_background.">\n<td colspan=\"5\">\n";
 					PRINT "<pre>";
 					switch ( config_get( 'file_upload_method' ) ) {
 						case DISK:
@@ -250,6 +316,7 @@
 					echo htmlspecialchars($v_content);
 
 					PRINT "</pre></span>\n";
+ 					print "</td></tr>";
 				}
 
 
@@ -258,6 +325,7 @@
 					( $v_filesize != 0 ) &&
 					( in_array( strtolower( file_get_extension( $t_file_display_name ) ), $t_preview_image_ext, true ) ) ) {
 
+ 					print "<tr ".$t_current_background."><td colspan=\"5\">";
 					$t_preview_style = 'border: 0;';
 					$t_max_width = config_get( 'preview_max_width' );
 					if ( $t_max_width > 0 ) {
@@ -274,13 +342,12 @@
 
 					PRINT "\n<br />$t_href_start<img alt=\"$t_title\" $t_preview_style src=\"file_download.php?file_id=$v_id&amp;type=bug\" />$t_href_end";
 					$image_previewed = true;
+ 					print "</td></tr>";
 				}
 			}
 
-			if ( $i != ( $num_files - 1 ) ) {
-				PRINT "<br />\n";
-			}
 		}
+ 		print "</table>";
 	}
 	# --------------------
 	# delete all files that are associated with the given bug
@@ -610,12 +678,20 @@
 			$t_bug_id		= 0;
 		}
 
+		if ( $p_user_id == -1 )
+		{
+			$p_user_id = auth_get_current_user_id();
+		}
 		# prepare variables for insertion
 		$c_bug_id		= db_prepare_int( $p_bug_id );
 		$c_project_id		= db_prepare_int( $t_project_id );
 		$c_file_type	= db_prepare_string( $p_file_type );
 		$c_title = db_prepare_string( $p_title );
 		$c_desc = db_prepare_string( $p_desc );
+		$c_patch = db_prepare_bool( $p_patch );
+		$c_obsolete = db_prepare_bool( $p_obsolete );
+		$c_user_id = db_prepare_int( $p_user_id );
+		
 
 		if( $t_project_id == ALL_PROJECTS ) {
 			$t_file_path = config_get( 'absolute_path_default_upload_folder' );
@@ -679,9 +755,9 @@
 		$c_id = ( 'bug' == $p_table ) ? $c_bug_id : $c_project_id;
 					
 		$query = "INSERT INTO $t_file_table
-						(" . $p_table . "_id, title, description, diskfile, filename, folder, filesize, file_type, date_added, content)
+						(" . $p_table . "_id, title, description, diskfile, filename, folder, filesize, file_type, date_added, content, patch, obsolete, user_id)
 					  VALUES
-						($c_id, '$c_title', '$c_desc', '$c_disk_file_name', '$c_new_file_name', '$c_file_path', $c_file_size, '$c_file_type', " . db_now() .", $c_content)";
+						($c_id, '$c_title', '$c_desc', '$c_disk_file_name', '$c_new_file_name', '$c_file_path', $c_file_size, '$c_file_type', " . db_now() .", $c_content, $c_patch, $c_obsolete, $c_user_id)";
 		db_query( $query );
 
 		if ( 'bug' == $p_table ) {
@@ -794,5 +870,61 @@
 		} else {
 			return '';
 		}
+	}
+        # --------------------
+        # Check if the current user can mark attachment  as a patch.
+        function file_can_mark_patch( $p_bug_id, $p_file_id ) {
+                if ( bug_is_readonly( $p_bug_id ) ) {
+                        return false;
+                }
+
+                $t_submitted_by_me       = file_is_user_owner( $p_file_id, auth_get_current_user_id() );
+                $t_can_mark             = access_has_bug_level( config_get( 'allow_mark_patch_threshold' ), $p_bug_id );
+                $t_can_download         = $t_can_mark || $t_submitted_by_me;
+
+                return $t_can_download;
+        }
+
+        # --------------------
+        # Check if the current user can mark attachment as a obsolete.
+        function file_can_mark_obsolete( $p_bug_id, $p_file_id ) {
+                if ( bug_is_readonly( $p_bug_id ) ) {
+                        return false;
+                }
+
+                $t_submitted_by_me       = file_is_user_owner( $p_file_id, auth_get_current_user_id() );
+                $t_can_mark             = access_has_bug_level( config_get( 'allow_mark_obsolete_threshold' ), $p_bug_id );
+                $t_can_download         = $t_can_mark || $t_submitted_by_me;
+
+                return $t_can_download;
+        }
+
+        # --------------------
+        # Marks/unmarks file as a patch/obsolete
+        function file_mark( $p_file_id,  $p_field, $p_action, $p_bug_id ) {
+                if ( bug_is_readonly( $p_bug_id ) ) {
+                        return false;
+                }
+		$t_bug_file_table = config_get( 'mantis_bug_file_table' );
+		$query = "UPDATE $t_bug_file_table
+					SET $p_field = $p_action
+					WHERE id = $p_file_id";
+		db_query( $query );
+        }
+
+        function file_is_user_owner( $p_file_id, $p_user_id ) {
+                 if ( $p_user_id == file_get_field( $p_file_id, 'user_id' ) ) {
+                    return true;
+                 }
+                 return false;
+        }
+
+	# abandon files on user deletion
+	function file_user_abandon( $p_user_id ) {
+		$t_bug_file_table = config_get ( 'mantis_bug_file_table' );
+		$query = "UPDATE $t_bug_file_table
+				SET user_id = 0
+				WHERE id = $p_user_id";
+		db_query( $query );
 	}
 ?>
--- admin/schema.php	Fri Feb 13 10:33:15 2009
+++ admin/schema.php	Wed May 27 14:41:02 2009
@@ -361,4 +361,12 @@
 	", Array( 'mysql' => 'TYPE=MyISAM', 'pgsql' => 'WITHOUT OIDS' ) ) );
 
 $upgrade[] = Array('CreateIndexSQL', Array( 'idx_typeowner', config_get( 'mantis_tokens_table' ), 'type, owner' ) );
+# mantisbt 0007835
+$upgrade[] = Array( 'AddColumnSQL', Array( config_get( 'mantis_bug_file_table' ), "
+	user_id			I UNSIGNED NOTNULL DEFAULT '0',
+	patch			L NOTNULL DEFAULT \"'0'\",
+	obsolete		L NOTNULL DEFAULT \"'0'\" ") );
 ?>
--- lang/strings_english.txt	Fri Feb 13 10:33:13 2009
+++ lang/strings_english.txt	Wed May 27 15:39:29 2009
@@ -1577,4 +1577,17 @@
 $s_graph_page = 'Graph Bug History';
 $s_graph_bug_page_link = 'Graph';
 
+# print_api.php
+$s_file_comment = 'File description';
+$s_file_remarks = 'Remarks';
+$s_file_patch = 'Mark patch';
+$s_file_unpatch = 'Unmark patch';
+$s_file_obsolete = 'Obsolete';
+$s_file_unobsolete = 'Not obsolete';
+$s_file_type = 'Type';
+$s_file_created = 'Created';
+$s_file_size = 'Size';
+$s_file_status = 'Status';
+$s_file_action = 'Action';
+$s_file_is_patch = 'patch';
 ?>
--- core/user_api.php	Fri Feb 13 10:33:21 2009
+++ core/user_api.php	Wed May 27 13:42:33 2009
@@ -25,6 +25,7 @@
 
 	require_once( $t_core_dir . 'email_api.php' );
 	require_once( $t_core_dir . 'ldap_api.php' );
+	require_once( $t_core_dir . 'file_api.php' );
 
 	### User API ###
 
@@ -524,6 +525,9 @@
 		}
 
 		user_clear_cache( $p_user_id );
+		
+		# abandon user file
+		file_user_abandon( $p_user_id );
 
 		# Remove account
 		$query = "DELETE FROM $t_user_table

Relationships

related to 0008134 closed it's not possible to delete own attachments 
has duplicate 0008854 closedgrangeway request: direct attachment replacement 
has duplicate 0003442 closedvboctor Add description to uploading files 
has duplicate 0006603 closeddregad Include descriptions with file attachments 
related to 0008068 confirmed Title of attachment isn't shown 
related to 0005009 acknowledged Being able to know at what step a file was uploaded ? 
related to 0008287 acknowledged Missing notification on file attachment 
related to 0008947 new Reference to uploaded file in Notes 

Activities

vboctor

vboctor

2007-06-22 03:45

manager   ~0014801

I can't seem to open the PNG file. I like the idea, but I was thinking that we should support the concept of tags. Hence, an issue can be associated with multiple tags, one of these tags can be "patch". We can still have a check box on the file upload form that automatically associated the "patch" tag with the issue. This will also make filtering easier since it will build on whatever infrastructure we use for tags.

giallu

giallu

2007-06-29 11:00

reporter   ~0014836

The "tag" concept looks interesting (maybe it's to be discussed further on the ML?) but I think the "patch" property is something to be assigned to single attachments, not to the whole issue.

I will try to formalize what it's required for this in the wiki, then I will ask for comments on the ML

smig1o

smig1o

2008-02-22 10:48

reporter   ~0017154

Patch submitted.. it must be checked I think

giallu

giallu

2008-02-25 17:54

reporter   ~0017198

Thanks for the contribution. Here is my comments on the patch.

First of all, I note you based the patch on 1.1 code. Our guidelines for stable releases http://www.mantisbt.org/wiki/doku.php/mantisbt:development_scheme does not allow us to add new features there, so you should port the patch to svn trunk.

That said, some technical stuff:

  1. the schema update should be done in admin/schema.php
  2. I think we can avoid having a new file bug_mark_obsolete.php the required logic should be added to bug_file_add.php
  3. I'd like obsoleting a previous file while attaching the new one. This means:
    3a: If current user is above "can_obsolete" threshold, make a checklist of non obsolete attachments and allow me to select from them
    3b. this should go in the same box where I upload the file (so it's handled by bug_file_add.php)
  4. The old "Delete" link should be available as before, but with the mark_as_deleted meaning.
  5. The Remove from DB action replaces the old "Delete" operation

For a first round I think it's enough... I also inquired about the status of print_bug_attachments_list() and it seems it is listed under Deprecated functions by mistake.

Thank you again

vboctor

vboctor

2008-02-26 03:16

manager   ~0017201

  1. Relating to field names (e.g. ispatch), we typically don't have the "is" prefix for the boolean flags.

  2. bug_mark_obsolete.php doesn't do access checking. This may go away based on giallu's comments. However, it is very important for action pages to re-validate the access level.

  3. bug_mark_obsolete.php and similar pages should not include SQL queries. The scripts should call core APIs that execute the necessary sanitization and queries.

  4. Are we assuming that reporters can always obsolete attachments and mark them as patches? This is not clear in the documentation in config_default_inc.php.

  5. There is a couple of typos in the comments for $g_allow_mark_patch_threshold in config_defaults_inc.php.

  6. "unpatch" and "unobsolete" - I don't think these terms make a lot of sense.

  7. Would be nice to see screenshots of the GUI. Or if there is a demo instance available to try.

smig1o

smig1o

2008-02-27 07:06

reporter   ~0017206

Last edited: 2008-02-27 07:06

Thanks for comments.

  1. @giallu1 & @vboctor 1 - I've done changes in admin/schema.php. fileds names are patch and obsolete.

  2. @giallu 2 & @vboctor 2 - logic moved to bug_file_add.php so all checks done in there. bug_mark_obsolete.php and such removed.

  3. @vboctor 3 - new function added to file_api.php so now no SQL in GUI files.

  4. @vboctor 4&5 - comments updated in config_default_inc.php. Typos.. well English isnt my prime language so im gonna need help with that.

  5. @vboctor 6 - Ill change it in next patch.

  6. @vboctor 7 - Ill try to submit a screenshoot when Ill finish with GUI, but need some more info from giallu for that.

smig1o

smig1o

2008-02-29 04:33

reporter   ~0017217

Ok. I think stage 1 is ready.
I post patch and screenshoot too.
<screenshoot>

  • File plik.exe is not submitted by current user and is market as obsolete (remove request). All info about the file is available.
  • File 15.jpg us >regular file not submitted by current user
  • File 00017972.jpg is patch file not submitted by current user.
  • File 381520.gif if submitted by current user, so it may be market as a patch or as an obsolete.
  • File baza.xls is submitted by current user. Its patch and its marked as obsolete.
    Configuration doesnt allow current user to delete attachments. Even if he submitted it.
    All was moved to >Attach file< box.
    </screenshoot>
    <changelog>
    I had to add 3 fileds to mantis_bug_file_table:
  • patch - curently as integer but should be smaller (smallint?? tinytiny??)
  • obsolete - same as above
  • user_id - id of user that submitted the file. It isnt foreign key mantis_user_table(id) since some files may be adandoned
    I had to update bug_copy function in bug_api.php cos it contains SQL query instead of file_add function call.
    file_api.php
  • file_can_delete_bug_attachmets - now it checks >file submitter< vs >current user<
  • file_add - added new fields to function definition
  • file_can_mark_patch/obsolete - 2 functions that checks if current user can perform an action
  • file_mark - sets/unsets file as patch/obsolete
  • file_user_abandon - called from user_delete function

    print_api - modified
    user_api- modified
    strings_english and string_polish - added new strings

    config_defaults_inc.php
    $g_allow_mark_obsolete_threshold
    $g_allow_mark_patch_threshold
    added with comment
    </changelog>

Someone should reviewe it and apply (I hope)

giallu

giallu

2008-03-02 19:33

reporter   ~0017238

I tried to apply the patch but failed:

[giallu@hal9001 mantisbt]$ patch -p2 < diffs
patching file admin/schema.php
patching file bug_file_add.php
patching file bug_file_upload_inc.php
patching file bug_view_advanced_page.php
patching file bug_view_page.php
patching file config_defaults_inc.php
Hunk 0000001 FAILED at 18.
patch: **** malformed patch at line 180: diff -Naur mantis_orig/mantisbt/core/bug_api.php mantis_rd/mantisbt/core/bug_api.php

any idea?

smig1o

smig1o

2008-03-03 02:48

reporter   ~0017240

No idea why.. if patch for config_defailts_inc.php in in the middle of the patch it fails. If I move it to the end.. its ok.

Im no diff expert...

The fixed file posted as last.

vboctor

vboctor

2008-03-03 02:55

manager   ~0017241

That is what I hate about patches. I keep getting these hunk errors!

smig1o

smig1o

2008-03-03 03:33

reporter   ~0017242

Did you get today's fixed patch??

giallu

giallu

2008-03-03 05:09

reporter   ~0017245

Well... hunk errors means something is not quite in sync between the reference revision the patch is based on and the revision you are applying the patch to.

it's sort of svn and cvs conflict state, so you definitely want to see them :)

In this case, it seems smig1o was handcrafting the patch file...

smig1o

smig1o

2008-03-06 14:23

reporter   ~0017272

So here is updated patch with brand new attachments table.
I also did some sanitation (fixed db schema, fixed db calls)
Patch made against lastes source (5089)

Enjoy..

vboctor

vboctor

2008-03-08 04:31

manager   ~0017293

A couple of comments:

  1. Preview attachments seems to be broken (the table gets messed up, text is previewed in strange way, etc).
  2. The report issue page doesn't seem to be updated yet.
  3. We should add a field to the attachments that keep track of who uploaded the attachments.
smig1o

smig1o

2008-03-08 07:56

reporter   ~0017295

1 @vboctor 2 Seems that I have forgotten about report page... sorru :)
2 @vboctor 3 Well mantis_bug_file_table has now >user_id< field with id of user that uploaded the file. So seems I dont understand that. Do you want to display >uploader< in file list too??
3 @vboctor 1 What do you mean >broken; messed up<?? I didnt noticed that... Maby some screenshoot so I could fix that. On the other hand.. Do we ned that preview?? If someone claims it broken/messed he can always turn it off...
Anyways I need more info about that to fix it.
thanks for feedback too :)

smig1o

smig1o

2008-03-11 12:58

reporter   ~0017313

Ok added first >final< patch of the filehelper stage1. I hope its good enough to put it into mantis core.
patch and obsolete fields are now L type.

emathieu

emathieu

2009-05-28 07:51

reporter   ~0021955

I found the patch very useful, thank you smig1o.
Since I had to make some changes to incorporate it into 1.1.6, I attached an updated patch based on this version.

atrol

atrol

2013-08-16 12:43

developer   ~0037885

Removed assignment. giallu will not contribute to this issue in near future.

lesley.liu

lesley.liu

2017-04-26 06:39

reporter   ~0056721

Hi,
Is it possible to provide patch for later mantisbt?
I was requested to patch on 1.2.15 for https://www.mantisbt.org/bugs/view.php?id=7835#c17217, to have the obsolete option.
A patch file for 1.2.15 or 1.3.10 will be appreciated.
Thanks in advance.