mirror of
https://github.com/moodle/moodle.git
synced 2025-03-20 07:30:01 +01:00
Merge branch 'MDL-80849-main' of https://github.com/davewoloszyn/moodle
This commit is contained in:
commit
f686d2a6c7
@ -24,6 +24,12 @@ namespace communication_matrix;
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class matrix_user_manager {
|
||||
|
||||
/**
|
||||
* Prefix for Matrix usernames when they are detected as numeric.
|
||||
*/
|
||||
const MATRIX_USER_PREFIX = 'user';
|
||||
|
||||
/**
|
||||
* Gets matrix user id from moodle.
|
||||
*
|
||||
@ -56,6 +62,11 @@ class matrix_user_manager {
|
||||
$username = preg_replace('/[@#$%^&*()+{}|<>?!,]/i', '.', $username);
|
||||
$username = ltrim(rtrim($username, '.'), '.');
|
||||
|
||||
// Matrix/Synapse servers will not allow numeric usernames.
|
||||
if (is_numeric($username)) {
|
||||
$username = self::MATRIX_USER_PREFIX . $username;
|
||||
}
|
||||
|
||||
$homeserver = self::get_formatted_matrix_home_server();
|
||||
|
||||
return "@{$username}:{$homeserver}";
|
||||
|
@ -126,6 +126,11 @@ class matrix_user_manager_test extends \advanced_testcase {
|
||||
'colin.creavey',
|
||||
'@colin.creavey:matrix.example.org',
|
||||
],
|
||||
'numeric username' => [
|
||||
'https://matrix.example.org',
|
||||
'123456',
|
||||
'@' . matrix_user_manager::MATRIX_USER_PREFIX . '123456:matrix.example.org',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user