diff options
| author | Marc Alexander <admin@m-a-styles.de> | 2019-01-05 16:12:29 +0100 | 
|---|---|---|
| committer | Marc Alexander <admin@m-a-styles.de> | 2019-01-05 16:12:29 +0100 | 
| commit | 537ff0c567de293763226390ab9d968ab73d77d5 (patch) | |
| tree | 7480cd41593deff17963ed12ef1a21804f3d8422 /phpBB | |
| parent | 409bfafbf088b4ac194c4cc1b89c9c07e3f5ef99 (diff) | |
| parent | 08968bdb60c9ff286cb71901718500c7720f1da4 (diff) | |
| download | forums-537ff0c567de293763226390ab9d968ab73d77d5.tar forums-537ff0c567de293763226390ab9d968ab73d77d5.tar.gz forums-537ff0c567de293763226390ab9d968ab73d77d5.tar.bz2 forums-537ff0c567de293763226390ab9d968ab73d77d5.tar.xz forums-537ff0c567de293763226390ab9d968ab73d77d5.zip  | |
Merge pull request #5457 from battye/ticket/15883
[ticket/15883] New error message for when users try adding invalid usernames to a group
Diffstat (limited to 'phpBB')
| -rw-r--r-- | phpBB/includes/acp/acp_groups.php | 17 | ||||
| -rw-r--r-- | phpBB/includes/functions_user.php | 19 | ||||
| -rw-r--r-- | phpBB/includes/ucp/ucp_groups.php | 21 | ||||
| -rw-r--r-- | phpBB/language/en/acp/groups.php | 1 | 
4 files changed, 53 insertions, 5 deletions
diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 0e058213e0..7b1dc706db 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -29,6 +29,9 @@ class acp_groups  		global $phpbb_root_path, $phpbb_admin_path, $phpEx;  		global $request, $phpbb_container, $phpbb_dispatcher; +		/** @var \phpbb\language\language $language Language object */ +		$language = $phpbb_container->get('language'); +  		$user->add_lang('acp/groups');  		$this->tpl_name = 'acp_groups';  		$this->page_title = 'ACP_GROUPS_MANAGE'; @@ -293,7 +296,19 @@ class acp_groups  				// Add user/s to group  				if ($error = group_user_add($group_id, false, $name_ary, $group_name, $default, $leader, 0, $group_row))  				{ -					trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING); +					$display_message = $language->lang($error); + +					if ($error == 'GROUP_USERS_INVALID') +					{ +						// Find which users don't exist +						$actual_name_ary = $name_ary; +						$actual_user_id_ary = []; +						user_get_id_name($actual_user_id_ary, $actual_name_ary, false, true); + +						$display_message = $language->lang('GROUP_USERS_INVALID', implode($language->lang('COMMA_SEPARATOR'), array_udiff($name_ary, $actual_name_ary, 'strcasecmp'))); +					} + +					trigger_error($display_message . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING);  				}  				$message = ($leader) ? 'GROUP_MODS_ADDED' : 'GROUP_USERS_ADDED'; diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 26bb987561..5372a28d18 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -26,8 +26,10 @@ if (!defined('IN_PHPBB'))  * @param array &$user_id_ary The user ids to check or empty if usernames used  * @param array &$username_ary The usernames to check or empty if user ids used  * @param mixed $user_type Array of user types to check, false if not restricting by user type +* @param boolean $update_references If false, the supplied array is unset and appears unchanged from where it was called +* @return boolean|string Returns false on success, error string on failure  */ -function user_get_id_name(&$user_id_ary, &$username_ary, $user_type = false) +function user_get_id_name(&$user_id_ary, &$username_ary, $user_type = false, $update_references = false)  {  	global $db; @@ -50,7 +52,13 @@ function user_get_id_name(&$user_id_ary, &$username_ary, $user_type = false)  	}  	$sql_in = ($which_ary == 'user_id_ary') ? array_map('intval', ${$which_ary}) : array_map('utf8_clean_string', ${$which_ary}); -	unset(${$which_ary}); + +	// By unsetting the array here, the values passed in at the point user_get_id_name() was called will be retained. +	// Otherwise, if we don't unset (as the array was passed by reference) the original array will be updated below. +	if ($update_references === false) +	{ +		unset(${$which_ary}); +	}  	$user_id_ary = $username_ary = array(); @@ -2698,6 +2706,13 @@ function group_user_add($group_id, $user_id_ary = false, $username_ary = false,  		return 'NO_USER';  	} +	// Because the item that gets passed into the previous function is unset, the reference is lost and our original +	// array is retained - so we know there's a problem if there's a different number of ids to usernames now. +	if (count($user_id_ary) != count($username_ary)) +	{ +		return 'GROUP_USERS_INVALID'; +	} +  	// Remove users who are already members of this group  	$sql = 'SELECT user_id, group_leader  		FROM ' . USER_GROUP_TABLE . ' diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index 1fb026167a..4673912aed 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -32,6 +32,9 @@ class ucp_groups  		global $db, $user, $auth, $cache, $template;  		global $request, $phpbb_container, $phpbb_log; +		/** @var \phpbb\language\language $language Language object */ +		$language = $phpbb_container->get('language'); +  		$user->add_lang('groups');  		$return_page = '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $this->u_action . '">', '</a>'); @@ -1054,13 +1057,27 @@ class ucp_groups  						if (confirm_box(true))  						{ +							$return_manage_page = '<br /><br />' . $language->lang('RETURN_PAGE', '<a href="' . $this->u_action . '&action=list&g=' . $group_id . '">', '</a>'); +  							// Add user/s to group  							if ($error = group_user_add($group_id, false, $name_ary, $group_name, $default, 0, 0, $group_row))  							{ -								trigger_error($user->lang[$error] . $return_page); +								$display_message = $language->lang($error); + +								if ($error == 'GROUP_USERS_INVALID') +								{ +									// Find which users don't exist +									$actual_name_ary = $name_ary; +									$actual_user_id_ary = []; +									user_get_id_name($actual_user_id_ary, $actual_name_ary, false, true); + +									$display_message = $language->lang('GROUP_USERS_INVALID', implode($language->lang('COMMA_SEPARATOR'), array_udiff($name_ary, $actual_name_ary, 'strcasecmp'))); +								} + +								trigger_error($display_message . $return_manage_page);  							} -							trigger_error($user->lang['GROUP_USERS_ADDED'] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $this->u_action . '&action=list&g=' . $group_id . '">', '</a>')); +							trigger_error($language->lang('GROUP_USERS_ADDED') . $return_manage_page);  						}  						else  						{ diff --git a/phpBB/language/en/acp/groups.php b/phpBB/language/en/acp/groups.php index c3a5ae9e44..5d68132a34 100644 --- a/phpBB/language/en/acp/groups.php +++ b/phpBB/language/en/acp/groups.php @@ -111,6 +111,7 @@ $lang = array_merge($lang, array(  	'GROUP_USERS_ADDED'				=> 'New users added to group successfully.',  	'GROUP_USERS_EXIST'				=> 'The selected users are already members.',  	'GROUP_USERS_REMOVE'			=> 'Users removed from group and new defaults set successfully.', +	'GROUP_USERS_INVALID'			=> 'No users were added to the group as the following usernames do not exist: %s',  	'LEGEND_EXPLAIN'				=> 'These are the groups which are displayed in the group legend:',  	'LEGEND_SETTINGS'				=> 'Legend settings',  | 
