View Issue Details

IDProjectCategoryView StatusLast Update
0012557mantisbtbugtrackerpublic2019-06-20 06:03
Reporterdregad Assigned To 
PrioritynormalSeverityfeatureReproducibilityN/A
Status newResolutionopen 
Product Version1.2.9 
Target VersionFixed in Version 
Summary0012557: Bug view page: add monitoring for user select from list
Description

It 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

Relationships

related to 0012677 closedatrol Please change a search option to manage users 
related to 0025815 resolveddregad Users can't add monitors if access < show_monitor_list_threshold and >= monitor_add_others_bug_threshold 
has duplicate 0015891 closeddregad user dropdown selection box to assign viewers? 
has duplicate 0019490 closedatrol How can we add easily monitoring user in a mantis 
has duplicate 0025837 closedatrol Filed add users who track incident like a list from all users 
related to 0021099 new Support auto-complete when adding user to monitor list on an issue 

Activities

dregad

dregad

2010-11-23 16:26

developer  

0001-Fix-#12557:-Select-user-from-list-when-making-them-monitor-an-issue.patch (6,454 bytes)
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

dregad

dregad

2010-11-23 16:32

developer   ~0027465

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.

dregad

dregad

2010-11-23 16:32

developer  

Screenshot.png (7,997 bytes)
Screenshot.png (7,997 bytes)
dregad

dregad

2011-04-06 05:30

developer  

0001-Fix-12557-for-mantis-1.2.5.patch (6,026 bytes)
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

dregad

dregad

2011-04-06 05:30

developer   ~0028543

Updated patch (applies on top of 1.2.5) attached

jsiegel5

jsiegel5

2011-09-02 20:24

reporter   ~0029631

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

dregad

dregad

2011-09-09 10:53

developer   ~0029670

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).

baamster

baamster

2012-04-18 03:28

reporter   ~0031678

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

dregad

dregad

2012-04-18 04:15

developer   ~0031681

http://lmgtfy.com/?q=apply+patch

Discotechnica

Discotechnica

2015-08-27 17:57

reporter   ~0051320

Do these patch files work for MantisBT 1.2.15?
I renamed the files above a.patch and b.patch for easier typing and tried the following command. It did not work unfortunately:

/home1/MYSITE/public_html/bugs$ patch --dry-run < a.patch
patching file bug_monitor_add.php
patching file bug_monitor_list_view_inc.php
Hunk 0000001 FAILED at 37.
Hunk 0000002 succeeded at 54 (offset -15 lines).
1 out of 2 hunks FAILED -- saving rejects to file bug_monitor_list_view_inc.php.rej
can't find file to patch at input line 154
Perhaps you should have used the -p or --strip option?
The text leading up to this was:

|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

File to patch:
Skip this patch? [y]
Skipping patch.
1 out of 1 hunk ignored

dregad

dregad

2015-08-28 03:33

developer   ~0051321

Hello,

I just double-checked and can confirm that the patch does apply cleanly on latest 1.2.20dev (so it most likely does on 1.2.15 as well).

When applying git-formatted patches, as mentioned in the error message you got, you need to use the -p option, like so:

<pre>
dregad@dregad ~/dev/mantisbt (12x) $ patch --dry-run -p1 <12557.patch
checking file bug_monitor_add.php
checking file bug_monitor_list_view_inc.php
checking file lang/strings_english.txt
Hunk 0000001 succeeded at 1266 (offset 18 lines).
</pre>

HTH

Discotechnica

Discotechnica

2015-08-28 13:58

reporter   ~0051323

Thanks dregad for the help. I have no experience with .patch and I don't want to accidentally break my mantis install so I'm a bit cautious!

I ran the patch with the flags you suggested and got the error and output shown below. (I have rolled back the patch for the time being).

From googling it suggests manually patching the file with the details from the .rej file but I was unable to find "$t_users = array();" in my original file. I also downloaded mantis 1.2.19 and checked the same file there and also could not find that string.

-------RUNNING THE FIRST PATCH-------
/home1/MYSITE/public_html/bugs$ patch -p1 < a.patch
patching file bug_monitor_add.php
patching file bug_monitor_list_view_inc.php
Hunk 0000001 FAILED at 37.
Hunk 0000002 succeeded at 54 (offset -15 lines).
1 out of 2 hunks FAILED -- saving rejects to file bug_monitor_list_view_inc.php.rej
patching file lang/strings_english.txt
Hunk 0000001 succeeded at 1265 (offset 17 lines).

-------bug_monitor_list_view_inc.php.rej FROM FIRST PATCH-------
--- bug_monitor_list_view_inc.php
+++ bug_monitor_list_view_inc.php
@@ -37,12 +37,12 @@
$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 />';

dregad

dregad

2015-08-29 04:21

developer   ~0051324

I don't have time to look into details atm, but I suspect you're attempting to apply the old patch (for Mantis <= 1.2.4). Try again with 0001-Fix-12557-for-mantis-1.2.5.patch

Discotechnica

Discotechnica

2015-08-31 14:41

reporter   ~0051336

That worked. Thanks dregad!

====== Summary for future readers: ======

  • If you are patching a mantis version that is greater than or equal to 1.2.5 then just run 0001-Fix-12557-for-mantis-1.2.5.patch
  • As of this post, this patch has been tested up to mantis 1.2.20

====== How to patch (for noobs): ======

  • Note you can break stuff if you don't know what you're doing, likely even if you follow these instructions.
  • Make a backup of your site.
  • This site has useful information http://www.thegeekstuff.com/2014/12/patch-command-examples/
  • On Windows, I used WinSCP to connect to my site's FTP address.
  • Browse to the root directory of your mantis install, (www.mysite.com/bugs/).
  • Copy the patch file to this root directory from your computer.
  • Open a terminal window via WinSCP (Ctrl+T, or the black button with a > in it)
  • You may need to enable shell access from your domain host. (I had to enable mine via the domain billing site, not via cpanel. This is likely up to your webhost.)
  • Test run your patch by using: patch --dry-run -p1 < patchFileName.patch
  • Use flag -p1 in your patch command.
  • Run the patch with this command patch -p1 < patchFileName.patch
  • Delete the patch file.
dregad

dregad

2015-09-01 02:35

developer   ~0051338

Glad you could sort things out, and thanks for posting your feedback.

cid

cid

2017-01-13 04:34

reporter   ~0055100

Hello,
is it possible to update patch add monitoring for user select from list for Mantis version 2.0.0 ?
Thanks

libregeek

libregeek

2017-01-16 00:33

reporter   ~0055142

@cid
You can use this simple plugin to make the user monitoring input box into an autocomplete with multiple values. https://github.com/ejyothi/MantisBT-AjaxUserMonitoring

(This works with MantisBT-1.3 ( use master-1.3.x branch) and MantisBT-2.0 (master branch)

elftron

elftron

2017-01-22 19:24

reporter   ~0055257

@libregeek; I have tried the plugin but it says it needs MantisBt Core2.0.0 and I am using 1.3.5
How do I get it to work with 1.3.5. I am not very experienced with plugins so I am probably missing something obvious.

Thanks

libregeek

libregeek

2017-02-03 01:42

reporter   ~0055462

@elftron Try master-1.3.x branch instead of the branch. You can get it directly from https://github.com/ejyothi/MantisBT-AjaxUserMonitoring/tree/master-1.3.x

elftron

elftron

2017-02-05 16:56

reporter   ~0055497

@libregeek Thank you., Works perfectly and I now have a greater understanding of the Master Tree system

JackBeauregard

JackBeauregard

2017-05-03 02:22

reporter   ~0056763

Hello, since all my projects in Mantis are private I'd like to see only users who belong to the current project, tried this plugin but everyone sees every user to add in the box. Any idea?

sneuf

sneuf

2018-04-05 06:40

reporter   ~0059441

@dregad
Is it possible to integrate "add monitoring user select from drop down list" into Mantis (Version 2.13.x / 2.14.x)?
Thanks

mahindra

mahindra

2018-05-19 03:25

reporter   ~0059851

related to
0024139
0024436 urgent set this on hold please
0023375
0024435
0024378
0024087
0024432

and the cause for Realnameproblems since 2.12.0 which are solved by this https://mantisbt.org/bugs/view.php?id=24139#c59850

mahindra

mahindra

2018-05-25 13:32

reporter   ~0059942

https://github.com/mantisbt/mantisbt/pull/1351#issuecomment-391495880 @atrol - great Job!

joseba.ortega

joseba.ortega

2019-04-01 02:19

reporter   ~0061801

Hi: Is there any patch for version 9.3.3 ? drop list of users for monitoring a issue.

Thanks in advance

mahindra

mahindra

2019-04-01 02:55

reporter   ~0061802

Update to latest version.
You will be able to write username or realname to ad them

joseba.ortega

joseba.ortega

2019-04-01 03:17

reporter   ~0061803

Hi again:
I'm sorry.
9.3.3 is the version of my Glpi :).
Our version of mantis is 2.9.0.
I understand that i can add a user for monitoring a issue using realname or username. That's great.
When you want to add a new user for monitoring, could you see the drop list of all users?

Thanks a lot

mahindra

mahindra

2019-04-01 03:28

reporter   ~0061804

It depends on your rights

You can send an reminder there is a drop down
If you are able to assign IDs - you can see the users there
Or make a New tap and use Reporter or assigned to fields to check it out

mahindra

mahindra

2019-04-01 03:29

reporter   ~0061805

Last edited: 2019-04-01 03:29

View 2 revisions

A Combo to select users will be nice as written above

a.zhivotovskiy

a.zhivotovskiy

2019-06-04 19:59

reporter   ~0062193

Last edited: 2019-06-04 20:00

View 3 revisions

Mantis 2.21.0
copy patch into Mantis root directory
execute: sudo patch --dry-run -p1 <0001-Fix-12557-for-mantis-1.2.5.patch

Error:
checking file bug_monitor_add.php
Hunk 0000001 FAILED at 34.
1 out of 1 hunk FAILED
checking file bug_monitor_list_view_inc.php
Hunk 0000001 FAILED at 51.
1 out of 1 hunk FAILED
checking file lang/strings_english.txt
Hunk 0000001 FAILED at 1248.
1 out of 1 hunk FAILED

Please, can you check?

dregad

dregad

2019-06-05 09:26

developer   ~0062205

I am not using this functionality anymore - with a large number of users it becomes counterproductive to have a selection list vs typing the users' names in the field.

Anyway, here's an updated version of the patch. Note that this is against current dev-master (commit afb40dca79e54ff9c453d8bbe1b747c972e38f6f). NOTE: I did not test with older versions, and in fact it may not apply cleanly on 2.21.0 and older, because of changes introduced in 0025815.



0001-fix-12557-for-mantis-2.22.0-dev.patch (6,301 bytes)
From 020d09ac3a93a75c698dee1e90cc4f9222e984b1 Mon Sep 17 00:00:00 2001
From: Damien Regad <dregad@mantisbt.org>
Date: Wed, 5 Jun 2019 15:09:30 +0200
Subject: [PATCH 1/2] Add monitors to a bug by selecting users from list

This is more user friendly than having to type the the username,
particularly when Mantis is configured to display Realnames

Fixes #12557
---
 bug_monitor_add.php           | 30 +++++-----------
 bug_monitor_list_view_inc.php | 66 ++++++++++++++++++++++++++++++-----
 lang/strings_english.txt      |  2 +-
 3 files changed, 67 insertions(+), 31 deletions(-)

diff --git a/bug_monitor_add.php b/bug_monitor_add.php
index b5c18ff5d..f6d252f27 100644
--- a/bug_monitor_add.php
+++ b/bug_monitor_add.php
@@ -15,7 +15,7 @@
 # along with MantisBT.  If not, see <http://www.gnu.org/licenses/>.
 
 /**
- * This file turns monitoring on or off for a bug for the current user
+ * This file adds the current or specified user(s) to a bug's monitoring list
  *
  * @package MantisBT
  * @copyright Copyright 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
@@ -23,44 +23,32 @@
  * @link http://www.mantisbt.org
  *
  * @uses core.php
- * @uses access_api.php
  * @uses form_api.php
  * @uses gpc_api.php
- * @uses helper_api.php
  * @uses print_api.php
- * @uses utility_api.php
  */
 
 require_once( 'core.php' );
-require_api( 'error_api.php' );
 require_api( 'form_api.php' );
 require_api( 'gpc_api.php' );
-require_api( 'helper_api.php' );
 require_api( 'print_api.php' );
-require_api( 'utility_api.php' );
 
 form_security_validate( 'bug_monitor_add' );
 
 $f_bug_id = gpc_get_int( 'bug_id' );
-$f_usernames = trim( gpc_get_string( 'username', '' ) );
-
-$t_payload = array();
-
-if( !is_blank( $f_usernames ) ) {
-	$t_usernames = preg_split( '/[,|]/', $f_usernames, -1, PREG_SPLIT_NO_EMPTY );
-	$t_users = array();
-	foreach( $t_usernames as $t_username ) {
-		$t_users[] = array( 'name_or_realname' => trim( $t_username ) );
-	}
-
-	$t_payload['users'] = $t_users;
-}
+$f_user_ids = gpc_get_int_array( 'user_id', array() );
 
 $t_data = array(
 	'query' => array( 'issue_id' => $f_bug_id ),
-	'payload' => $t_payload,
 );
 
+if( $f_user_ids ) {
+	foreach( $f_user_ids as $t_user_id ) {
+		$t_users[] = array( 'id' => $t_user_id );
+	}
+	$t_data['payload'] = array( 'users' => $t_users );
+}
+
 $t_command = new MonitorAddCommand( $t_data );
 $t_command->execute();
 
diff --git a/bug_monitor_list_view_inc.php b/bug_monitor_list_view_inc.php
index 6cafd9275..d8cc8e342 100644
--- a/bug_monitor_list_view_inc.php
+++ b/bug_monitor_list_view_inc.php
@@ -119,17 +119,65 @@ if( $t_can_see_monitors || $t_can_add_others ) {
 								</div>
 <?php
 	if( $t_can_add_others ) {
+		# 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 = mb_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( ' ', mb_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 = mb_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 );
+?>
+            <div class="space-10"></div>
+            <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[]" class="input-sm" multiple>
+                    <option value="0"><?php echo '[' . lang_get( 'myself' ) . ']'; ?></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>
 
-		<div class="space-10"></div>
-		<form method="get" action="bug_monitor_add.php" class="form-inline noprint">
-			<?php echo form_security_field( 'bug_monitor_add' ) ?>
-			<input type="hidden" name="bug_id" value="<?php echo (integer)$f_bug_id; ?>" />
-			<label for="bug_monitor_list_username"><?php echo lang_get( 'username' ) ?></label>
-			<input type="text" class="input-sm" id="bug_monitor_list_username" name="username" />
-			<input type="submit" class="btn btn-primary btn-sm btn-white btn-round" value="<?php echo lang_get( 'add_user_to_monitor' ) ?>" />
-		</form>
-<?php } ?>
+                <button class="btn btn-primary btn-sm btn-white btn-round">
+                    <?php echo lang_get( 'add_user_to_monitor' ) ?>
+                </button>
+            </form>
+<?php
+        }
+    }
+?>
 							</td>
 						</tr>
 					</table>
diff --git a/lang/strings_english.txt b/lang/strings_english.txt
index 87cfeca49..e98b320bc 100644
--- a/lang/strings_english.txt
+++ b/lang/strings_english.txt
@@ -1280,7 +1280,7 @@ $s_close_bug_button = 'Close';
 $s_move_bug_button = 'Move';
 $s_attached_files = 'Attached Files';
 $s_publish = 'Publish';
-$s_add_user_to_monitor = 'Add';
+$s_add_user_to_monitor = 'Start Monitoring';
 
 # view_bug_page.php
 $s_bug_view_title = 'View Issue Details';
-- 
2.17.0

a.zhivotovskiy

a.zhivotovskiy

2019-06-05 10:59

reporter   ~0062209

sudo patch --dry-run -p1 <0001-fix-12557-for-mantis-2.22.0-dev.patch
checking file bug_monitor_add.php
checking file bug_monitor_list_view_inc.php
Hunk 1 FAILED at 119.
1 out of 1 hunk FAILED
checking file lang/strings_english.txt

dregad

dregad

2019-06-05 11:32

developer   ~0062210

Yeah well as I said before

it may not apply cleanly on 2.21.0 and older

QED.

I'm not going to adapt the patch for compatibility with earlier versions. Feel free to do so yourself if you need it.

dduminy

dduminy

2019-06-20 06:03

reporter   ~0062277

Thanks so much for your patch. I think it should be integrated in the next version. The feature is really cool and expected.
I understand that it might be faster to type the login of the newly added user , but perhaps, you can consider to make it configurable

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.0-beta.1
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.0-beta.1 =>
2015-03-12 12:36 atrol Relationship added has duplicate 0019490
2015-08-27 17:57 Discotechnica Note Added: 0051320
2015-08-28 03:33 dregad Note Added: 0051321
2015-08-28 13:58 Discotechnica Note Added: 0051323
2015-08-29 04:21 dregad Note Added: 0051324
2015-08-31 14:41 Discotechnica Note Added: 0051336
2015-09-01 02:35 dregad Note Added: 0051338
2016-06-13 06:26 dregad Relationship added related to 0021099
2017-01-13 04:34 cid Note Added: 0055100
2017-01-16 00:33 libregeek Note Added: 0055142
2017-01-22 19:24 elftron Note Added: 0055257
2017-02-03 01:42 libregeek Note Added: 0055462
2017-02-05 16:56 elftron Note Added: 0055497
2017-05-03 02:22 JackBeauregard Note Added: 0056763
2018-04-05 06:40 sneuf Note Added: 0059441
2018-05-19 03:25 mahindra Note Added: 0059851
2018-05-25 13:32 mahindra Note Added: 0059942
2019-04-01 02:19 joseba.ortega Note Added: 0061801
2019-04-01 02:55 mahindra Note Added: 0061802
2019-04-01 03:17 joseba.ortega Note Added: 0061803
2019-04-01 03:28 mahindra Note Added: 0061804
2019-04-01 03:29 mahindra Note Added: 0061805
2019-04-01 03:29 mahindra Note Edited: 0061805 View Revisions
2019-06-04 13:02 atrol Relationship added has duplicate 0025837
2019-06-04 19:59 a.zhivotovskiy Note Added: 0062193
2019-06-04 19:59 a.zhivotovskiy Note Edited: 0062193 View Revisions
2019-06-04 20:00 a.zhivotovskiy Note Edited: 0062193 View Revisions
2019-06-05 09:26 dregad File Added: screenshot-12557-for-2.22.0.png
2019-06-05 09:26 dregad File Added: 0001-fix-12557-for-mantis-2.22.0-dev.patch
2019-06-05 09:26 dregad Note Added: 0062205
2019-06-05 09:27 dregad Relationship added related to 0025815
2019-06-05 10:59 a.zhivotovskiy Note Added: 0062209
2019-06-05 11:32 dregad Note Added: 0062210
2019-06-20 06:03 dduminy Note Added: 0062277