View Issue Details

IDProjectCategoryView StatusLast Update
0003975mantisbtemailpublic2018-01-30 05:57
Reportermasc Assigned Tothraxisp  
PrioritynormalSeveritytweakReproducibilityalways
Status closedResolutionfixed 
PlatformX86OSWindowsOS VersionWin2K
Summary0003975: Realname vs username in email history
Description

In the email history is reported the username while in the web history is reported the realname.
The function history_get_raw_events_array have to be updated changing the query.

TagsNo tags attached.
Attached Files
realname.diff (5,988 bytes)   
Index: account_update.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/account_update.php,v
retrieving revision 1.36
diff -r1.36 account_update.php
58c58,93
< 	if ( $f_realname != user_get_name( $t_user_id ) ) {
---
> 	if ( $f_realname != user_get_field( $t_user_id, 'realname' ) ) {
> 		# checks for problems with realnames
> 		$c_realname = db_prepare_string( $f_realname );
> 		$t_username = user_get_field( $t_user_id, 'username' );
> 
> 		# allow realname to match username
> 		if ( $f_realname <> $t_username ) {
> 			# check realname does not match an existing username
> 			$t_user_table = config_get( 'mantis_user_table' );
> 
> 			$query = "SELECT username
> 				FROM $t_user_table
> 				WHERE username='$c_realname'";
> 			$result = db_query( $query, 1 );
> 
> 			if ( db_num_rows( $result ) > 0 ) {
> 				trigger_error( ERROR_USER_REAL_MATCH_USER, ERROR );
> 			}
> 
> 			# check to see if the realname is unique
> 			$query = "SELECT id
> 				FROM $t_user_table
> 				WHERE realname='$c_realname'";
> 			$result = db_query( $query );
> 			$count = db_num_rows( $result );
> 			if ( $count > 0 ) {
> 				# set flags for non-unique realnames
> 				$t_count = db_num_rows( $result );
> 				echo lang_get( 'realname_duplicated' ) . '<br />';
> 				user_set_field( $t_user_id, 'duplicate_realname', 'Y' );
> 				for ( $i=0 ; $i < $count ; $i++ ) {
> 					$t_id = db_result( $result, $i );
> 					user_set_field( $t_id, 'duplicate_realname', 'Y' );
> 				}
> 			}
> 		}
Index: config_defaults_inc.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/config_defaults_inc.php,v
retrieving revision 1.183
diff -r1.183 config_defaults_inc.php
349a350,352
> 	# -- show users with their real name or not
> 	$g_show_realname = OFF;
> 
Index: admin/upgrades/0_18_inc.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/admin/upgrades/0_18_inc.php,v
retrieving revision 1.14
diff -r1.14 0_18_inc.php
264c264
< 	# Author: Marcello Scat� marcello@marcelloscata.com
---
> 	# Author: Marcello Scat‡ marcello@marcelloscata.com
441a442,475
> 		$upgrades[] = new SQLUpgrade( 
> 			'user-duplicate',
> 			'Add realname duplicate field to user table',
> 			"ALTER TABLE $t_user_table ADD duplicate_realname CHAR( 1 ) DEFAULT ''" );
> 
> 		$upgrades[] = new FunctionUpgrade(
> 		'user-duplicate-fix',
> 		'set values for duplicate_realname',
> 		'upgrade_0_18_user_duplicate' );
> 
> 	function upgrade_0_18_user_duplicate() {
> 		global $t_user_table;
> 
> 		$query = "SELECT realname FROM $t_user_table 
> 								WHERE realname != '' 
> 								GROUP BY realname 
> 								HAVING count(realname) > 1";
> 		$result = db_query( $query );
> 		$t_count = db_num_rows( $result );
> 		for ( $i = 0 ; $i < $t_count ; $i++ ) {
> 			$t_row = db_fetch_array( $result );
> 			$t_name = $t_row['realname'];
> 			$query = "UPDATE $t_user_table
> 				SET duplicate_realname = 'Y'
> 				WHERE realname='$t_name'";
> 			db_query( $query );
> 		}
> 
> 		return true;
> 	}
> 
> 
> 
> 
Index: core/constant_inc.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/core/constant_inc.php,v
retrieving revision 1.24
diff -r1.24 constant_inc.php
206a207
> 	define( 'ERROR_USER_REAL_MATCH_USER',		807 );
Index: core/history_api.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/core/history_api.php,v
retrieving revision 1.25
diff -r1.25 history_api.php
112,115c112,113
< 		$query = "SELECT b.*, u.username
< 				FROM $t_mantis_bug_history_table b
< 				LEFT JOIN $t_mantis_user_table u
< 				ON b.user_id=u.id
---
> 		$query = "SELECT *
> 				FROM $t_mantis_bug_history_table
129,134c127,128
< 			# $v_username will be empty, if user no longer exists.
< 			if ( is_blank( $v_username ) ) {
< 				$raw_history[$i]['username'] = user_get_name( $v_user_id );
< 			} else {
< 				$raw_history[$i]['username'] = $v_username;
< 			}
---
> 			# user_get_name handles deleted users, and username vs realname
> 			$raw_history[$i]['username'] = user_get_name( $v_user_id );
Index: core/user_api.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/core/user_api.php,v
retrieving revision 1.74
diff -r1.74 user_api.php
379,380c379
< 		user_clear_cache( $p_user_id );
< 
---
> 		#unset non-unique realname flags if necessary
382a382,398
> 		$c_realname = db_prepare_string( user_get_field( $p_user_id, 'realname' ) );
> 		$query = "SELECT id
> 				FROM $t_user_table
> 				WHERE realname='$c_realname'";
> 		$result = db_query( $query );
> 		$t_count = db_num_rows( $result );
> 
> 		if ( $t_count == 2 ) {
> 			# unset flags if there are now only 2 unique names
> 			for ( $i=0 ; $i < $t_count ; $i++ ) {
> 				$t_user_id = db_result( $result, $i );
> 				user_set_field( $t_user_id, 'duplicate_realname', '' );
> 			}
> 		}
> 
> 		user_clear_cache( $p_user_id );
> 
483c499,511
< 			return is_blank( $row['realname'] ) ? $row['username'] : $row['realname'];
---
> 			if ( ON == config_get( 'show_realname' ) ) {
> 				if ( is_blank( $row['realname'] ) ) {
> 					return '(' . $row['username'] . ')';
> 				}else{
> 					if ( is_blank( $row['duplicate_realname'] ) ) {
> 						return $row['realname'];
> 					}else{
> 						return $row['realname'] . ' (' . $row['username'] . ')';
> 					}
> 				}
> 			}else{
> 				return $row['username'];
> 			}
Index: lang/strings_english.txt
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/lang/strings_english.txt,v
retrieving revision 1.189
diff -r1.189 strings_english.txt
211a212
> $MANTIS_ERROR[ERROR_USER_REAL_MATCH_USER] = 'The "Real Name" chosen matches another user\'s login name. Please choose another.';
385a387
> $s_realname_duplicated = 'Real name is in use by another user';
realname.diff (5,988 bytes)   
realname.tar.gz (38,008 bytes)

Relationships

parent of 0004198 closedthraxisp Realname can duplicate a username 
child of 0003987 closedvboctor Mantis 0.19.0 Release 

Activities

thraxisp

thraxisp

2004-07-25 19:34

reporter   ~0006355

I have a partial fix for this. Do we want to see this as just "Real Name", or "Real Name (Userid)".

sgrund

sgrund

2004-07-26 01:01

reporter   ~0006357

IMHO only Real Name. We want to hide the username (or userid) in all 'public' areas.

thraxisp

thraxisp

2004-07-26 15:37

reporter   ~0006375

Last edited: 2018-01-30 03:34

Per a discussion with Paul this morning, there may be a problem with displaying only the realname. It is possible for a realname to duplicate someone elses username. I'll raise this as a separate issue.

Barring that, here is a short patch on CVS HEAD that I'll apply if there is agreement.

Index: core/history_api.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/core/history_api.php,v
retrieving revision 1.25
diff -r1.25 history_api.php
112,115c112,113
<               $query = "SELECT b.*, u.username
<                               FROM $t_mantis_bug_history_table b
<                               LEFT JOIN $t_mantis_user_table u
<                               ON b.user_id=u.id
---
>               $query = "SELECT *
>                               FROM $t_mantis_bug_history_table
129,134c127,128
<                       # $v_username will be empty, if user no longer exists.
<                       if ( is_blank( $v_username ) ) {
<                               $raw_history[$i]['username'] = user_get_name( $v_user_id );
<                       } else {
<                               $raw_history[$i]['username'] = $v_username;
<                       }
---
>                       # user_get_name handles deleted users, and username vs realname
>                       $raw_history[$i]['username'] = user_get_name( $v_user_id );
thraxisp

thraxisp

2004-07-28 12:14

reporter   ~0006419

The problem is really more complex that I thought. From developer discussions, here is my proposal:

1) due to site preferences, we need a config variable ($g_show_realname) with values of ON and OFF. This will allow a site admin to pick his/her poison.

2) If show_realname is ON, but the realname is not set, it will show as "(username)".

3) If show_realname is ON, and realname is not unique, it will show as "real name (username)". This will have to be pre-determined when the realname is set as not to do a bunch of long queries while generating lists. This will only work with names in the mantis database for now (i.e., will not work if names come from LDAP directories).

4) In dropdowns, the names will be sorted by the text of the field ignoring the brackets. That is, realnames and usernames will be interleaved in alphabetical order.

5) A check that realname does NOT match an existing username will be added to the account_page processing. Realname and username will be allowed to match for an individual.

6) A check that the realname is unique will be added to the account_page processing. Non-unique realnames will generate a warning, but be accepted. (A database flag for uniqueness will be set (see above) if the check fails. Code to clear the flag needs to be added when the realname changes or an account is deleted.

Note that realname is a maximum of 64 characters long and username is 32. This might make for some wide combo boxes in some cases.

thraxisp

thraxisp

2004-07-28 19:59

reporter   ~0006429

I've attached a patch that addresses all except point 4.

It includes changes to the upgrade scripts. I'd like some feedback.

thraxisp

thraxisp

2004-07-30 16:11

reporter   ~0006480

changes checked into CVS