Skip to content

Commit

Permalink
MDL-19667 report: Add a new capability to view user outline report
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitriim committed Dec 14, 2017
1 parent 109aa07 commit 124f314
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
11 changes: 11 additions & 0 deletions report/outline/db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@
),

'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
),
)
);

Expand Down
1 change: 1 addition & 0 deletions report/outline/lang/en/report_outline.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
$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';
Expand Down
2 changes: 1 addition & 1 deletion report/outline/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
33 changes: 33 additions & 0 deletions report/outline/tests/lib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -108,4 +120,25 @@ public function test_report_outline_myprofile_navigation_without_permission() {
$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));
}
}
2 changes: 1 addition & 1 deletion report/outline/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 124f314

Please sign in to comment.