mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
f067d6004f
This commit addresses a number of issues with the Matrix user manager. These are, unfortunately, tough to break out into smaller commits. The following issues are addressed: Matrix usernames should be kept intact in the profile field. Prior to this change, usernames were mangled and the hostname removed entirely. Instead the hostname was added back when it is used. This approach is not suited to a case where a user inserts their own matrix username on a federated server. Unit tests should have the minimum of requirements and dependencies. Prior to this change, unit tests were setting up an entire mock system which was completely unnecessary. These unit tests should only test the static methods that they claim to test, not the entire communication subsystem, matrix API, matrix client, processors, and providers. Matrix host names should not be curtailed. Prior to this change the hostname of the matrix server was modified if it contained any . characters. For example, the following changes were previously made: | hostname | before | after | | ------------------ | ------- | ------------------ | | matrix.example.com | matrix | matrix.example.com | | www.example.com | example | example.com | I believe that the original intent was to strip the www from the front, but this is not documented anywhere that I have found. In any case, the username should be the completed and fully-qualified username. Many of the methods were poorly named: - `set_qualified_matrix_user_id` is actually a userid formatter. This has been replaced with `get_formatted_matrix_userid`. - `set_matrix_home_server` is actually a hostname formatter. This has been replaced with `get_formatted_matrix_home_server`. - `add_user_matrix_id_to_moodle` sets the matrix userid for a moodle user, it does not add more than one. This has been replaced with `set_matrix_userid_in_moodle`. The `set_qualified_matrix_user_id` method was silently returning with a false value if the profile custom field did not exist, but the `get_matrixid_from_moodle` method was creating the profile custom field in the same situation. These have been swapped so a set operation will create the field if it does not exist, but a get operation will not.