1
0
mirror of https://github.com/moodle/moodle.git synced 2025-03-22 16:40:07 +01:00

MDL-48309 mod_forum: Handle discussion subscriptions correctly

This commit is contained in:
Andrew Nicols 2014-11-21 10:34:05 +08:00
parent 5eddcfee34
commit 6220813776
2 changed files with 78 additions and 8 deletions

@ -51,6 +51,10 @@ if ($user !== 0) {
if (!is_null($sesskey)) {
$url->param('sesskey', $sesskey);
}
if (!is_null($discussionid)) {
$url->param('d', $discussionid);
$discussion = $DB->get_record('forum_discussions', array('id' => $discussionid), '*', MUST_EXIST);
}
$PAGE->set_url($url);
$forum = $DB->get_record('forum', array('id' => $id), '*', MUST_EXIST);
@ -147,12 +151,23 @@ $info->name = fullname($user);
$info->forum = format_string($forum->name);
if ($issubscribed) {
if (is_null($sesskey)) { // we came here via link in email
if (is_null($sesskey)) {
// We came here via link in email.
$PAGE->set_title($course->shortname);
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
echo $OUTPUT->confirm(get_string('confirmunsubscribe', 'forum', format_string($forum->name)),
new moodle_url($PAGE->url, array('sesskey' => sesskey())), new moodle_url('/mod/forum/view.php', array('f' => $id)));
$viewurl = new moodle_url('/mod/forum/view.php', array('f' => $id));
if ($discussionid) {
$a = new stdClass();
$a->forum = format_string($forum->name);
$a->discussion = format_string($discussion->name);
echo $OUTPUT->confirm(get_string('confirmunsubscribediscussion', 'forum', $a),
$PAGE->url, $viewurl);
} else {
echo $OUTPUT->confirm(get_string('confirmunsubscribe', 'forum', format_string($forum->name)),
$PAGE->url, $viewurl);
}
echo $OUTPUT->footer();
exit;
}
@ -164,7 +179,6 @@ if ($issubscribed) {
print_error('cannotunsubscribe', 'forum', $_SERVER["HTTP_REFERER"]);
}
} else {
$discussion = $DB->get_record('forum_discussions', array('id' => $discussionid));
if (\mod_forum\subscriptions::unsubscribe_user_from_discussion($user->id, $discussion, $context)) {
$info->discussion = $discussion->name;
redirect($returnto, get_string("discussionnownotsubscribed", "forum", $info), 1);
@ -180,12 +194,23 @@ if ($issubscribed) {
if (!has_capability('mod/forum:viewdiscussion', $context)) {
print_error('noviewdiscussionspermission', 'forum', $_SERVER["HTTP_REFERER"]);
}
if (is_null($sesskey)) { // we came here via link in email
if (is_null($sesskey)) {
// We came here via link in email.
$PAGE->set_title($course->shortname);
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
echo $OUTPUT->confirm(get_string('confirmsubscribe', 'forum', format_string($forum->name)),
new moodle_url($PAGE->url, array('sesskey' => sesskey())), new moodle_url('/mod/forum/view.php', array('f' => $id)));
$viewurl = new moodle_url('/mod/forum/view.php', array('f' => $id));
if ($discussionid) {
$a = new stdClass();
$a->forum = format_string($forum->name);
$a->discussion = format_string($discussion->name);
echo $OUTPUT->confirm(get_string('confirmsubscribediscussion', 'forum', $a),
$PAGE->url, $viewurl);
} else {
echo $OUTPUT->confirm(get_string('confirmsubscribe', 'forum', format_string($forum->name)),
$PAGE->url, $viewurl);
}
echo $OUTPUT->footer();
exit;
}
@ -194,7 +219,6 @@ if ($issubscribed) {
\mod_forum\subscriptions::subscribe_user($user->id, $forum, $context, true);
redirect($returnto, get_string("nowsubscribed", "forum", $info), 1);
} else {
$discussion = $DB->get_record('forum_discussions', array('id' => $discussionid));
$info->discussion = $discussion->name;
\mod_forum\subscriptions::subscribe_user_to_discussion($user->id, $discussion, $context);
redirect($returnto, get_string("discussionnowsubscribed", "forum", $info), 1);

@ -304,3 +304,49 @@ Feature: A user can control their own subscription preferences for a discussion
And I follow "Test post subject one"
And "You are not subscribed to this discussion. Click to subscribe." "link" should not exist
And "You are subscribed to this discussion. Click to unsubscribe." "link" should not exist
Scenario: A user can toggle their subscription preferences when viewing a discussion
Given I add a "Forum" to section "1" and I fill the form with:
| Forum name | Test forum name |
| Forum type | Standard forum for general use |
| Description | Test forum description |
| Subscription mode | Optional subscription |
And I add a new discussion to "Test forum name" forum with:
| Subject | Test post subject one |
| Message | Test post message one |
And I log out
And I log in as "student1"
And I follow "Course 1"
And I follow "Test forum name"
When I follow "Test post subject one"
Then I should see "Subscribe to this forum"
And I should see "Subscribe to this discussion"
And I follow "Subscribe to this forum"
And I follow "Continue"
And I follow "Test post subject one"
And I should see "Unsubscribe from this forum"
And I should see "Unsubscribe from this discussion"
And I follow "Unsubscribe from this discussion"
And I follow "Continue"
And I follow "Test post subject one"
And I should see "Unsubscribe from this forum"
And I should see "Subscribe to this discussion"
And I follow "Unsubscribe from this forum"
And I follow "Continue"
And I follow "Test post subject one"
And I should see "Subscribe to this forum"
And I should see "Subscribe to this discussion"
And I follow "Subscribe to this discussion"
And I follow "Continue"
And I should see "Subscribe to this forum"
And I should see "Unsubscribe from this discussion"
And I follow "Subscribe to this forum"
And I follow "Continue"
And I follow "Test post subject one"
And I should see "Unsubscribe from this forum"
And I should see "Unsubscribe from this discussion"
And I follow "Unsubscribe from this forum"
And I follow "Continue"
And I follow "Test post subject one"
And I should see "Subscribe to this forum"
And I should see "Subscribe to this discussion"