Commit ebfb73db authored by Andrew Nicols's avatar Andrew Nicols
Browse files

MDL-1626 mod_forum: Update user interface to reflect per-discussion subscriptions

AMOS BEGIN
  MOV [forcessubscribe,mod_forum],[forcesubscribed,mod_forum]
AMOS END
parent a42d7818
......@@ -90,6 +90,7 @@ class mod_forum_post_form extends moodleform {
$modcontext = $this->_customdata['modcontext'];
$forum = $this->_customdata['forum'];
$post = $this->_customdata['post'];
$subscribe = $this->_customdata['subscribe'];
$edit = $this->_customdata['edit'];
$thresholdwarning = $this->_customdata['thresholdwarning'];
......@@ -113,26 +114,28 @@ class mod_forum_post_form extends moodleform {
$mform->setType('message', PARAM_RAW);
$mform->addRule('message', get_string('required'), 'required', null, 'client');
if (isset($forum->id) && \mod_forum\subscriptions::is_forcesubscribed($forum)) {
$manageactivities = has_capability('moodle/course:manageactivities', $coursecontext);
if (\mod_forum\subscriptions::is_forcesubscribed($forum)) {
$mform->addElement('static', 'subscribemessage', get_string('subscription', 'forum'), get_string('everyoneissubscribed', 'forum'));
$mform->addElement('hidden', 'subscribe');
$mform->setType('subscribe', PARAM_INT);
$mform->addHelpButton('subscribemessage', 'subscription', 'forum');
$mform->addHelpButton('subscribemessage', 'forcesubscribed', 'forum');
} else if (\mod_forum\subscriptions::subscription_disabled($forum) && !$manageactivities) {
$mform->addElement('static', 'subscribemessage', get_string('subscription', 'forum'), get_string('disallowsubscribe', 'forum'));
$mform->addElement('hidden', 'discussionsubscribe');
$mform->setType('discussionsubscribe', PARAM_INT);
$mform->addHelpButton('subscribemessage', 'disallowsubscription', 'forum');
} else if (\mod_forum\subscriptions::subscription_disabled($forum) ||
has_capability('moodle/course:manageactivities', $coursecontext)) {
} else {
$options = array();
$options[0] = get_string('subscribestop', 'forum');
$options[1] = get_string('subscribestart', 'forum');
$options[0] = get_string('discussionsubscribestop', 'forum');
$options[1] = get_string('discussionsubscribestart', 'forum');
$mform->addElement('select', 'subscribe', get_string('subscription', 'forum'), $options);
$mform->addHelpButton('subscribe', 'subscription', 'forum');
} else if (\mod_forum\subscriptions::is_forcesubscribed($forum)) {
$mform->addElement('static', 'subscribemessage', get_string('subscription', 'forum'), get_string('disallowsubscribe', 'forum'));
$mform->addElement('hidden', 'subscribe');
$mform->setType('subscribe', PARAM_INT);
$mform->addHelpButton('subscribemessage', 'subscription', 'forum');
$mform->addElement('select', 'discussionsubscribe', get_string('discussionsubscription', 'forum'), $options);
$mform->addHelpButton('discussionsubscribe', 'discussionsubscription', 'forum');
}
if (!empty($forum->maxattachments) && $forum->maxbytes != 1 && has_capability('mod/forum:createattachment', $modcontext)) { // 1 = No attachments at all
......@@ -140,7 +143,7 @@ class mod_forum_post_form extends moodleform {
$mform->addHelpButton('attachments', 'attachment', 'forum');
}
if (empty($post->id) && has_capability('moodle/course:manageactivities', $coursecontext)) { // hack alert
if (empty($post->id) && $manageactivities) {
$mform->addElement('checkbox', 'mailnow', get_string('mailnow', 'forum'));
}
......@@ -238,4 +241,3 @@ class mod_forum_post_form extends moodleform {
return $errors;
}
}
......@@ -182,7 +182,19 @@
$PAGE->set_heading($course->fullname);
$PAGE->set_button($searchform);
echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($forum->name), 2);
$headingvalue = format_string($forum->name);
if (has_capability('mod/forum:viewdiscussion', $modcontext)) {
// Discussion subscription.
if (\mod_forum\subscriptions::is_subscribable($forum)) {
$headingvalue .= ' ';
$headingvalue .= html_writer::tag('span', forum_get_discussion_subscription_icon($forum, $post->discussion), array(
'class' => 'discussionsubscription',
));
}
}
echo $OUTPUT->heading($headingvalue, 2);
/// Check to see if groups are being used in this forum
/// If so, make sure the current person is allowed to see this discussion
......@@ -285,7 +297,7 @@
$canrate = has_capability('mod/forum:rate', $modcontext);
forum_print_discussion($course, $cm, $forum, $discussion, $post, $displaymode, $canreply, $canrate);
echo $OUTPUT->footer();
// Add the subscription toggle JS.
$PAGE->requires->yui_module('moodle-mod_forum-subscriptiontoggle', 'Y.M.mod_forum.subscriptiontoggle.init');
echo $OUTPUT->footer();
......@@ -79,6 +79,8 @@ $string['cannotupdatepost'] = 'You can not update this post';
$string['cannotviewpostyet'] = 'You cannot read other students questions in this discussion yet because you haven\'t posted';
$string['cannotviewusersposts'] = 'There are no posts made by this user that you are able to view.';
$string['cleanreadtime'] = 'Mark old posts as read hour';
$string['clicktounsubscribe'] = 'You are subscribed to this discussion. Click to unsubscribe.';
$string['clicktosubscribe'] = 'Not subscribed. Click to subscribe.';
$string['completiondiscussions'] = 'Student must create discussions:';
$string['completiondiscussionsgroup'] = 'Require discussions';
$string['completiondiscussionshelp'] = 'requiring discussions to complete';
......@@ -121,11 +123,19 @@ $string['digestmailsubject'] = '{$a}: forum digest';
$string['digestmailtime'] = 'Hour to send digest emails';
$string['digestsentusers'] = 'Email digests successfully sent to {$a} users.';
$string['disallowsubscribe'] = 'Subscriptions not allowed';
$string['disallowsubscription'] = 'Subscription';
$string['disallowsubscription_help'] = 'This forum has been configured so that you cannot subscribe to discussions.';
$string['disallowsubscribeteacher'] = 'Subscriptions not allowed (except for teachers)';
$string['discussion'] = 'Discussion';
$string['discussionmoved'] = 'This discussion has been moved to \'{$a}\'.';
$string['discussionmovedpost'] = 'This discussion has been moved to <a href="{$a->discusshref}">here</a> in the forum <a href="{$a->forumhref}">{$a->forumname}</a>';
$string['discussionname'] = 'Discussion name';
$string['discussionnownotsubscribed'] = '{$a->name} will NOT be notified of new posts in \'{$a->name}\' of \'{$a->forum}\'';
$string['discussionnowsubscribed'] = '{$a->name} will be notified of new posts in \'{$a->name}\' of \'{$a->forum}\'';
$string['discussionsubscribestop'] = 'I don\'t want email copies of posts to this discussion';
$string['discussionsubscribestart'] = 'Send me email copies of posts to this discussion';
$string['discussionsubscription'] = 'Discussion subscription';
$string['discussionsubscription_help'] = 'Subscribing to a discussion means you will receive notifications of new posts to that discussion.';
$string['discussions'] = 'Discussions';
$string['discussionsstartedby'] = 'Discussions started by {$a}';
$string['discussionsstartedbyrecent'] = 'Discussions recently started by {$a}';
......@@ -192,7 +202,8 @@ $string['existingsubscribers'] = 'Existing subscribers';
$string['exportdiscussion'] = 'Export whole discussion';
$string['forcedreadtracking'] = 'Allow forced read tracking';
$string['forcedreadtracking_desc'] = 'Allows forums to be set to forced read tracking. Will result in decreased performance for some users, particularly on courses with many forums and posts. When off, any forums previously set to Forced are treated as optional.';
$string['forcessubscribe'] = 'This forum forces everyone to be subscribed';
$string['forcesubscribed_help'] = 'This forum has been configured so that you cannot unsubscribe from discussions.';
$string['forcesubscribed'] = 'This forum forces everyone to be subscribed';
$string['forum'] = 'Forum';
$string['forum:addinstance'] = 'Add a new forum';
$string['forum:addnews'] = 'Add news';
......
......@@ -3580,10 +3580,64 @@ function forum_print_discussion_header(&$post, $forum, $group=-1, $datestring=""
userdate($usedate, $datestring).'</a>';
echo "</td>\n";
if (has_capability('mod/forum:viewdiscussion', $modcontext)) {
// Discussion subscription.
if (\mod_forum\subscriptions::is_subscribable($forum)) {
echo '<td class="discussionsubscription">';
echo forum_get_discussion_subscription_icon($forum, $post->discussion);
echo '</td>';
}
}
echo "</tr>\n\n";
}
/**
* Return the markup for the discussion subscription toggling icon.
*
* @param stdClass $forum The forum object.
* @param int $discussionid The discussion to create an icon for.
* @return string The generated markup.
*/
function forum_get_discussion_subscription_icon($forum, $discussionid, $returnurl = null) {
global $USER, $OUTPUT, $PAGE;
if ($returnurl === null && $PAGE->url) {
$returnurl = $PAGE->url->out();
}
$o = '';
$subscriptionstatus = \mod_forum\subscriptions::is_subscribed($USER->id, $forum, $discussionid);
$subscriptionlink = new moodle_url('/mod/forum/subscribe.php', array(
'sesskey' => sesskey(),
'id' => $forum->id,
'd' => $discussionid,
'returnurl' => $returnurl,
));
if ($subscriptionstatus) {
$o .= html_writer::link($subscriptionlink,
$OUTPUT->pix_icon('t/subscribed', get_string('clicktounsubscribe', 'forum'), 'mod_forum'),
array(
'title' => get_string('clicktounsubscribe', 'forum'),
'class' => 'discussiontoggle iconsmall',
'data-forumid' => $forum->id,
'data-discussionid' => $discussionid,
));
} else {
$o .= html_writer::link($subscriptionlink,
$OUTPUT->pix_icon('t/unsubscribed', get_string('clicktosubscribe', 'forum'), 'mod_forum'),
array(
'title' => get_string('clicktosubscribe', 'forum'),
'class' => 'discussiontoggle iconsmall',
'data-forumid' => $forum->id,
'data-discussionid' => $discussionid,
));
}
return $o;
}
/**
* Print the drop down that allows the user to select how they want to have
* the discussion displayed.
......@@ -4405,11 +4459,12 @@ function forum_count_replies($post, $children=true) {
* Given a new post, subscribes or unsubscribes as appropriate.
* Returns some text which describes what happened.
*
* @global objec
* @param object $post
* @param object $forum
* @param object $fromform The submitted form
* @param stdClass $forum The forum record
* @param stdClass $discussion The forum discussion record
* @return string
*/
function forum_post_subscription($post, $forum) {
function forum_post_subscription($fromform, $forum, $discussion) {
global $USER;
if (\mod_forum\subscriptions::is_forcesubscribed($forum)) {
......@@ -4421,35 +4476,23 @@ function forum_post_subscription($post, $forum) {
\mod_forum\subscriptions::unsubscribe_user($USER->id, $forum);
}
return "";
} else { // go with the user's choice
if (isset($post->subscribe)) {
// no change
if ((!empty($post->subscribe) && $subscribed)
|| (empty($post->subscribe) && !$subscribed)) {
return "";
} elseif (!empty($post->subscribe) && !$subscribed) {
$action = 'subscribe';
} elseif (empty($post->subscribe) && $subscribed) {
$action = 'unsubscribe';
}
}
}
$info = new stdClass();
$info->name = fullname($USER);
$info->forum = format_string($forum->name);
switch ($action) {
case 'subscribe':
forum_subscribe($USER->id, $post->forum);
return "<p>".get_string("nowsubscribed", "forum", $info)."</p>";
case 'unsubscribe':
forum_unsubscribe($USER->id, $post->forum);
return "<p>".get_string("nownotsubscribed", "forum", $info)."</p>";
if ($fromform->discussionsubscribe) {
if ($result = \mod_forum\subscriptions::subscribe_user_to_discussion($USER->id, $discussion)) {
return html_writer::tag('p', get_string('nowsubscribed', 'forum', $info));
}
} else {
if ($result = \mod_forum\subscriptions::unsubscribe_user_from_discussion($USER->id, $discussion)) {
return html_writer::tag('p', get_string('nownotsubscribed', 'forum', $info));
}
}
return '';
}
/**
......@@ -4967,10 +5010,11 @@ function forum_user_can_see_post($forum, $discussion, $post, $user=NULL, $cm=NUL
* @param void $unused (originally current group)
* @param int $page Page mode, page to display (optional).
* @param int $perpage The maximum number of discussions per page(optional)
* @param boolean $subscriptionstatus Whether the user is currently subscribed to the discussion in some fashion.
*
*/
function forum_print_latest_discussions($course, $forum, $maxdiscussions=-1, $displayformat='plain', $sort='',
$currentgroup=-1, $groupmode=-1, $page=-1, $perpage=100, $cm=NULL) {
function forum_print_latest_discussions($course, $forum, $maxdiscussions = -1, $displayformat = 'plain', $sort = '',
$currentgroup = -1, $groupmode = -1, $page = -1, $perpage = 100, $cm = null) {
global $CFG, $USER, $OUTPUT;
if (!$cm) {
......@@ -5154,6 +5198,11 @@ function forum_print_latest_discussions($course, $forum, $maxdiscussions=-1, $di
}
}
echo '<th class="header lastpost" scope="col">'.get_string('lastpost', 'forum').'</th>';
if (has_capability('mod/forum:viewdiscussion', $context)) {
if (\mod_forum\subscriptions::is_subscribable($forum)) {
echo '<th class="header discussionsubscription" scope="col">&nbsp;</th>';
}
}
echo '</tr>';
echo '</thead>';
echo '<tbody>';
......
......@@ -573,6 +573,7 @@ $mform_post = new mod_forum_post_form('post.php', array('course' => $course,
'modcontext' => $modcontext,
'forum' => $forum,
'post' => $post,
'subscribe' => \mod_forum\subscriptions::is_subscribed($USER->id, $forum),
'thresholdwarning' => $thresholdwarning,
'edit' => $edit), 'post', '', array('id' => 'mformforum'));
......@@ -607,20 +608,16 @@ if (!empty($parent)) {
}
}
if (forum_is_subscribed($USER->id, $forum->id)) {
$subscribe = true;
} else if (forum_user_has_posted($forum->id, 0, $USER->id)) {
$subscribe = false;
} else {
// user not posted yet - use subscription default specified in profile
$subscribe = !empty($USER->autosubscribe);
}
$postid = empty($post->id) ? null : $post->id;
$draftid_editor = file_get_submitted_draft_itemid('message');
$currenttext = file_prepare_draft_area($draftid_editor, $modcontext->id, 'mod_forum', 'post', $postid, mod_forum_post_form::editor_options($modcontext, $postid), $post->message);
// Always suggest that the user be subscribed to a discussion that they're posting in unless they've already posted, in
// which case use their existing preference.
$discussionsubscribe = true;
if (isset($discussion) && forum_user_has_posted($forum->id, $discussion->id, $USER->id)) {
$discussionsubscribe = \mod_forum\subscriptions::is_subscribed($USER->id, $forum, $discussion->id);
}
$mform_post->set_data(array( 'attachments'=>$draftitemid,
'general'=>$heading,
'subject'=>$post->subject,
......@@ -629,7 +626,7 @@ $mform_post->set_data(array( 'attachments'=>$draftitemid,
'format'=>empty($post->messageformat) ? editors_get_preferred_format() : $post->messageformat,
'itemid'=>$draftid_editor
),
'subscribe'=>$subscribe?1:0,
'discussionsubscribe' => $discussionsubscribe,
'mailnow'=>!empty($post->mailnow),
'userid'=>$post->userid,
'parent'=>$post->parent,
......@@ -728,7 +725,7 @@ if ($fromform = $mform_post->get_data()) {
$message .= '<br />'.get_string("editedpostupdated", "forum", fullname($realuser));
}
if ($subscribemessage = forum_post_subscription($fromform, $forum)) {
if ($subscribemessage = forum_post_subscription($fromform, $forum, $discussion)) {
$timemessage = 4;
}
if ($forum->type == 'single') {
......@@ -778,7 +775,7 @@ if ($fromform = $mform_post->get_data()) {
$timemessage = 4;
}
if ($subscribemessage = forum_post_subscription($fromform, $forum)) {
if ($subscribemessage = forum_post_subscription($fromform, $forum, $discussion)) {
$timemessage = 4;
}
......@@ -881,7 +878,7 @@ if ($fromform = $mform_post->get_data()) {
$message .= '<p>'.get_string("postaddedtimeleft", "forum", format_time($CFG->maxeditingtime)) . '</p>';
}
if ($subscribemessage = forum_post_subscription($discussion, $forum)) {
if ($subscribemessage = forum_post_subscription($fromform, $forum, $discussion)) {
$timemessage = 6;
}
......
......@@ -118,7 +118,7 @@ class mod_forum_renderer extends plugin_renderer_base {
*/
public function subscribed_users(user_selector_base $existingusers) {
$output = $this->output->box_start('subscriberdiv boxaligncenter');
$output .= html_writer::tag('p', get_string('forcessubscribe', 'forum'));
$output .= html_writer::tag('p', get_string('forcesubscribed', 'forum'));
$output .= $existingusers->display(true);
$output .= $this->output->box_end();
return $output;
......
......@@ -61,6 +61,9 @@
.path-mod-forum .forumheaderlist .discussion .lastpost {white-space: nowrap;text-align: right;}
.path-mod-forum .forumheaderlist .replies,
.path-mod-forum .forumheaderlist .discussion .author {white-space: nowrap;}
.path-mod-forum .forumheaderlist thead .discussionsubscription {
text-align: center;
}
/** Styles for subscribers.php */
#page-mod-forum-subscribers .subscriberdiv,
......@@ -108,4 +111,4 @@ span.unread {
}
.forumpost.unread .row.header {
border-bottom: 1px solid #DDD;
}
\ No newline at end of file
}
......@@ -34,10 +34,12 @@
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once($CFG->dirroot.'/mod/forum/lib.php');
$id = required_param('id', PARAM_INT); // the forum to subscribe or unsubscribe to
$mode = optional_param('mode', null, PARAM_INT); // the forum's subscription mode
$user = optional_param('user', 0, PARAM_INT); // userid of the user to subscribe, defaults to $USER
$sesskey = optional_param('sesskey', null, PARAM_RAW); // sesskey
$id = required_param('id', PARAM_INT); // The forum to set subscription on.
$mode = optional_param('mode', null, PARAM_INT); // The forum's subscription mode.
$user = optional_param('user', 0, PARAM_INT); // The userid of the user to subscribe, defaults to $USER.
$discussionid = optional_param('d', null, PARAM_INT); // The discussionid to subscribe.
$sesskey = optional_param('sesskey', null, PARAM_RAW);
$returnurl = optional_param('returnurl', null, PARAM_RAW);
$url = new moodle_url('/mod/forum/subscribe.php', array('id'=>$id));
if (!is_null($mode)) {
......@@ -98,6 +100,10 @@ $returnto = optional_param('backtoindex',0,PARAM_INT)
? "index.php?id=".$course->id
: "view.php?f=$id";
if ($returnurl) {
$returnto = $returnurl;
}
if (!is_null($mode) and has_capability('mod/forum:managesubscriptions', $context)) {
require_sesskey();
switch ($mode) {
......@@ -136,7 +142,7 @@ $info = new stdClass();
$info->name = fullname($user);
$info->forum = format_string($forum->name);
if (\mod_forum\subscriptions::is_subscribed($user->id, $forum)) {
if (\mod_forum\subscriptions::is_subscribed($user->id, $forum, $discussionid)) {
if (is_null($sesskey)) { // we came here via link in email
$PAGE->set_title($course->shortname);
$PAGE->set_heading($course->fullname);
......@@ -147,10 +153,20 @@ if (\mod_forum\subscriptions::is_subscribed($user->id, $forum)) {
exit;
}
require_sesskey();
if (\mod_forum\subscriptions::unsubscribe_user($user->id, $forum, $context, true)) {
redirect($returnto, get_string("nownotsubscribed", "forum", $info), 1);
if ($discussionid === null) {
if (\mod_forum\subscriptions::unsubscribe_user($user->id, $forum, $context, true)) {
redirect($returnto, get_string("nownotsubscribed", "forum", $info), 1);
} else {
print_error('cannotunsubscribe', 'forum', $_SERVER["HTTP_REFERER"]);
}
} else {
print_error('cannotunsubscribe', 'forum', $_SERVER["HTTP_REFERER"]);
$discussion = $DB->get_record('forum_discussions', array('id' => $discussionid));
if (\mod_forum\subscriptions::unsubscribe_user_from_discussion($user->id, $discussion, $context)) {
$info->name = $discussion->name;
redirect($returnto, get_string("discussionnownotsubscribed", "forum", $info), 1);
} else {
print_error('cannotunsubscribe', 'forum', $_SERVER["HTTP_REFERER"]);
}
}
} else { // subscribe
......@@ -170,6 +186,13 @@ if (\mod_forum\subscriptions::is_subscribed($user->id, $forum)) {
exit;
}
require_sesskey();
\mod_forum\subscriptions::subscribe_user($user->id, $forum, $context, true);
redirect($returnto, get_string("nowsubscribed", "forum", $info), 1);
if ($discussionid == null) {
\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->name = $discussion->name;
\mod_forum\subscriptions::subscribe_user_to_discussion($user->id, $discussion, $context);
redirect($returnto, get_string("discussionnowsubscribed", "forum", $info), 1);
}
}
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Subscribe to or unsubscribe from a forum discussion.
*
* @package mod_forum
* @copyright 2014 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define('AJAX_SCRIPT', true);
require_once(dirname(dirname(__DIR__)) . '/config.php');
require_once($CFG->dirroot . '/mod/forum/lib.php');
$forumid = required_param('forumid', PARAM_INT); // The forum to subscribe or unsubscribe.
$discussionid = optional_param('discussionid', null, PARAM_INT); // The discussionid to subscribe.
$sesskey = optional_param('sesskey', null, PARAM_RAW);
$forum = $DB->get_record('forum', array('id' => $forumid), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $forum->course), '*', MUST_EXIST);
$discussion = $DB->get_record('forum_discussions', array('id' => $discussionid), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('forum', $forum->id, $course->id, false, MUST_EXIST);
$context = context_module::instance($cm->id);
require_login($course, false, $cm);
$return = new stdClass();
if (!\mod_forum\subscriptions::is_subscribable($forum)) {
// Nothing to do. We won't actually output any content here though.
echo json_encode($return);
die;
}
if (\mod_forum\subscriptions::is_subscribed($USER->id, $forum, $discussion->id)) {
// The user is subscribed, unsubscribe them.
\mod_forum\subscriptions::unsubscribe_user_from_discussion($USER->id, $discussion, $context);
} else {
// The user is unsubscribed, subscribe them.
\mod_forum\subscriptions::subscribe_user_to_discussion($USER->id, $discussion, $context);
}
// Now return the updated subscription icon.
$return->icon = forum_get_discussion_subscription_icon($forum, $discussion->id);
echo json_encode($return);
die;
@mod @mod_forum
Feature: A user can control their own subscription preferences for a discussion
In order to receive notifications for things I am interested in
As a user
I need to choose my discussion subscriptions
Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | One | student.one@example.com |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "course enrolments" exist:
| user | course | role |
| student1 | C1 | student |
And I log in as "admin"
And I follow "Course 1"
And I turn editing mode on
Scenario: An optional forum can have discussions subscribed to
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 add a new discussion to "Test forum name" forum with:
| Subject | Test post subject two |
| Message | Test post message two |
And I log out
When I log in as "student1"
And I follow "Course 1"
And I follow "Test forum name"
Then I should see "Subscribe to this forum"
And "Not subscribed. Click to subscribe." "link" should exist in the "Test post subject one" "table_row"
And "Not subscribed. Click to subscribe." "link" should exist in the "Test post subject two" "table_row"
And I click on "Not subscribed. Click to subscribe." "link" in the "Test post subject one" "table_row"
And I follow "Continue"
And I should see "Subscribe to this forum"
And "You are subscribed to this discussion. Click to unsubscribe." "link" should exist in the "Test post subject one" "table_row"
And "Not subscribed. Click to subscribe." "link" should exist in the "Test post subject two" "table_row"
And I click on "You are subscribed to this discussion. Click to unsubscribe." "link" in the "Test post subject one" "table_row"
And I follow "Continue"
And I should see "Subscribe to this forum"
And "Not subscribed. Click to subscribe." "link" should exist in the "Test post subject one" "table_row"
And "Not subscribed. Click to subscribe." "link" should exist in the "Test post subject two" "table_row"
And I click on "Not subscribed. Click to subscribe." "link" in the "Test post subject one" "table_row"
And I follow "Continue"
And I should see "Subscribe to this forum"
And "You are subscribed to this discussion. Click to unsubscribe." "link" should exist in the "Test post subject one" "table_row"
And "Not subscribed. Click to subscribe." "link" should exist in the "Test post subject two" "table_row"
And I follow "Subscribe to this forum"
And I follow "Continue"
And I should see "Unsubscribe from this forum"
And "You are subscribed to this discussion. Click to unsubscribe." "link" should exist in the "Test post subject one" "table_row"
And "You are subscribed to this discussion. Click to unsubscribe." "link" should exist in the "Test post subject two" "table_row"
And I follow "Unsubscribe from this forum"
And I follow "Continue"
And I should see "Subscribe to this forum"
And "Not subscribed. Click to subscribe." "link" should exist in the "Test post subject one" "table_row"
And "Not subscribed. Click to subscribe." "link" should exist in the "Test post subject two" "table_row"
Scenario: An automatic subscription forum can have discussions unsubscribed from
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 | Auto 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 add a new discussion to "Test forum name" forum with:
| Subject | Test post subject two |
| Message | Test post message two |