MDL-78619 communication: De-couple room & user management and API fix

Management fix: Although rooms and room users are implemented as
separate provider interfaces, there were still assumptions that
adding/removing rooms would require user handling. Where room_provider
was implemented but room_user_provider was not, that would then result
in either unnecessary ad-hoc tasks, or tasks failing with errors. Now,
checks are in place to avoid these scenarios.

API fix: Previously save_form_data() was being called on the old
provider instead of the newly enabled one, so when switching between
providers the settings would not be correctly applied and the provider
may not function. Now, the object is reloaded and the data is saved correctly.
This commit is contained in:
Michael Hawkins
2023-08-27 23:06:22 +08:00
parent cdf17eb7d5
commit bfbb314e2f
2 changed files with 12 additions and 8 deletions
+10 -5
View File
@@ -451,6 +451,9 @@ class api {
);
}
// Reload so the currently selected provider is used.
$this->reload();
// Update provider record from form data.
if ($instance !== null) {
$this->communication->get_form_provider()->save_form_data($instance);
@@ -514,8 +517,8 @@ class api {
return;
}
// No userids? don't bother doing anything.
if (empty($userids)) {
// No user IDs or this provider does not manage users? No action required.
if (empty($userids) || !$this->communication->supports_user_features()) {
return;
}
@@ -542,12 +545,14 @@ class api {
return;
}
if ($this->communication->get_provider() === processor::PROVIDER_NONE) {
$provider = $this->communication->get_provider();
if ($provider === processor::PROVIDER_NONE) {
return;
}
// No user ids? don't bother doing anything.
if (empty($userids)) {
// No user IDs or this provider does not manage users? No action required.
if (empty($userids) || !$this->communication->supports_user_features()) {
return;
}
@@ -46,13 +46,12 @@ class create_and_configure_room_task extends adhoc_task {
return;
}
// If the room is created successfully, add members to the room.
if ($communication->get_room_provider()->create_chat_room()) {
// If the room is created successfully, add members to the room if supported by the provider.
if ($communication->get_room_provider()->create_chat_room() && $communication->supports_user_features()) {
add_members_to_room_task::queue(
$communication
);
}
}
/**