MDL-68093 wiki: Restrict group options to participation groups

This commit is contained in:
Mark Johnson 2023-02-15 13:35:28 +00:00
parent 1a520430d4
commit 7095fe0caa
3 changed files with 200 additions and 2 deletions

View File

@ -65,13 +65,13 @@ if (groups_get_activity_groupmode($cm)) {
$modulecontext = context_module::instance($cm->id);
$canaccessgroups = has_capability('moodle/site:accessallgroups', $modulecontext);
if ($canaccessgroups) {
$groups->availablegroups = groups_get_all_groups($cm->course);
$groups->availablegroups = groups_get_all_groups($cm->course, 0, 0, 'g.*', false, true);
$allpart = new stdClass();
$allpart->id = '0';
$allpart->name = get_string('allparticipants');
array_unshift($groups->availablegroups, $allpart);
} else {
$groups->availablegroups = groups_get_all_groups($cm->course, $USER->id);
$groups->availablegroups = groups_get_all_groups($cm->course, $USER->id, 0, 'g.*', false, true);
}
if (!empty($group)) {
$groups->currentgroup = $group;

View File

@ -0,0 +1,86 @@
<?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/>.
/**
* Steps definitions related to mod_quiz.
*
* @package mod_wiki
* @category test
* @copyright 2023 Catalyst IT Europe Ltd.
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
use Behat\Gherkin\Node\TableNode as TableNode;
use Behat\Mink\Exception\ExpectationException as ExpectationException;
/**
* Steps definitions related to mod_wiki.
*
* @copyright 2023 Catalyst IT Europe Ltd.
* @author Mark Johnson <mark.johnson@catalyst-eu.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_mod_wiki extends behat_base {
/**
* Add the specified pages to the specified wiki
*
* The first row should be column names:
* | wiki | user | group | title | content |
*
*
* wiki idnumber of the wiki course module
* user username of the user who is creating the page
* group (optional) idnumber of the group the page belongs to
* title (optional) the title text of the page
* content (optional) the content of the page
*
* @param TableNode $data The pages to add
*
* @Given /^the following wiki pages exist:$/
*/
public function the_following_wiki_pages_exist(TableNode $data): void {
global $DB;
$generator = behat_util::get_data_generator()->get_plugin_generator('mod_wiki');
// Add the pages.
foreach ($data->getHash() as $pagedata) {
if (!array_key_exists('wiki', $pagedata)) {
throw new ExpectationException('When adding pages to a wiki, ' .
'the wiki column is required containing the wiki idnumber.', $this->getSession());
}
$wikicm = $this->get_course_module_for_identifier($pagedata['wiki']);
$wiki = $DB->get_record('wiki', ['id' => $wikicm->instance]);
$wiki->cmid = $wikicm->cmid;
$pagedata['wikiid'] = $wiki->id;
unset($pagedata['wiki']);
if (array_key_exists('group', $pagedata)) {
$pagedata['group'] = $DB->get_field('groups', 'id', ['idnumber' => $pagedata['group']], MUST_EXIST);
}
if (array_key_exists('user', $pagedata)) {
$pagedata['userid'] = $DB->get_field('user', 'id', ['username' => $pagedata['user']], MUST_EXIST);
unset($pagedata['user']);
}
$generator->create_page($wiki, $pagedata);
}
}
}

View File

@ -0,0 +1,112 @@
@mod @mod_wiki
Feature: Groups can have separate content on a wiki
In order to create a wiki with my group
As a user
I need to view and add wiki pages by group
Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
| student1 | Student | 1 | student1@example.com |
| student2 | Student | 2 | student2@example.com |
| student3 | Student | 3 | student1@example.com |
| student4 | Student | 4 | student2@example.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 |
| student1 | C1 | student |
| student2 | C1 | student |
| student3 | C1 | student |
| student4 | C1 | student |
Given the following "groups" exist:
| name | course | idnumber | participation |
| Group 1 | C1 | G1 | 1 |
| Group 2 | C1 | G2 | 1 |
| Group 3 | C1 | G3 | 0 |
And the following "group members" exist:
| user | group |
| student1 | G1 |
| student2 | G2 |
| student3 | G3 |
And the following "activities" exist:
| activity | course | name | idnumber | wikimode | firstpagetitle | groupmode |
| wiki | C1 | Separate wiki | wiki1 | collaborative | Separate page 1 | 1 |
| wiki | C1 | Visible wiki | wiki2 | collaborative | Visible page 1 | 2 |
And the following wiki pages exist:
| wiki | title | content | group |
| wiki1 | Separate page 1 | Group 1 page | G1 |
| wiki1 | Separate page 1 | Group 2 page | G2 |
| wiki2 | Visible page 1 | Group 1 page | G1 |
| wiki2 | Visible page 1 | Group 2 page | G2 |
And the following wiki pages exist:
| wiki | title | content |
| wiki1 | Separate page 1 | No group page |
| wiki2 | Visible page 1 | No group page |
Scenario Outline: Teacher can see all participation group wikis
Given I am on the "<wiki>" "wiki activity" page logged in as teacher1
And I should see "All participants" in the "<mode> groups" "select"
And I should see "Group 1" in the "<mode> groups" "select"
And I should see "Group 2" in the "<mode> groups" "select"
And I should not see "Group 3" in the "<mode> groups" "select"
And I should see "No group page"
And I should not see "Group 1 page"
And I should not see "Group 2 page"
When I select "Group 1" from the "<mode> groups" singleselect
Then I should not see "No group page"
And I should see "Group 1 page"
And I should not see "Group 2 page"
Examples:
| wiki | mode |
| wiki1 | Separate |
| wiki2 | Visible |
Scenario Outline: Teacher can add a page to any participation group's wiki
Given I am on the "<wiki>" "wiki activity" page logged in as teacher1
And I select "Edit" from the "jump" singleselect
And I set the field "HTML format" to "[[Internal link]]"
And I press "Save"
When I follow "Internal link"
And I should see "New page"
Then I should see "All participants" in the "Group" "select"
And I should see "Group 1" in the "Group" "select"
And I should see "Group 2" in the "Group" "select"
And I should not see "Group 3" in the "Group" "select"
Examples:
| wiki |
| wiki1 |
| wiki2 |
Scenario Outline: Students should only see their participation groups' own wiki in separate groups mode
Given I am on the "wiki1" "wiki activity" page logged in as <user>
Then I should see "Separate groups: <group>"
And "Separate groups" "select" should not exist
And I should see "<page>"
Examples:
| user | group | page |
| student1 | Group 1 | Group 1 page |
| student2 | Group 2 | Group 2 page |
# The view page throws an exception if the user is not in a group, so we cannot test
# student3 and student4.
Scenario Outline: Students can see all participation groups' own wikis in visible groups mode
Given I am on the "wiki2" "wiki activity" page logged in as <user>
And I should see "All participants" in the "Visible groups" "select"
And I should see "Group 1" in the "Visible groups" "select"
And I should see "Group 2" in the "Visible groups" "select"
And I should not see "Group 3" in the "Visible groups" "select"
And I should see "<page>"
Examples:
| user | page |
| student1 | Group 1 page |
| student2 | Group 2 page |
| student3 | Group 1 page |
| student4 | Group 1 page |