MDL-73598 reportbuilder: feature switch for custom reports.

This commit is contained in:
Paul Holden
2022-01-19 23:20:52 +00:00
parent a01f1fa71c
commit 335012580b
6 changed files with 105 additions and 8 deletions
+14 -5
View File
@@ -51,7 +51,9 @@ class permission {
* @return bool
*/
public static function can_view_reports_list(?int $userid = null): bool {
return has_any_capability([
global $CFG;
return !empty($CFG->enablecustomreports) && has_any_capability([
'moodle/reportbuilder:editall',
'moodle/reportbuilder:edit',
'moodle/reportbuilder:view',
@@ -96,7 +98,6 @@ class permission {
*
* @param report $report
* @param int|null $userid User ID to check, or the current user if omitted
* @return void
* @throws report_access_exception
*/
public static function require_can_edit_report(report $report, ?int $userid = null): void {
@@ -113,7 +114,11 @@ class permission {
* @return bool
*/
public static function can_edit_report(report $report, ?int $userid = null): bool {
global $USER;
global $CFG, $USER;
if (empty($CFG->enablecustomreports)) {
return false;
}
// We can only edit custom reports.
if ($report->get('type') !== base::TYPE_CUSTOM_REPORT) {
@@ -135,8 +140,12 @@ class permission {
* @return bool
*/
public static function can_create_report(?int $userid = null): bool {
$capabilities = ['moodle/reportbuilder:edit', 'moodle/reportbuilder:editall'];
return has_any_capability($capabilities, context_system::instance(), $userid);
global $CFG;
return !empty($CFG->enablecustomreports) && has_any_capability([
'moodle/reportbuilder:edit',
'moodle/reportbuilder:editall',
], context_system::instance(), $userid);
}
/**