31 Commits

Author SHA1 Message Date
Andrew Nicols
d38c3dfc8e
MDL-77917 communication_matrix: Topic must not be null
The Matrix space/room topic must always be a string. We should normalise
this on the way out of the API.
2023-08-24 23:19:38 +08:00
Andrew Nicols
6d1bd4787f
MDL-77917 communication_matrix: Use v1.7 upload content API
Version 1.7 of the Matrix API adds a new endpoint for uploading media.
`_matrix/media/v1/create` and adds a new path parameter to the existing
`_matrix/media/v3/upload` endpoint.
2023-08-24 11:59:30 +08:00
Andrew Nicols
914686bc5e
MDL-77917 communication_matrix: Support server API versions
This commit brings in support for multiple versions of the Matrix
specification.

A Matrix server is compromised of a number of individually versioned API
endpoints, for example:

    /_matrix/client/v3/createRoom
    /_matrix/client/v3/rooms/:roomid/joined_members
    /_matrix/media/v1/create

The combination of a large number of these individually versioned
endpoints forms a Matrix Specification version.

For example:

* the /_matrix/media/v1/create endpoint was created for version 1.7 of the
  specification, and does not exist in earlier versions.
* in the future a new behaviour or parameter may be created for the
  `createRoom` endpoint and a new endpoint created at:

    /_matrix/client/v4/createRoom

A single server can support multiple versions of the Matrix
specification. The server declares the versions of the specification
that it supports using a non-versioned endpoint at
`/_matrix/client/versions`.

As a Matrix client, Moodle should:
* query the server version endpoint
* determine the combination of mutually supported Matrix specification
  versions
* create a client instance of the highest-supported version of the
  specification.

For example, if Moodle (Matrix client) and a remote server have the
following support:

```
Moodle:      1.1  1.2  1.3  1.4  1.5  1.6  1.7
Server:  r0  1.1  1.2  1.3  1.4  1.5  1.6
```

The versions in common are 1.1 through 1.6, and version 1.6 would be
chosen.

To avoid duplication and allow for support of future features more
easily, the Moodle client is written as:
* a set of classes named `v1p1` through `v1p7` (currently) which extend
  the `matrix_client` abstract class; and
* a set if PHP traits which provide the implementation for individual
  versioned endpoints.

Each client version then imports any relevant traits which are present
in that version of the Matrix Specification. For example versions 1.1 to
1.6 do _not_ have the `/_matrix/media/v1/create` endpoint so they do not
import this trait. This trait was introduced in version 1.7, so the
trait is included from that version onwards.

In the future, if an endpoint is created which conflicts with an
existing endpoint, then it would be easy to create a new client version
which uses the existing common traits, and adds the new trait.

Each endpoint is written using a `command` class which extends the
Guzzle implementation of the PSR-7 Request interface. This command
class adds support for easy creation of:
* path parameters within the URI
* query parameters
* body parameters

This is done to avoid complex patterns of Request creation which are
repeated for every client endpoint.
2023-08-24 11:59:25 +08:00
Huong Nguyen
aeeb1653c0
Merge branch 'MDL-78553-master' of https://github.com/davewoloszyn/moodle 2023-08-03 09:44:24 +07:00
David Woloszyn
317251a978 MDL-78553 core_communication: Move settings to their own page 2023-08-03 12:36:04 +10:00
David Woloszyn
5aea409a87 MDL-78553 behat: Add disable communication helper trait 2023-08-03 10:20:23 +10:00
Sara Arjona
c1d805a676
Merge branch 'MDL-78738-master' of https://github.com/andrewnicols/moodle 2023-08-01 16:24:42 +02:00
Andrew Nicols
8b97071c94
MDL-78738 core_communication: Set avatar from a stored_file
We should always use a stored_file instance to set the avatar, and never
a data uri. Especially where the datauri is from Moodle itself.

This change requires a number of changes in associated locations.

I am not adding this change to any upgrade notes as this is a
master-only feature.

Note: I have removed some tests and will not consider fixing them
because I will be entirely removing that test file in a subsequent issue
(MDL-77917).
2023-08-01 19:50:14 +08:00
Andrew Nicols
f067d6004f
MDL-78723 communication_matrix: Address issues with user manager
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.
2023-07-24 10:35:52 +08:00
Andrew Nicols
6d8db08c35
Merge branch 'MDL-78567-master' of https://github.com/stevandoMoodle/moodle 2023-07-13 16:49:59 +02:00
Stevani Andolo
68e60b9bab MDL-78567 communication_matrix: Fixed plugin version for upgrade 2023-06-30 11:21:17 +08:00
David Woloszyn
616c6a0809 MDL-77356 communication_matrix: Update avatar if different 2023-06-30 10:38:40 +10:00
David Woloszyn
162c9fdd66 MDL-77356 communication: Update avatar filename and avatar synced 2023-06-30 10:38:40 +10:00
Andrew Nicols
54f2722a7b
Merge branch 'MDL-78523-master' of https://github.com/safatshahin/moodle 2023-06-24 23:39:37 +08:00
Safat
42f704ac11 MDL-78523 communication_matrix: Behat coverage for matrix safe disable 2023-06-22 12:19:44 +10:00
Safat
d785ff6f57 MDL-78523 core_communication: Safe disable of communication plugins 2023-06-22 12:19:44 +10:00
Safat
3f48306385 MDL-76704 core_communication: Default setting for communication provider 2023-06-21 14:46:32 +10:00
Safat
7e91f77541 MDL-77357 communication_matrix: Add plugin savepoint 2023-06-08 14:18:25 +10:00
Safat
17e4523382 MDL-77357 communication_matrix: Test fix for course banner notification 2023-06-06 17:08:51 +10:00
Safat
5fc1dedeae MDL-77357 communication_matrix: Implement dynamic form fields 2023-06-01 00:42:53 +10:00
Safat
04b7c496f0 MDL-77357 core_communication: Add api for provider form fields 2023-06-01 00:39:03 +10:00
David Woloszyn
81414b527a MDL-77252 course: Fixed failing communication room status test 2023-05-26 11:55:23 +10:00
Andrew Nicols
d895574c9a
Merge branch 'MDL-77252-master' of https://github.com/davewoloszyn/moodle 2023-05-25 10:49:30 +08:00
Eloy Lafuente (stronk7)
b171f57cd5
MDL-77576 matrix: Bump version to today
All master versions need to be > than the previous
release (4.2) versions. To avoid overlapping to happen.
2023-05-19 11:20:29 +02:00
David Woloszyn
5bad9bd064 MDL-77252 course: Show notification depending on room status 2023-05-17 10:22:24 +10:00
David Woloszyn
d38cc920c5 MDL-77252 core_communication: Get room status and notifications 2023-05-17 10:06:11 +10:00
Safat
019f74f8b6 MDL-77576 core_communication: Implement privacy api 2023-05-11 13:35:17 +10:00
Safat
9a060a6d8d MDL-77576 communication_matrix: Create Matrix plugin
This commit will implement a matrix communication plugin
to integrate matrix services with core communication.

Originally implemented as MDL-76701, MDL-76702, MDL-77357,
MDL-76705, MDL-77473 and  MDL-76708.

Co-Authored-By: Stevani Andolo <stevani.andolo@moodle.com>
Co-Authored-By: David Woloszyn <david.woloszyn@moodle.com>
Co-Authored-By: Safat Shahin <safat.shahin@moodle.com>
2023-05-11 13:35:16 +10:00
Safat
ca1e5d0beb MDL-77576 core_communication: Add core communication api
This commit will implement the base api for core
communication. This will include the room creation,
room membership, room access url and all associated
api and related interfaces.

Originally implemented as MDL-76702, MDL-76703 and MDL-76705.

Co-Authored-By: David Woloszyn <david.woloszyn@moodle.com>
Co-Authored-By: Safat Shahin <safat.shahin@moodle.com>
2023-05-11 13:35:16 +10:00
Huong Nguyen
ec5663f1a4 MDL-77576 core: Register a new communication plugin-type
A new communication plugin type added to core to implement
the communication provider features.

Original implemented as MDL-76699

Co-Authored-By: Huong Nguyen <huongnv13@gmail.com>
2023-05-05 14:41:30 +10:00
Huong Nguyen
163b4134df MDL-77576 core: Register new communication sub-system
Create a new subsystem for communication and create
associated experimental settings to safely use the
new subsystem.

Originally implemented as MDL-76699.

Co-Authored-By: Huong Nguyen <huongnv13@gmail.com>
2023-05-05 14:41:28 +10:00