MDL-84464 report_loglive: Hide report for teacher without groups
This commit is contained in:
committed by
Huong Nguyen
parent
7a6315e676
commit
0a75e8e4cf
+11
-10
@@ -29,6 +29,7 @@ use core\report_helper;
|
||||
require('../../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once($CFG->dirroot.'/course/lib.php');
|
||||
global $SITE, $PAGE;
|
||||
|
||||
$id = optional_param('id', 0, PARAM_INT);
|
||||
$page = optional_param('page', 0, PARAM_INT);
|
||||
@@ -60,23 +61,23 @@ $url = new moodle_url("/report/loglive/index.php", $params);
|
||||
|
||||
$PAGE->set_url($url);
|
||||
$PAGE->set_pagelayout('report');
|
||||
$PAGE->set_context($context);
|
||||
$strlivelogs = get_string('livelogs', 'report_loglive');
|
||||
$PAGE->set_title("$coursename: $strlivelogs");
|
||||
$output = $PAGE->get_renderer('report_loglive');
|
||||
echo $output->header();
|
||||
if (!report_helper::has_valid_group($context)) {
|
||||
echo $output->notification(get_string('notingroup'));
|
||||
echo $output->footer();
|
||||
exit();
|
||||
}
|
||||
|
||||
$renderable = new report_loglive_renderable($logreader, $id, $url, 0, $page);
|
||||
$refresh = $renderable->get_refresh_rate();
|
||||
$logreader = $renderable->selectedlogreader;
|
||||
|
||||
$strlivelogs = get_string('livelogs', 'report_loglive');
|
||||
$strupdatesevery = get_string('updatesevery', 'moodle', $refresh);
|
||||
|
||||
|
||||
$PAGE->set_url($url);
|
||||
$PAGE->set_context($context);
|
||||
$PAGE->set_title("$coursename: $strlivelogs");
|
||||
$PAGE->set_heading($coursename);
|
||||
|
||||
$output = $PAGE->get_renderer('report_loglive');
|
||||
echo $output->header();
|
||||
|
||||
// Print selector dropdown.
|
||||
$pluginname = get_string('pluginname', 'report_loglive');
|
||||
report_helper::print_report_selector($pluginname);
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use core\report_helper;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
/**
|
||||
@@ -36,7 +38,10 @@ defined('MOODLE_INTERNAL') || die;
|
||||
* @param context $context The context of the course
|
||||
*/
|
||||
function report_loglive_extend_navigation_course($navigation, $course, $context) {
|
||||
if (has_capability('report/loglive:view', $context)) {
|
||||
if (
|
||||
has_capability('report/log:view', $context)
|
||||
&& report_helper::has_valid_group($context)
|
||||
) {
|
||||
$url = new moodle_url('/report/loglive/index.php', array('id' => $course->id));
|
||||
$navigation->add(get_string('pluginname', 'report_loglive'), $url, navigation_node::TYPE_SETTING, null, null,
|
||||
new pix_icon('i/report', ''));
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
<?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/>.
|
||||
|
||||
require_once(__DIR__ . '/../../../../lib/behat/behat_base.php');
|
||||
/**
|
||||
* Step definition for report_loglive behat tests.
|
||||
*
|
||||
* @package report_loglive
|
||||
* @category test
|
||||
* @copyright 2025 Laurent David <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class behat_report_loglive extends behat_base {
|
||||
/**
|
||||
* Convert page names to URLs for steps like 'When I am on the "[identifier]" "[page type]" page'.
|
||||
*
|
||||
* Recognised page names are:
|
||||
* | pagetype | name meaning | description |
|
||||
* | Logs | Course name | The course report loglive page |
|
||||
*
|
||||
* @param string $page identifies which type of page this is, e.g. 'Logs'.
|
||||
* @param string $identifier identifies the particular page, e.g. 'C1'.
|
||||
* @return moodle_url the corresponding URL.
|
||||
* @throws Exception with a meaningful error message if the specified page cannot be found.
|
||||
*/
|
||||
protected function resolve_page_instance_url(string $page, string $identifier): moodle_url {
|
||||
switch (strtolower($page)) {
|
||||
case 'logs':
|
||||
$courseid = $this->get_course_id($identifier);
|
||||
return new moodle_url('/report/loglive/index.php', [
|
||||
'id' => $courseid,
|
||||
]);
|
||||
default:
|
||||
throw new Exception("Unrecognised page type '{$page}'");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
@report @report_loglive
|
||||
Feature: In a course with group mode, I can view the group report loglive page or not
|
||||
depending on the group I am in.
|
||||
|
||||
Background:
|
||||
Given the following "courses" exist:
|
||||
| fullname | shortname | category | groupmode |
|
||||
| Course separate group | C1 | 0 | 1 |
|
||||
| Course visible group | C2 | 0 | 2 |
|
||||
| Course no group | C3 | 0 | 0 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| student1 | Student | 1 | student1@example.com |
|
||||
| student2 | Student | 2 | student2@example.com |
|
||||
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||
| teacher2 | Teacher | 2 | teacher2@example.com |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | teacher |
|
||||
| teacher2 | C1 | teacher |
|
||||
| student1 | C1 | student |
|
||||
| student2 | C1 | student |
|
||||
| teacher1 | C2 | teacher |
|
||||
| teacher2 | C2 | teacher |
|
||||
| student1 | C2 | student |
|
||||
| student2 | C2 | student |
|
||||
| teacher1 | C3 | teacher |
|
||||
| teacher2 | C3 | teacher |
|
||||
| student1 | C3 | student |
|
||||
| student2 | C3 | student |
|
||||
And the following "groups" exist:
|
||||
| course | name | idnumber |
|
||||
| C1 | Group C1.1 | group11 |
|
||||
| C2 | Group C2.1 | group21 |
|
||||
| C3 | Group C3.1 | group31 |
|
||||
And the following "group members" exist:
|
||||
| group | user |
|
||||
| group11 | student1 |
|
||||
| group11 | teacher1 |
|
||||
| group21 | student1 |
|
||||
| group21 | teacher1 |
|
||||
| group31 | student1 |
|
||||
| group31 | teacher1 |
|
||||
And the following "activities" exist:
|
||||
| activity | name | intro | course | idnumber |
|
||||
| page | Page11 | Page11 | C1 | page1 |
|
||||
| page | Page21 | Page21 | C2 | page1 |
|
||||
| page | Page31 | Page31 | C3 | page1 |
|
||||
# Generate logs for the pages.
|
||||
And I am on the "Page11" "page activity" page logged in as student1
|
||||
And I am on "Course separate group" course homepage
|
||||
And I log out
|
||||
And I am on the "Page11" "page activity" page logged in as student2
|
||||
And I am on "Course separate group" course homepage
|
||||
And I log out
|
||||
And I am on the "Page21" "page activity" page logged in as student1
|
||||
And I am on "Course visible group" course homepage
|
||||
And I log out
|
||||
And I am on the "Page21" "page activity" page logged in as student2
|
||||
And I am on "Course visible group" course homepage
|
||||
And I log out
|
||||
And I am on the "Page31" "page activity" page logged in as student1
|
||||
And I am on "Course no group" course homepage
|
||||
And I log out
|
||||
And I am on the "Page31" "page activity" page logged in as student2
|
||||
And I am on "Course no group" course homepage
|
||||
And I log out
|
||||
|
||||
Scenario Outline: As a user in a course, I can view a link to the report live logs if I am in the right group.
|
||||
Given I log in as "<user>"
|
||||
And I am on "<course>" course homepage
|
||||
When I navigate to "Reports" in current page administration
|
||||
And "Live logs" "link" <shouldexist>
|
||||
And I log out
|
||||
Examples:
|
||||
| course | user | shouldexist |
|
||||
| Course separate group | teacher1 | should exist |
|
||||
| Course separate group | teacher2 | should not exist |
|
||||
| Course visible group | teacher1 | should exist |
|
||||
| Course visible group | teacher2 | should exist |
|
||||
| Course no group | teacher1 | should exist |
|
||||
| Course no group | teacher2 | should exist |
|
||||
|
||||
Scenario Outline: As a non editing teacher not in a group, I can not view the live report logs.
|
||||
Given I log in as "<user>"
|
||||
When I am on the "<course>" "report_loglive > Logs" page
|
||||
Then I <shouldsee> "you need to be part of a group to see this page."
|
||||
Examples:
|
||||
| course | user | shouldsee |
|
||||
| Course separate group | teacher1 | should not see |
|
||||
| Course separate group | teacher2 | should see |
|
||||
| Course visible group | teacher1 | should not see |
|
||||
| Course visible group | teacher2 | should not see |
|
||||
| Course no group | teacher1 | should not see |
|
||||
| Course no group | teacher2 | should not see |
|
||||
Reference in New Issue
Block a user