MDL-47252 mod_forum: Ensure guest users can't subscribe to discussions

This commit is contained in:
Dave Cooper 2014-09-16 17:19:54 +08:00
parent 272fec367f
commit 12cf8140a2
3 changed files with 37 additions and 2 deletions

View File

@ -230,7 +230,7 @@
echo $OUTPUT->header();
$headingvalue = format_string($forum->name);
if (has_capability('mod/forum:viewdiscussion', $modcontext)) {
if ((!isguestuser() && isloggedin()) && has_capability('mod/forum:viewdiscussion', $modcontext)) {
// Discussion subscription.
if (\mod_forum\subscriptions::is_subscribable($forum)) {
$headingvalue .= ' ';

View File

@ -3717,7 +3717,7 @@ function forum_print_discussion_header(&$post, $forum, $group=-1, $datestring=""
userdate($usedate, $datestring).'</a>';
echo "</td>\n";
if (has_capability('mod/forum:viewdiscussion', $modcontext)) {
if ((!isguestuser() && isloggedin()) && has_capability('mod/forum:viewdiscussion', $modcontext)) {
// Discussion subscription.
if (\mod_forum\subscriptions::is_subscribable($forum)) {
echo '<td class="discussionsubscription">';

View File

@ -269,3 +269,38 @@ Feature: A user can control their own subscription preferences for a discussion
And I follow "Test post subject two"
And I follow "Reply"
And the field "Discussion subscription" matches value "I don't want email copies of posts to this discussion"
Scenario: A guest should not be able to subscribe to a discussion
Given I click on "Home" "link" in the "Navigation" "block"
And 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 |
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
When I log in as "guest"
And I follow "Test forum name"
Then "Not subscribed. Click to subscribe." "link" should not exist in the "Test post subject one" "table_row"
And "You are subscribed to this discussion. Click to unsubscribe." "link" should not exist in the "Test post subject one" "table_row"
And I follow "Test post subject one"
And "Not subscribed. Click to subscribe." "link" should not exist
And "You are subscribed to this discussion. Click to unsubscribe." "link" should not exist
Scenario: A user who is not logged in should not be able to subscribe to a discussion
Given I click on "Home" "link" in the "Navigation" "block"
And 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 |
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
When I follow "Test forum name"
Then "Not subscribed. Click to subscribe." "link" should not exist in the "Test post subject one" "table_row"
And "You are subscribed to this discussion. Click to unsubscribe." "link" should not exist in the "Test post subject one" "table_row"
And I follow "Test post subject one"
And "Not subscribed. Click to subscribe." "link" should not exist
And "You are subscribed to this discussion. Click to unsubscribe." "link" should not exist