From b7b5d7112f4a73a9824e2b38cdcef73aaa649f23 Mon Sep 17 00:00:00 2001 From: Juan Segarra Montesinos Date: Sat, 3 Jul 2021 09:49:36 +0200 Subject: [PATCH] MDL-70335 mod_forum: Subscribe users from Forced to Auto mode When a teacher changes the subscription mode from forced subscription to auto subscription using the "cog" icon in the forum page, users are not seen in the Show/edit current subscribers" page. This does not happens when done from the Edit settings page. --- mod/forum/subscribe.php | 4 +- ...forum_subscriptions_mode_behaviour.feature | 40 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 mod/forum/tests/behat/forum_subscriptions_mode_behaviour.feature diff --git a/mod/forum/subscribe.php b/mod/forum/subscribe.php index 8d8b8f9c49d..c8472a7173e 100644 --- a/mod/forum/subscribe.php +++ b/mod/forum/subscribe.php @@ -141,13 +141,15 @@ if (!is_null($mode) and has_capability('mod/forum:managesubscriptions', $context ); break; case FORUM_INITIALSUBSCRIBE : // 2 + \mod_forum\subscriptions::set_subscription_mode($forum->id, FORUM_INITIALSUBSCRIBE); if ($forum->forcesubscribe <> FORUM_INITIALSUBSCRIBE) { + // Reload the forum again to get the updated forcesubscribe field. + $forum = $DB->get_record('forum', array('id' => $id), '*', MUST_EXIST); $users = \mod_forum\subscriptions::get_potential_subscribers($context, 0, 'u.id, u.email', ''); foreach ($users as $user) { \mod_forum\subscriptions::subscribe_user($user->id, $forum, $context); } } - \mod_forum\subscriptions::set_subscription_mode($forum->id, FORUM_INITIALSUBSCRIBE); redirect( $returnto, get_string('everyoneisnowsubscribed', 'forum'), diff --git a/mod/forum/tests/behat/forum_subscriptions_mode_behaviour.feature b/mod/forum/tests/behat/forum_subscriptions_mode_behaviour.feature new file mode 100644 index 00000000000..84b1d297ae5 --- /dev/null +++ b/mod/forum/tests/behat/forum_subscriptions_mode_behaviour.feature @@ -0,0 +1,40 @@ +@mod @mod_forum +Feature: Changes to the subscription mode of a forum can change subcribers of a forum + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | teacher | Teacher | Tom | teacher@example.com | + | student1 | Student | 1 | student.1@example.com | + | student2 | Student | 2 | student.2@example.com | + And the following "courses" exist: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And the following "course enrolments" exist: + | user | course | role | + | teacher | C1 | editingteacher | + | student1 | C1 | student | + | student2 | C1 | student | + And the following "activity" exists: + | activity | forum | + | idnumber | f01 | + | course | C1 | + | intro | Test forum description | + | name | Test forum name | + | type | general | + | forcesubscribe | 1 | + And I log in as "teacher" + And I am on "Course 1" course homepage + + @javascript + Scenario: A change from Forced subscription to Auto subcription causes all participants to be subscribed + Given I follow "Test forum name" + And I navigate to "Auto subscription" in current page administration + When I navigate to "Show/edit current subscribers" in current page administration + Then I should not see "There are no subscribers yet for this forum" + And I should see "Student 1" + And I should see "student.1@example.com" + And I should see "Student 2" + And I should see "student.2@example.com" + And I should see "Teacher Tom" + And I should see "teacher@example.com"