mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
Merge branch 'MDL-19667-master-viewuserreport' of https://github.com/dmitriim/moodle
This commit is contained in:
commit
b09b1a0a0b
5 changed files with 47 additions and 2 deletions
|
@ -37,6 +37,17 @@ $capabilities = array(
|
|||
),
|
||||
|
||||
'clonepermissionsfrom' => 'coursereport/outline:view',
|
||||
),
|
||||
|
||||
'report/outline:viewuserreport' => array(
|
||||
'riskbitmask' => RISK_PERSONAL,
|
||||
'captype' => 'read',
|
||||
'contextlevel' => CONTEXT_COURSE,
|
||||
'archetypes' => array(
|
||||
'teacher' => CAP_ALLOW,
|
||||
'editingteacher' => CAP_ALLOW,
|
||||
'manager' => CAP_ALLOW
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ $string['nocapability'] = 'Can not access user outline report';
|
|||
$string['nologreaderenabled'] = 'No log reader enabled';
|
||||
$string['numviews'] = '{$a->numviews} views by {$a->distinctusers} users';
|
||||
$string['outline:view'] = 'View activity report';
|
||||
$string['outline:viewuserreport'] = 'View user activity report';
|
||||
$string['page-report-outline-x'] = 'Any outline report';
|
||||
$string['page-report-outline-index'] = 'Course outline report';
|
||||
$string['page-report-outline-user'] = 'User course outline report';
|
||||
|
|
|
@ -86,7 +86,7 @@ function report_outline_can_access_user_report($user, $course) {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (has_capability('report/outline:view', $coursecontext)) {
|
||||
if (has_capability('report/outline:viewuserreport', $coursecontext)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,16 +45,28 @@ class report_outline_lib_testcase extends advanced_testcase {
|
|||
*/
|
||||
private $course;
|
||||
|
||||
/**
|
||||
* @var context_course Course context.
|
||||
*/
|
||||
private $coursecontext;
|
||||
|
||||
/**
|
||||
* @var \core_user\output\myprofile\tree The navigation tree.
|
||||
*/
|
||||
private $tree;
|
||||
|
||||
/**
|
||||
* @var int Dummy role for testing.
|
||||
*/
|
||||
private $roleid;
|
||||
|
||||
public function setUp() {
|
||||
$this->user = $this->getDataGenerator()->create_user();
|
||||
$this->user2 = $this->getDataGenerator()->create_user();
|
||||
$this->course = $this->getDataGenerator()->create_course();
|
||||
$this->tree = new \core_user\output\myprofile\tree();
|
||||
$this->coursecontext = context_course::instance($this->course->id);
|
||||
$this->roleid = create_role('Dummy role', 'dummyrole', 'dummy role description');
|
||||
$this->resetAfterTest();
|
||||
}
|
||||
|
||||
|
@ -108,4 +120,25 @@ class report_outline_lib_testcase extends advanced_testcase {
|
|||
$this->assertArrayNotHasKey('outline', $nodes->getValue($this->tree));
|
||||
$this->assertArrayNotHasKey('complete', $nodes->getValue($this->tree));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the current user can not access user report without report/outline:viewuserreport permission.
|
||||
*/
|
||||
public function test_report_outline_can_not_access_user_report_without_viewuserreport_permission() {
|
||||
$this->getDataGenerator()->role_assign($this->roleid, $this->user->id, $this->coursecontext->id);
|
||||
$this->setUser($this->user);
|
||||
|
||||
$this->assertFalse(report_outline_can_access_user_report($this->user, $this->course));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the current user can access user report with report/outline:viewuserreport permission.
|
||||
*/
|
||||
public function test_report_outline_can_access_user_report_with_viewuserreport_permission() {
|
||||
assign_capability('report/outline:viewuserreport', CAP_ALLOW, $this->roleid, $this->coursecontext->id, true);
|
||||
$this->getDataGenerator()->role_assign($this->roleid, $this->user->id, $this->coursecontext->id);
|
||||
$this->setUser($this->user);
|
||||
|
||||
$this->assertTrue(report_outline_can_access_user_report($this->user, $this->course));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,6 @@
|
|||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
$plugin->version = 2017111300; // The current plugin version (Date: YYYYMMDDXX)
|
||||
$plugin->version = 2017111301; // The current plugin version (Date: YYYYMMDDXX)
|
||||
$plugin->requires = 2017110800; // Requires this Moodle version
|
||||
$plugin->component = 'report_outline'; // Full name of the plugin (used for diagnostics)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue