2014-11-26 15:09 EST

View Issue Details Jump to Notes ] Wiki ]
IDProjectCategoryView StatusLast Update
0012557mantisbtbugtrackerpublic2014-01-21 18:42
Reporterdregad 
Assigned To 
PrioritynormalSeverityfeatureReproducibilityN/A
StatusnewResolutionopen 
Product Version1.2.9 
Target VersionFixed in Version 
Summary0012557: Bug view page: add monitoring for user select from list
DescriptionIt would be nice when adding users to the monitoring list of an issue, to be able to select them from a list instead of having to type the username blindly, particularly when Mantis is configured to display Realnames.
Tagspatch
Attached Files
  • patch file icon 0001-Fix-#12557:-Select-user-from-list-when-making-them-monitor-an-issue.patch (6,454 bytes) 2010-11-23 16:26 - 
    From f93c18bc90d1fda86ec66ce9c33f984a77a40fdc Mon Sep 17 00:00:00 2001
    From: Damien Regad <damien.regad@merckserono.net>
    Date: Tue, 23 Nov 2010 22:27:30 +0100
    Subject: [PATCH] Fix #12557: Select user from list when making them monitor an issue
    
    This is more user friendly than having to type the the username, particularly
    when Mantis is configured to display Realnames
    ---
     bug_monitor_add.php           |   14 +++-----
     bug_monitor_list_view_inc.php |   78 ++++++++++++++++++++++++++++++++++-------
     lang/strings_english.txt      |    2 +-
     3 files changed, 71 insertions(+), 23 deletions(-)
    
    diff --git a/bug_monitor_add.php b/bug_monitor_add.php
    index 6bcc027..ce55d4d 100644
    --- a/bug_monitor_add.php
    +++ b/bug_monitor_add.php
    @@ -34,20 +34,16 @@
     	$f_bug_id = gpc_get_int( 'bug_id' );
     	$t_bug = bug_get( $f_bug_id, true );
     	$f_username = gpc_get_string( 'username', '' );
    +	$f_user_id = gpc_get_string( 'user_id', '' );
     
     	$t_logged_in_user_id = auth_get_current_user_id();
     
    -	if ( is_blank( $f_username ) ) {
    +	if ( is_blank( $f_user_id ) ) {
     		$t_user_id = $t_logged_in_user_id;
     	} else {
    -		$t_user_id = user_get_id_by_name( $f_username );
    -		if ( $t_user_id === false ) {
    -			$t_user_id = user_get_id_by_realname( $f_username );
    -
    -			if ( $t_user_id === false ) {
    -				error_parameters( $f_username );
    -				trigger_error( ERROR_USER_BY_NAME_NOT_FOUND, E_USER_ERROR );
    -			}
    +		$t_user_id = $f_user_id;
    +		if( 0 == $t_user_id ) {
    +			trigger_error( ERROR_USER_BY_ID_NOT_FOUND, E_USER_ERROR );
     		}
     	}
     
    diff --git a/bug_monitor_list_view_inc.php b/bug_monitor_list_view_inc.php
    index 9a539f5..e2d6c8f 100644
    --- a/bug_monitor_list_view_inc.php
    +++ b/bug_monitor_list_view_inc.php
    @@ -37,12 +37,12 @@ if ( access_has_bug_level( config_get( 'show_monitor_list_threshold' ), $f_bug_i
     	$result = db_query_bound($query, Array( $c_bug_id ) );
     	$num_users = db_num_rows($result);
     
    -	$t_users = array();
    +	$t_users_monitoring = array();
     	for ( $i = 0; $i < $num_users; $i++ ) {
     		$row = db_fetch_array( $result );
    -		$t_users[$i] = $row['user_id'];
    +		$t_users_monitoring[$i] = $row['user_id'];
     	}
    -	user_cache_array_rows( $t_users );
    +	user_cache_array_rows( $t_users_monitoring );
     
     	echo '<a name="monitors" id="monitors" /><br />';
     
    @@ -69,23 +69,75 @@ if ( access_has_bug_level( config_get( 'show_monitor_list_threshold' ), $f_bug_i
     			$t_can_delete_others = access_has_bug_level( config_get( 'monitor_delete_others_bug_threshold' ), $f_bug_id ); 
     	 		for ( $i = 0; $i < $num_users; $i++ ) {
     				echo ($i > 0) ? ', ' : '';
    -				echo print_user( $t_users[$i] );
    +				echo print_user( $t_users_monitoring[$i] );
     				if ( $t_can_delete_others ) {
    -					echo ' [<a class="small" href="' . helper_mantis_url( 'bug_monitor_delete.php' ) . '?bug_id=' . $f_bug_id . '&user_id=' . $t_users[$i] . form_security_param( 'bug_monitor_delete' ) . '">' . lang_get( 'delete_link' ) . '</a>]';
    +					echo ' [<a class="small" href="' . helper_mantis_url( 'bug_monitor_delete.php' ) 
    +						. '?bug_id=' . $f_bug_id . '&user_id=' . $t_users_monitoring[$i] 
    +						. form_security_param( 'bug_monitor_delete' ) . '">' 
    +						. lang_get( 'delete_link' ) . '</a>]';
     				}
     	 		}
      		}
     
     		if ( access_has_bug_level( config_get( 'monitor_add_others_bug_threshold' ), $f_bug_id ) ) {
    -			echo '<br /><br />', lang_get( 'username' );
    +
    +			# Build list of users who can monitor the bug, excluding those already monitoring it
    +			# @@@ Code is mostly based on print_user_option_list - maybe modify that slightly, to avoid code duplication
    +			$t_users_can_monitor = project_get_all_user_rows( $g_project_override, config_get( 'monitor_bug_threshold' ) );
    +
    +			$t_display = array();
    +			$t_sort = array();
    +			$t_show_realname = ( ON == config_get( 'show_realname' ) );
    +			$t_sort_by_last_name = ( ON == config_get( 'sort_by_last_name' ) );
    +
    +			foreach( $t_users_can_monitor as $key => $t_user ) {
    +
    +				# If user is already monitoring the issue, remove them from list
    +				if( in_array( $t_user['id'], $t_users_monitoring ) ) {
    +					unset( $t_users_can_monitor[$key] );
    +					continue;
    +				}
    +
    +				$t_user_name = string_attribute( $t_user['username'] );
    +				$t_sort_name = utf8_strtolower( $t_user_name );
    +				if( $t_show_realname && ( $t_user['realname'] <> '' ) ) {
    +					$t_user_name = string_attribute( $t_user['realname'] );
    +					if( $t_sort_by_last_name ) {
    +						$t_sort_name_bits = explode( ' ', utf8_strtolower( $t_user_name ), 2 );
    +						$t_sort_name = ( isset( $t_sort_name_bits[1] ) ? $t_sort_name_bits[1] . ', ' : '' ) . $t_sort_name_bits[0];
    +					} else {
    +						$t_sort_name = utf8_strtolower( $t_user_name );
    +					}
    +				}
    +				$t_display[] = $t_user_name;
    +				$t_sort[] = $t_sort_name;
    +			}
    +
    +			# Display form only if there are users who can monitor the bug
    +			if( count( $t_users_can_monitor ) > 0 ) {
    +				array_multisort( $t_sort, SORT_ASC, SORT_STRING, $t_users_can_monitor, $t_display );
    +				echo '<br /><br />';
    +?>
    +				<form method="get" action="bug_monitor_add.php">
    +				<?php echo form_security_field( 'bug_monitor_add' ) ?>
    +					<input type="hidden" name="bug_id" value="<?php echo (integer)$f_bug_id; ?>" />
    +					<select name="user_id">
    +						<option value="0"></option>";
    +<?php
    +						# Build selection list with all users who can monitor this bug
    +						foreach( $t_users_can_monitor as $key => $t_user ) {
    +							echo '<option value="' . $t_user['id'] . '" ';
    +							echo '>' . string_attribute( $t_display[$key] ) . '</option>';
    +						}
    +?>
    +					</select>
    +
    +					<input type="submit" class="button" value="<?php echo lang_get( 'add_user_to_monitor' ) ?>" />
    +				</form>
    +<?php
    +			}
    +		}
     ?>
    -		<form method="get" action="bug_monitor_add.php">
    -		<?php echo form_security_field( 'bug_monitor_add' ) ?>
    -			<input type="hidden" name="bug_id" value="<?php echo (integer)$f_bug_id; ?>" />
    -			<input type="text" name="username" />
    -			<input type="submit" class="button" value="<?php echo lang_get( 'add_user_to_monitor' ) ?>" />
    -		</form>
    -		<?php } ?>
     	</td>
     </tr>
     </table>
    diff --git a/lang/strings_english.txt b/lang/strings_english.txt
    index eb21912..da61f2e 100644
    --- a/lang/strings_english.txt
    +++ b/lang/strings_english.txt
    @@ -1248,7 +1248,7 @@ $s_move_bug_button = 'Move';
     $s_attached_files = 'Attached Files';
     $s_publish = 'Publish';
     $s_cached = 'Cached';
    -$s_add_user_to_monitor = 'Add';
    +$s_add_user_to_monitor = 'Start Monitoring';
     
     # view_bug_inc.php
     
    -- 
    1.7.1
    
    
  • png file icon Screenshot.png (7,997 bytes) 2010-11-23 16:32 - 
    png file icon Screenshot.png (7,997 bytes) 2010-11-23 16:32 + 
  • patch file icon 0001-Fix-12557-for-mantis-1.2.5.patch (6,026 bytes) 2011-04-06 05:30 - 
    From e145e849c8dd86fc1e57acc4bc076ff780874690 Mon Sep 17 00:00:00 2001
    From: Damien Regad <damien.regad@merckserono.net>
    Date: Tue, 23 Nov 2010 22:27:30 +0100
    Subject: [PATCH] Fix #12557: Select user from list when making them monitor an issue
    
    This is more user friendly than having to type the the username, particularly
    when Mantis is configured to display Realnames
    ---
     bug_monitor_add.php           |   14 +++-----
     bug_monitor_list_view_inc.php |   72 +++++++++++++++++++++++++++++++++++------
     lang/strings_english.txt      |    2 +-
     3 files changed, 68 insertions(+), 20 deletions(-)
    
    diff --git a/bug_monitor_add.php b/bug_monitor_add.php
    index 7aca38c..5ba7b13 100644
    --- a/bug_monitor_add.php
    +++ b/bug_monitor_add.php
    @@ -34,20 +34,16 @@
     	$f_bug_id = gpc_get_int( 'bug_id' );
     	$t_bug = bug_get( $f_bug_id, true );
     	$f_username = gpc_get_string( 'username', '' );
    +	$f_user_id = gpc_get_string( 'user_id', '' );
     
     	$t_logged_in_user_id = auth_get_current_user_id();
     
    -	if ( is_blank( $f_username ) ) {
    +	if ( is_blank( $f_user_id ) ) {
     		$t_user_id = $t_logged_in_user_id;
     	} else {
    -		$t_user_id = user_get_id_by_name( $f_username );
    -		if ( $t_user_id === false ) {
    -			$t_user_id = user_get_id_by_realname( $f_username );
    -
    -			if ( $t_user_id === false ) {
    -				error_parameters( $f_username );
    -				trigger_error( ERROR_USER_BY_NAME_NOT_FOUND, E_USER_ERROR );
    -			}
    +		$t_user_id = $f_user_id;
    +		if( 0 == $t_user_id ) {
    +			trigger_error( ERROR_USER_BY_ID_NOT_FOUND, E_USER_ERROR );
     		}
     	}
     
    diff --git a/bug_monitor_list_view_inc.php b/bug_monitor_list_view_inc.php
    index 039847d..de90565 100644
    --- a/bug_monitor_list_view_inc.php
    +++ b/bug_monitor_list_view_inc.php
    @@ -51,26 +51,78 @@ if ( access_has_bug_level( config_get( 'show_monitor_list_threshold' ), $f_bug_i
     		if ( 0 == $num_users ) {
     			echo lang_get( 'no_users_monitoring_bug' );
     		} else {
    -			$t_can_delete_others = access_has_bug_level( config_get( 'monitor_delete_others_bug_threshold' ), $f_bug_id ); 
    +			$t_can_delete_others = access_has_bug_level( config_get( 'monitor_delete_others_bug_threshold' ), $f_bug_id );
     	 		for ( $i = 0; $i < $num_users; $i++ ) {
     				echo ($i > 0) ? ', ' : '';
     				echo print_user( $t_users[$i] );
     				if ( $t_can_delete_others ) {
    -					echo ' [<a class="small" href="' . helper_mantis_url( 'bug_monitor_delete.php' ) . '?bug_id=' . $f_bug_id . '&user_id=' . $t_users[$i] . form_security_param( 'bug_monitor_delete' ) . '">' . lang_get( 'delete_link' ) . '</a>]';
    +					echo ' [<a class="small" href="' . helper_mantis_url( 'bug_monitor_delete.php' )
    +						. '?bug_id=' . $f_bug_id . '&user_id=' . $t_users[$i]
    +						. form_security_param( 'bug_monitor_delete' ) . '">'
    +						. lang_get( 'delete_link' ) . '</a>]';
     				}
     	 		}
      		}
     
     		if ( access_has_bug_level( config_get( 'monitor_add_others_bug_threshold' ), $f_bug_id ) ) {
    -			echo '<br /><br />', lang_get( 'username' );
    +
    +			# Build list of users who can monitor the bug, excluding those already monitoring it
    +			# @@@ Code is mostly based on print_user_option_list - maybe modify that slightly, to avoid code duplication
    +			$t_users_can_monitor = project_get_all_user_rows( $g_project_override, config_get( 'monitor_bug_threshold' ) );
    +
    +			$t_display = array();
    +			$t_sort = array();
    +			$t_show_realname = ( ON == config_get( 'show_realname' ) );
    +			$t_sort_by_last_name = ( ON == config_get( 'sort_by_last_name' ) );
    +
    +			foreach( $t_users_can_monitor as $key => $t_user ) {
    +
    +				# If user is already monitoring the issue, remove them from list
    +				if( in_array( $t_user['id'], $t_users ) ) {
    +					unset( $t_users_can_monitor[$key] );
    +					continue;
    +				}
    +
    +				$t_user_name = string_attribute( $t_user['username'] );
    +				$t_sort_name = utf8_strtolower( $t_user_name );
    +				if( $t_show_realname && ( $t_user['realname'] <> '' ) ) {
    +					$t_user_name = string_attribute( $t_user['realname'] );
    +					if( $t_sort_by_last_name ) {
    +						$t_sort_name_bits = explode( ' ', utf8_strtolower( $t_user_name ), 2 );
    +						$t_sort_name = ( isset( $t_sort_name_bits[1] ) ? $t_sort_name_bits[1] . ', ' : '' ) . $t_sort_name_bits[0];
    +					} else {
    +						$t_sort_name = utf8_strtolower( $t_user_name );
    +					}
    +				}
    +				$t_display[] = $t_user_name;
    +				$t_sort[] = $t_sort_name;
    +			}
    +
    +			# Display form only if there are users who can monitor the bug
    +			if( count( $t_users_can_monitor ) > 0 ) {
    +				array_multisort( $t_sort, SORT_ASC, SORT_STRING, $t_users_can_monitor, $t_display );
    +				echo '<br /><br />';
    +?>
    +				<form method="get" action="bug_monitor_add.php">
    +				<?php echo form_security_field( 'bug_monitor_add' ) ?>
    +					<input type="hidden" name="bug_id" value="<?php echo (integer)$f_bug_id; ?>" />
    +					<select name="user_id">
    +						<option value="0"></option>";
    +<?php
    +						# Build selection list with all users who can monitor this bug
    +						foreach( $t_users_can_monitor as $key => $t_user ) {
    +							echo '<option value="' . $t_user['id'] . '" ';
    +							echo '>' . string_attribute( $t_display[$key] ) . '</option>';
    +						}
    +?>
    +					</select>
    +
    +					<input type="submit" class="button" value="<?php echo lang_get( 'add_user_to_monitor' ) ?>" />
    +				</form>
    +<?php
    +			}
    +		}
     ?>
    -		<form method="get" action="bug_monitor_add.php">
    -		<?php echo form_security_field( 'bug_monitor_add' ) ?>
    -			<input type="hidden" name="bug_id" value="<?php echo (integer)$f_bug_id; ?>" />
    -			<input type="text" name="username" />
    -			<input type="submit" class="button" value="<?php echo lang_get( 'add_user_to_monitor' ) ?>" />
    -		</form>
    -		<?php } ?>
     	</td>
     </tr>
     </table>
    diff --git a/lang/strings_english.txt b/lang/strings_english.txt
    index cff3989..e3069a4 100644
    --- a/lang/strings_english.txt
    +++ b/lang/strings_english.txt
    @@ -1248,7 +1248,7 @@ $s_move_bug_button = 'Move';
     $s_attached_files = 'Attached Files';
     $s_publish = 'Publish';
     $s_cached = 'Cached';
    -$s_add_user_to_monitor = 'Add';
    +$s_add_user_to_monitor = 'Start Monitoring';
     
     # view_bug_inc.php
     
    -- 
    1.7.1
    
    
    patch file icon 0001-Fix-12557-for-mantis-1.2.5.patch (6,026 bytes) 2011-04-06 05:30 + 

- Relationships
related to 0012677acknowledged Please change a search option to manage users 
has duplicate 0015891closeddregad user dropdown selection box to assign viewers? 
+ Relationships

-  Notes
User avatar

~0027465

dregad (developer)

Attached is my first shot at implementing this. It works but I am not fully satisfied by the code as it duplicates a lot of the logic in print_user_option_list.

I am also not sure about the wording for the button, and whether there should be an explanatory text in front of the selection list.

Feedback welcome.
User avatar

~0028543

dregad (developer)

Updated patch (applies on top of 1.2.5) attached
User avatar

~0029631

jsiegel5 (reporter)

Hi dregad,
Thanks for updating the patch to work with 1.2.5 and later. I spent an hour trying to figure out how to apply the older patch to 1.2.7 before it occurred to me to check this ticket for an update. My team really likes thie feature!
Regards, Jeff
User avatar

~0029670

dregad (developer)

An alternate and maybe better way of implementing this feature could be to use the same code as proposed by daryn in 0012677:0028099 - it would at least avoid the code duplication from print_user_option_list (but only works in 1.3.x).
User avatar

~0031678

baamster (reporter)

Hi, I have no clue how to impelment a .patch file. Any tips?
User avatar

~0031681

dregad (developer)

http://lmgtfy.com/?q=apply+patch [^]
+  Notes

- Issue History
Date Modified Username Field Change
2010-11-23 16:22 dregad New Issue
2010-11-23 16:26 dregad File Added: 0001-Fix-#12557:-Select-user-from-list-when-making-them-monitor-an-issue.patch
2010-11-23 16:26 dregad Tag Attached: patch
2010-11-23 16:32 dregad Note Added: 0027465
2010-11-23 16:32 dregad File Added: Screenshot.png
2010-11-30 09:01 dhx Target Version => 1.3.x
2011-04-06 05:30 dregad File Added: 0001-Fix-12557-for-mantis-1.2.5.patch
2011-04-06 05:30 dregad Note Added: 0028543
2011-09-02 20:24 jsiegel5 Note Added: 0029631
2011-09-09 10:53 dregad Note Added: 0029670
2011-09-09 10:53 dregad Product Version git trunk => 1.2.9
2011-09-09 10:53 dregad Relationship added related to 0012677
2012-04-18 03:28 baamster Note Added: 0031678
2012-04-18 04:15 dregad Note Added: 0031681
2013-05-21 09:11 dregad Relationship added has duplicate 0015891
2013-08-14 08:36 MishaMart Issue cloned: 0016267
2013-08-16 04:38 hero2289 Tag Attached: closed
2013-08-16 06:33 atrol Tag Detached: closed
2014-01-21 18:42 atrol Target Version 1.3.x =>
+ Issue History