Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ jobs:
fail-fast: false
matrix:
include:
- php: '8.1'
moodle-branch: 'master'
- php: '8.3'
moodle-branch: 'main'
database: 'pgsql'
- php: '8.0'
moodle-branch: 'MOODLE_403_STABLE'
- php: '8.3'
moodle-branch: 'MOODLE_500_STABLE'
database: 'mariadb'
- php: '8.1'
moodle-branch: 'MOODLE_402_STABLE'
- php: '8.2'
moodle-branch: 'MOODLE_405_STABLE'
database: 'pgsql'
- php: '8.0'
moodle-branch: 'MOODLE_401_STABLE'
- php: '8.2'
moodle-branch: 'MOODLE_404_STABLE'
database: 'mariadb'

services:
postgres:
image: postgres:13
image: postgres:14
env:
POSTGRES_USER: 'postgres'
POSTGRES_HOST_AUTH_METHOD: 'trust'
Expand Down Expand Up @@ -109,7 +109,7 @@ jobs:
run: moodle-plugin-ci mustache

- name: Grunt
if: ${{ matrix.moodle-branch == 'MOODLE_402_STABLE' }}
if: ${{ always() }}
run: moodle-plugin-ci grunt --max-lint-warnings 0

- name: PHPUnit tests
Expand Down
2 changes: 1 addition & 1 deletion amd/build/userselector.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion amd/build/userselector.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 6 additions & 7 deletions amd/src/userselector.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,12 @@ export function transport(selector, query, success, failure) {

.then((results) => {
// For each user in the result, render the display, and set it on the _label field.
return Promise.all(results.map((user) => {
return Templates.render('report_customsql/form-user-selector-suggestion', user)
.then((html) => {
user._label = html;
return user;
});
}));
return Promise.all(
results.map(async(user) => {
user._label = await Templates.render('report_customsql/form-user-selector-suggestion', user);
return user;
})
);
})

.then(success)
Expand Down
5 changes: 3 additions & 2 deletions categoryadd_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
*/
class report_customsql_addcategory_form extends moodleform {

// Form definition.
#[\Override]
public function definition() {
global $CFG, $DB;
$mform = $this->_form;
Expand All @@ -54,7 +54,7 @@ public function definition() {
}

$mform->addElement('text', 'name', get_string('categoryname'), ['size' => '30']);
$mform->addRule('name', get_string('required'), 'required', null);
$mform->addRule('name', null, 'required', null);
$mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
$mform->setDefault('name', '');
$mform->setType('name', PARAM_TEXT);
Expand All @@ -65,6 +65,7 @@ public function definition() {
$this->add_action_buttons(true, $strsubmit);
}

#[\Override]
public function validation($data, $files) {
global $DB;
$errors = parent::validation($data, $files);
Expand Down
27 changes: 27 additions & 0 deletions changes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
# Change log for the Ad-hoc database queries report

## Changes in 4.4

* This version is compatible with Moodle 5.0.
* External APIs: Updated to use new base classes, as the minimum supported version is now Moodle 4.4.
* Fixed a bug so that users only see queries they have permission to view.
* Tidied up various parts of the codebase.
* Improved Behat tests and navigation URLs.
* PHPUnit: Removed unnecessary references to deprecated or removed plugins.
* Accessibility: Required form fields now use the default required field message.
* Fixed #114 — when downloading, return an empty CSV file (with headers) when there are no results.
* Fixed test queries for MySQL containing CHR characters.


## Changes in 4.3

* The report now shows results for the most recent time the query should have run,
making it clearer when there are no results.
* Improved the heading for the list of past results.
* Log events: Removed legacy logging methods for compatibility with Moodle 4.2.
* Added [wwwroot] to the email subject line to identify which environment sent the email.
* When emailing single-row queries, the number of rows sent is now limited to 5 to avoid building
an overly large list over time.
* Fixed a bug to clean the file report name before generating downloads.
* The session is now unlocked, allowing the users to run more than one report at a time (#113).
* Removed underline on mouse hover


## Changes in 4.2

* This version works with Moodle 4.0.
Expand Down
5 changes: 5 additions & 0 deletions classes/event/query_deleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,25 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class query_deleted extends \core\event\base {

#[\Override]
protected function init() {
$this->data['crud'] = 'd';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'report_customsql_queries';
}

#[\Override]
public static function get_name() {
return get_string('query_deleted', 'report_customsql');
}

#[\Override]
public function get_description() {
return "User {$this->userid} has deleted the SQL query with id {$this->objectid}.";
}

#[\Override]
public function get_url() {
return new \moodle_url('/report/customsql/index.php');
}
Expand Down
5 changes: 5 additions & 0 deletions classes/event/query_edited.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,25 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class query_edited extends \core\event\base {

#[\Override]
protected function init() {
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'report_customsql_queries';
}

#[\Override]
public static function get_name() {
return get_string('query_edited', 'report_customsql');
}

#[\Override]
public function get_description() {
return "User {$this->userid} has edited the SQL query with id {$this->objectid}.";
}

#[\Override]
public function get_url() {
return new \moodle_url('/report/customsql/view.php', ['id' => $this->objectid]);
}
Expand Down
5 changes: 5 additions & 0 deletions classes/event/query_viewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,25 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class query_viewed extends \core\event\base {

#[\Override]
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'report_customsql_queries';
}

#[\Override]
public static function get_name() {
return get_string('query_viewed', 'report_customsql');
}

#[\Override]
public function get_description() {
return "User {$this->userid} has viewed the SQL query with id {$this->objectid}.";
}

#[\Override]
public function get_url() {
return new \moodle_url('/report/customsql/view.php', ['id' => $this->objectid]);
}
Expand Down
40 changes: 21 additions & 19 deletions classes/external/get_users.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

namespace report_customsql\external;

defined('MOODLE_INTERNAL') || die();

global $CFG;
require_once($CFG->libdir . '/externallib.php');
use core_external\external_api;
use core_external\external_description;
use core_external\external_function_parameters;
use core_external\external_multiple_structure;
use core_external\external_single_structure;
use core_external\external_value;

/**
* Web service used by form autocomplete to get a list of users with a given capability.
Expand All @@ -28,16 +30,16 @@
* @copyright 2020 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class get_users extends \external_api {
class get_users extends external_api {
/**
* Parameter declaration.
*
* @return \external_function_parameters Parameters
* @return external_function_parameters Parameters
*/
public static function execute_parameters(): \external_function_parameters {
return new \external_function_parameters([
'query' => new \external_value(PARAM_RAW, 'Contents of the search box.'),
'capability' => new \external_value(PARAM_CAPABILITY, 'Return only users with this capability in the system context.'),
public static function execute_parameters(): external_function_parameters {
return new external_function_parameters([
'query' => new external_value(PARAM_RAW, 'Contents of the search box.'),
'capability' => new external_value(PARAM_CAPABILITY, 'Return only users with this capability in the system context.'),
]);
}

Expand Down Expand Up @@ -136,16 +138,16 @@ public static function prepare_result_object(\stdClass $user, array $extrafields
/**
* Returns type for declaration.
*
* @return \external_description Result type
* @return external_description Result type
*/
public static function execute_returns(): \external_description {
return new \external_multiple_structure(
new \external_single_structure([
'id' => new \external_value(PARAM_INT, 'User id.'),
'fullname' => new \external_value(PARAM_RAW, 'User full name.'),
'identity' => new \external_value(PARAM_RAW, 'Additional user identifying info.'),
'hasidentity' => new \external_value(PARAM_BOOL, 'Whether identity is non-blank.'),
'profileimageurlsmall' => new \external_value(PARAM_RAW, 'URL of the user profile image.'),
public static function execute_returns(): external_description {
return new external_multiple_structure(
new external_single_structure([
'id' => new external_value(PARAM_INT, 'User id.'),
'fullname' => new external_value(PARAM_RAW, 'User full name.'),
'identity' => new external_value(PARAM_RAW, 'Additional user identifying info.'),
'hasidentity' => new external_value(PARAM_BOOL, 'Whether identity is non-blank.'),
'profileimageurlsmall' => new external_value(PARAM_RAW, 'URL of the user profile image.'),
]));
}
}
36 changes: 31 additions & 5 deletions classes/local/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,51 @@ public function __construct(\stdClass $record) {
/**
* Load queries of category from records.
*
* @param array $queries Records to load.
* @param \stdClass[] $queries Records to load.
*/
public function load_queries_data(array $queries): void {
$statistic = [];
$queriesdata = [];
foreach (report_customsql_runable_options() as $type => $description) {
$fitleredqueries = utils::get_number_of_report_by_type($queries, $type);
$statistic[$type] = count($fitleredqueries);
if ($fitleredqueries) {
$filteredqueries = self::get_reports_of_a_particular_runtype($queries, $type);
$filteredqueries = self::filter_reports_by_capability($filteredqueries);
$statistic[$type] = count($filteredqueries);
if ($filteredqueries) {
$queriesdata[] = [
'type' => $type,
'queries' => $fitleredqueries,
'queries' => $filteredqueries,
];
}
}
$this->queriesdata = $queriesdata;
$this->statistic = $statistic;
}

/**
* Get queries for each type.
*
* @param \stdClass[] $queries Array of queries.
* @param string $type Type to filter.
* @return \stdClass[] All queries of type.
*/
public static function get_reports_of_a_particular_runtype(array $queries, string $type) {
return array_filter($queries, function($query) use ($type) {
return $query->runable == $type;
}, ARRAY_FILTER_USE_BOTH);
}

/**
* Given an array of qureries, remove any that the current user cannot access.
*
* @param \stdClass[] $queries Array of queries.
* @return \stdClass[] queries the current user is allowed to see.
*/
public static function filter_reports_by_capability(array $queries) {
return array_filter($queries, function($query) {
return has_capability($query->capability ?? 'moodle/site:config', \context_system::instance());
}, ARRAY_FILTER_USE_BOTH);
}

/**
* Get category ID.
*
Expand Down
Loading
Loading