MDL-36460 mod_forum: Restrict forum subsription list based on availability info

This commit is contained in:
Andrew Nicols 2014-06-27 13:38:37 +08:00
parent 6597413d41
commit c87b87e62f
5 changed files with 120 additions and 12 deletions

View File

@ -58,6 +58,11 @@ class mod_forum_existing_subscriber_selector extends mod_forum_subscriber_select
WHERE $wherecondition AND s.forum = :forumid
ORDER BY $sort", $params);
$cm = get_coursemodule_from_instance('forum', $this->forumid);
$modinfo = get_fast_modinfo($cm->course);
$info = new \core_availability\info_module($modinfo->get_cm($cm->id));
$subscribers = $info->filter_user_list($subscribers);
return array(get_string("existingsubscribers", 'forum') => $subscribers);
}

View File

@ -108,7 +108,6 @@ class mod_forum_potential_subscriber_selector extends mod_forum_subscriber_selec
$params = array_merge($params, $eparams);
$fields = 'SELECT ' . $this->required_fields_sql('u');
$countfields = 'SELECT COUNT(u.id)';
$sql = " FROM {user} u
JOIN ($esql) je ON je.id = u.id
@ -117,21 +116,25 @@ class mod_forum_potential_subscriber_selector extends mod_forum_subscriber_selec
list($sort, $sortparams) = users_order_by_sql('u', $search, $this->accesscontext);
$order = ' ORDER BY ' . $sort;
// Check to see if there are too many to show sensibly.
if (!$this->is_validating()) {
$potentialmemberscount = $DB->count_records_sql($countfields . $sql, $params);
if ($potentialmemberscount > $this->maxusersperpage) {
return $this->too_many_results($search, $potentialmemberscount);
}
}
// If not, show them.
$availableusers = $DB->get_records_sql($fields . $sql . $order, array_merge($params, $sortparams));
$cm = get_coursemodule_from_instance('forum', $this->forumid);
$modinfo = get_fast_modinfo($cm->course);
$info = new \core_availability\info_module($modinfo->get_cm($cm->id));
$availableusers = $info->filter_user_list($availableusers);
if (empty($availableusers)) {
return array();
}
// Check to see if there are too many to show sensibly.
if (!$this->is_validating()) {
$potentialmemberscount = count($availableusers);
if ($potentialmemberscount > $this->maxusersperpage) {
return $this->too_many_results($search, $potentialmemberscount);
}
}
if ($this->forcesubscribed) {
return array(get_string("existingsubscribers", 'forum') => $availableusers);
} else {

View File

@ -464,6 +464,12 @@ class subscriptions {
// Guest user should never be subscribed to a forum.
unset($results[$CFG->siteguest]);
// Apply the activity module availability resetrictions.
$cm = get_coursemodule_from_instance('forum', $forum->id, $forum->course);
$modinfo = get_fast_modinfo($forum->course);
$info = new \core_availability\info_module($modinfo->get_cm($cm->id));
$results = $info->filter_user_list($results);
return $results;
}

View File

@ -100,9 +100,10 @@
}
// For each subscribed user in this forum and discussion, copy over per-discussion subscriptions if required.
$discussiongroup = $discussion->groupid == -1 ? 0 : $discussion->groupid;
$potentialsubscribers = \mod_forum\subscriptions::get_potential_subscribers(
$modcontext,
$potentialsubscribers = \mod_forum\subscriptions::fetch_subscribed_users(
$forum,
$discussiongroup,
$modcontext,
'u.id'
);

View File

@ -0,0 +1,93 @@
@mod @mod_forum
Feature: As a teacher I need to see an accurate list of subscribed users
In order to see who is subscribed to a forum
As a teacher
I need to view the list of subscribed users
Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher | Teacher | Teacher | teacher@example.com |
| student1 | Student | 1 | student.1@example.com |
| student2 | Student | 2 | student.2@example.com |
| student3 | Student | 3 | student.3@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 |
| student3 | C1 | student |
And the following "groups" exist:
| name | course | idnumber |
| Group 1 | C1 | G1 |
| Group 2 | C1 | G2 |
And the following "group members" exist:
| user | group |
| student1 | G1 |
| student2 | G2 |
And the following "groupings" exist:
| name | course | idnumber |
| Grouping 1 | C1 | GG1 |
And the following "grouping groups" exist:
| grouping | group |
| GG1 | G1 |
And I log in as "admin"
And I set the following administration settings values:
| Enable conditional access | 1 |
And I log out
And I log in as "teacher"
And I follow "Course 1"
And I turn editing mode on
@javascript
Scenario: A forced forum lists all subscribers
When I add a "Forum" to section "1" and I fill the form with:
| Forum name | Forced Forum 1 |
| Forum type | Standard forum for general use |
| Description | Test forum description |
| Subscription mode | Forced subscription |
And I follow "Forced Forum 1"
And I follow "Show/edit current subscribers"
Then I should see "Student 1"
And I should see "Teacher Teacher"
And I should see "Student 2"
And I should see "Student 3"
And I click on "Edit settings" "link" in the "Administration" "block"
And I expand all fieldsets
And I click on "Add restriction..." "button"
And I click on "Grouping" "button" in the "Add restriction..." "dialogue"
And I set the field with xpath "//select[@name='id']" to "Grouping 1"
And I press "Save and display"
And I follow "Show/edit current subscribers"
And I should see "Student 1"
And I should see "Teacher Teacher"
And I should not see "Student 2"
And I should not see "Student 3"
@javascript
Scenario: An automatic forum lists all subscribers
When I add a "Forum" to section "1" and I fill the form with:
| Forum name | Forced Forum 1 |
| Forum type | Standard forum for general use |
| Description | Test forum description |
| Subscription mode | Auto subscription |
And I follow "Forced Forum 1"
And I follow "Show/edit current subscribers"
Then I should see "Student 1"
And I should see "Teacher Teacher"
And I should see "Student 2"
And I should see "Student 3"
And I click on "Edit settings" "link" in the "Administration" "block"
And I expand all fieldsets
And I click on "Add restriction..." "button"
And I click on "Grouping" "button" in the "Add restriction..." "dialogue"
And I set the field with xpath "//select[@name='id']" to "Grouping 1"
And I press "Save and display"
And I follow "Show/edit current subscribers"
And I should see "Student 1"
And I should see "Teacher Teacher"
And I should not see "Student 2"
And I should not see "Student 3"