MDL-38990 mod_forum: Restrict ability to post to all groups in a forum

In order to post to all groups in a forum, you must have the
moodle/site:accessallgroups capability.

Thanks to Jakob Ackermann <[email protected]> for part of the fix
on this one.
This commit is contained in:
Andrew Nicols
2014-07-10 11:52:57 +08:00
committed by Damyon Wiese
parent 1721c8eb85
commit 91c8d4da71
3 changed files with 179 additions and 3 deletions
+11 -3
View File
@@ -162,13 +162,21 @@ class mod_forum_post_form extends moodleform {
$mform->setConstants(array('timestart'=> 0, 'timeend'=>0));
}
if (groups_get_activity_groupmode($cm, $course)) { // hack alert
if ($groupmode = groups_get_activity_groupmode($cm, $course)) { // hack alert
$groupdata = groups_get_activity_allowed_groups($cm);
$groupcount = count($groupdata);
$groupinfo = array();
$modulecontext = context_module::instance($cm->id);
$contextcheck = has_capability('mod/forum:movediscussions', $modulecontext) && empty($post->parent) && $groupcount;
if ($contextcheck) {
// Check whether the user has access to all groups in this forum from the accessallgroups cap.
if ($groupmode == VISIBLEGROUPS || has_capability('moodle/site:accessallgroups', $modulecontext)) {
// Only allow posting to all groups if the user has access to all groups.
$groupinfo = array('0' => get_string('allparticipants'));
$groupcount++;
}
$contextcheck = has_capability('mod/forum:movediscussions', $modulecontext) && empty($post->parent) && $groupcount > 1;
if ($contextcheck) {
foreach ($groupdata as $grouptemp) {
$groupinfo[$grouptemp->id] = $grouptemp->name;
}
@@ -0,0 +1,84 @@
@mod @mod_forum
Feature: Posting to all groups in a separate group discussion is restricted to users with access to all groups
In order to post to all groups in a forum with separate groups
As a teacher
I need to have the accessallgroups capability or be a member of all of the groups
Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@asd.com |
| noneditor1 | Non-editing teacher | 1 | noneditor1@asd.com |
| noneditor2 | Non-editing teacher | 2 | noneditor2@asd.com |
| student1 | Student | 1 | student1@asd.com |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| noneditor1 | C1 | teacher |
| noneditor2 | C1 | teacher |
| student1 | C1 | student |
And the following "groups" exist:
| name | course | idnumber |
| Group A | C1 | G1 |
| Group B | C1 | G2 |
| Group C | C1 | G3 |
And the following "group members" exist:
| user | group |
| teacher1 | G1 |
| teacher1 | G2 |
| noneditor1 | G1 |
| noneditor1 | G2 |
| noneditor1 | G3 |
| noneditor2 | G1 |
| noneditor2 | G2 |
| student1 | G1 |
| student1 | G2 |
And I log in as "teacher1"
And I follow "Course 1"
And I turn editing mode on
And I add a "Forum" to section "1" and I fill the form with:
| Forum name | Standard forum name |
| Forum type | Standard forum for general use |
| Description | Standard forum description |
| Group mode | Separate groups |
And I log out
Scenario: Teacher with accessallgroups can post in all groups
Given I log in as "teacher1"
And I follow "Course 1"
And I follow "Standard forum name"
When I click on "Add a new discussion topic" "button"
Then the "Group" select box should contain "All participants"
And the "Group" select box should contain "Group A"
And the "Group" select box should contain "Group B"
@javascript
Scenario: Teacher in all groups but without accessallgroups can only post in their groups
And I log in as "admin"
And I set the following system permissions of "Non-editing teacher" role:
| moodle/site:accessallgroups | Prohibit |
And I log out
Given I log in as "noneditor1"
And I follow "Course 1"
And I follow "Standard forum name"
When I click on "Add a new discussion topic" "button"
Then the "Group" select box should not contain "All participants"
And the "Group" select box should contain "Group A"
And the "Group" select box should contain "Group B"
@javascript
Scenario: Teacher in some groups and without accessallgroups can only post in their groups
And I log in as "admin"
And I set the following system permissions of "Non-editing teacher" role:
| moodle/site:accessallgroups | Prohibit |
And I log out
Given I log in as "noneditor1"
And I follow "Course 1"
And I follow "Standard forum name"
When I click on "Add a new discussion topic" "button"
Then the "Group" select box should not contain "All participants"
And the "Group" select box should contain "Group A"
And the "Group" select box should contain "Group B"
@@ -0,0 +1,84 @@
@mod @mod_forum
Feature: Posting to groups in a separate group discussion when restricted to groupings
In order to post to groups in a forum with separate groups and groupings
As a teacher
I need to have groups configured to post to a group
Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | teacher1 | teacher1 | teacher1@asd.com |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | teacher |
And the following "groups" exist:
| name | course | idnumber |
| G1G1 | C1 | G1G1 |
| G1G2 | C1 | G1G2 |
| G2G1 | C1 | G2G1 |
And the following "groupings" exist:
| name | course | idnumber |
| G1 | C1 | G1 |
| G2 | C1 | G2 |
And the following "group members" exist:
| user | group |
| teacher1 | G1G1 |
| teacher1 | G1G2 |
| teacher1 | G2G1 |
And the following "grouping groups" exist:
| grouping | group |
| G1 | G1G1 |
| G1 | G1G2 |
| G2 | G2G1 |
And I log in as "admin"
And I follow "Course 1"
And I turn editing mode on
And I add a "Forum" to section "1" and I fill the form with:
| Forum name | Multiple groups forum |
| Forum type | Standard forum for general use |
| Description | Standard forum description |
| Group mode | Separate groups |
| Grouping | G1 |
And I add a "Forum" to section "1" and I fill the form with:
| Forum name | Single groups forum |
| Forum type | Standard forum for general use |
| Description | Standard forum description |
| Group mode | Separate groups |
| Grouping | G2 |
And I log out
Scenario: Teacher with accessallgroups can post in all groups
Given I log in as "teacher1"
And I follow "Course 1"
And I follow "Multiple groups forum"
When I click on "Add a new discussion topic" "button"
Then the "Group" select box should contain "All participants"
And the "Group" select box should contain "G1G1"
And the "Group" select box should contain "G1G2"
And I follow "Course 1"
And I follow "Single groups forum"
And I click on "Add a new discussion topic" "button"
And the "Group" select box should contain "All participants"
And the "Group" select box should contain "G2G1"
@javascript
Scenario: Teacher in all groups but without accessallgroups can post in either group but not to All Participants
And I log in as "admin"
And I set the following system permissions of "Non-editing teacher" role:
| moodle/site:accessallgroups | Prohibit |
And I log out
Given I log in as "teacher1"
And I follow "Course 1"
And I follow "Multiple groups forum"
When I click on "Add a new discussion topic" "button"
Then the "Group" select box should not contain "All participants"
And the "Group" select box should contain "G1G1"
And the "Group" select box should contain "G1G2"
And I follow "Course 1"
And I follow "Single groups forum"
And I click on "Add a new discussion topic" "button"
And I should see "G2G1"
And "Group" "select" should not exist