refactor!: retire legacy administration
Moodle Plugin CI / test (push) Successful in 3m26s

BREAKING CHANGE: legacy management routes now fail closed and the legacy helper API is removed.
This commit is contained in:
2026-08-20 08:08:30 +00:00
parent 297e4ab7cd
commit 82ba9222ff
17 changed files with 127 additions and 737 deletions
+2 -3
View File
@@ -25,7 +25,6 @@
namespace local_webhooks\event; namespace local_webhooks\event;
use core\event\base; use core\event\base;
use moodle_url;
/** /**
* Defines how to work with events. * Defines how to work with events.
@@ -55,10 +54,10 @@ class backup_performed extends base {
/** /**
* Get URL related to the action. * Get URL related to the action.
* *
* @throws \moodle_exception * @return null
*/ */
public function get_url() { public function get_url() {
return new moodle_url('/local/webhooks/index.php'); return null;
} }
/** /**
+2 -3
View File
@@ -25,7 +25,6 @@
namespace local_webhooks\event; namespace local_webhooks\event;
use core\event\base; use core\event\base;
use moodle_url;
/** /**
* Defines how to work with events. * Defines how to work with events.
@@ -55,10 +54,10 @@ class backup_restored extends base {
/** /**
* Get URL related to the action. * Get URL related to the action.
* *
* @throws \moodle_exception * @return null
*/ */
public function get_url() { public function get_url() {
return new moodle_url('/local/webhooks/index.php'); return null;
} }
/** /**
+2 -3
View File
@@ -25,7 +25,6 @@
namespace local_webhooks\event; namespace local_webhooks\event;
use core\event\base; use core\event\base;
use moodle_url;
/** /**
* Defines how to work with events. * Defines how to work with events.
@@ -53,10 +52,10 @@ class response_answer extends base {
/** /**
* Get URL related to the action. * Get URL related to the action.
* *
* @throws \moodle_exception * @return null
*/ */
public function get_url() { public function get_url() {
return new moodle_url('/local/webhooks/editservice.php', ['serviceid' => $this->objectid]); return null;
} }
/** /**
+2 -3
View File
@@ -25,7 +25,6 @@
namespace local_webhooks\event; namespace local_webhooks\event;
use core\event\base; use core\event\base;
use moodle_url;
/** /**
* Defines how to work with events. * Defines how to work with events.
@@ -55,10 +54,10 @@ class service_added extends base {
/** /**
* Get URL related to the action. * Get URL related to the action.
* *
* @throws \moodle_exception * @return null
*/ */
public function get_url() { public function get_url() {
return new moodle_url('/local/webhooks/editservice.php', ['serviceid' => $this->objectid]); return null;
} }
/** /**
+2 -3
View File
@@ -25,7 +25,6 @@
namespace local_webhooks\event; namespace local_webhooks\event;
use core\event\base; use core\event\base;
use moodle_url;
/** /**
* Defines how to work with events. * Defines how to work with events.
@@ -55,10 +54,10 @@ class service_deleted extends base {
/** /**
* Get URL related to the action. * Get URL related to the action.
* *
* @throws \moodle_exception * @return null
*/ */
public function get_url() { public function get_url() {
return new moodle_url('/local/webhooks/index.php'); return null;
} }
/** /**
+2 -3
View File
@@ -25,7 +25,6 @@
namespace local_webhooks\event; namespace local_webhooks\event;
use core\event\base; use core\event\base;
use moodle_url;
/** /**
* Defines how to work with events. * Defines how to work with events.
@@ -55,10 +54,10 @@ class service_updated extends base {
/** /**
* Get URL related to the action. * Get URL related to the action.
* *
* @throws \moodle_exception * @return null
*/ */
public function get_url() { public function get_url() {
return new moodle_url('/local/webhooks/editservice.php', ['serviceid' => $this->objectid]); return null;
} }
/** /**
-103
View File
@@ -1,103 +0,0 @@
<?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/>.
/**
* Defines the service editing form.
*
* @package local_webhooks
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/formslib.php');
/**
* Description editing form definition.
*
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class service_edit_form extends moodleform {
/**
* Defines the standard structure of the form.
*
* @throws \coding_exception
*/
protected function definition() {
$mform =& $this->_form;
$size = ['size' => 60];
/* Form heading */
$mform->addElement('header', 'editserviceheader', new lang_string('service', 'local_webhooks'));
/* Name of the service */
$mform->addElement('text', 'title', new lang_string('name', 'local_webhooks'), $size);
$mform->addRule('title', null, 'required');
$mform->setType('title', PARAM_NOTAGS);
/* Callback address */
$mform->addElement('text', 'url', new lang_string('url', 'local_webhooks'), $size);
$mform->addRule('url', null, 'required');
$mform->setType('url', PARAM_URL);
/* Enabling the service */
$mform->addElement('advcheckbox', 'enable', new lang_string('enable', 'local_webhooks'));
$mform->setType('enable', PARAM_BOOL);
$mform->setDefault('enable', 1);
$mform->setAdvanced('enable');
/* Token */
$mform->addElement('text', 'token', new lang_string('token', 'local_webhooks'), $size);
$mform->setType('token', PARAM_NOTAGS);
/* Additional information */
$mform->addElement('text', 'other', new lang_string('sourceext', 'local_webhooks'), $size);
$mform->setType('other', PARAM_NOTAGS);
$mform->setAdvanced('other');
/* Content type */
$contenttype = [
'json' => 'application/json',
'x-www-form-urlencoded' => 'application/x-www-form-urlencoded',
];
$mform->addElement('select', 'type', new lang_string('contenttype', 'local_webhooks'), $contenttype);
$mform->setAdvanced('type');
/* Form heading */
$mform->addElement('header', 'editserviceheaderevent', new lang_string('edulevel', 'local_webhooks'));
/* List of events */
$events = [];
/* Formation of the list of elements */
foreach (local_webhooks_get_event_choices() as $component => $choices) {
foreach ($choices as $key => $eventname) {
$events[$component][] =& $mform->createElement('checkbox', $key, $eventname);
}
}
/* Displays groups of items */
foreach ($events as $key => $event) {
$mform->addGroup($event, 'events', $key, '<br />');
}
/* Control Panel */
$this->add_action_buttons();
}
}
-54
View File
@@ -1,54 +0,0 @@
<?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/>.
/**
* Defines forms.
*
* @package local_webhooks
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/formslib.php');
/**
* Description of the form of restoration.
*
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class service_backup_form extends moodleform {
/**
* Defines the standard structure of the form.
*
* @throws \coding_exception
*/
protected function definition() {
$mform =& $this->_form;
/* Form heading */
$mform->addElement('header', 'editserviceheader', new lang_string('restore', 'local_webhooks'));
/* Download the file */
$mform->addElement('filepicker', 'backupfile', new lang_string('file', 'local_webhooks'));
$mform->addRule('backupfile', null, 'required');
/* Control Panel */
$this->add_action_buttons(true, new lang_string('restore', 'local_webhooks'));
}
}
+3 -78
View File
@@ -23,83 +23,8 @@
*/ */
require_once(__DIR__ . '/../../config.php'); require_once(__DIR__ . '/../../config.php');
require_once(__DIR__ . '/classes/service_edit_form.php');
require_once(__DIR__ . '/lib.php');
require_once($CFG->libdir . '/adminlib.php'); require_login();
require_capability('moodle/site:config', context_system::instance());
/* Optional parameters */ throw new moodle_exception('legacyuidisabled', 'local_webhooks');
$serviceid = optional_param('serviceid', 0, PARAM_INT);
/* Link generation */
$urlparameters = ['serviceid' => $serviceid];
$baseurl = new moodle_url('/local/webhooks/editservice.php', $urlparameters);
$managerservice = new moodle_url('/local/webhooks/index.php');
/* Configure the context of the page */
admin_externalpage_setup('local_webhooks', '', null, $baseurl);
$context = context_system::instance();
/* Create an editing form */
$mform = new service_edit_form($PAGE->url);
/* Cancel processing */
if ($mform->is_cancelled()) {
redirect($managerservice);
}
/* Getting the data */
$servicerecord = new stdClass();
if (($editing = (bool) $serviceid) === true) {
$servicerecord = local_webhooks_get_record($serviceid);
if (is_array($servicerecord->events)) {
$events = [];
/* Escaping event names */
foreach ($servicerecord->events as $eventname => $eventstatus) {
$eventname = base64_encode($eventname);
$events[$eventname] = $eventstatus;
}
$servicerecord->events = $events;
}
$mform->set_data($servicerecord);
}
/* Processing of received data */
if (!empty($data = $mform->get_data())) {
if (is_array($data->events)) {
$events = [];
/* Deciphering event names */
foreach ($data->events as $eventname => $eventstatus) {
$eventname = (string) base64_decode($eventname);
$events[$eventname] = $eventstatus;
}
$data->events = $events;
}
if ($editing) {
$data->id = $serviceid;
local_webhooks_update_record($data, false);
redirect($managerservice, new lang_string('eventwebserviceserviceupdated', 'local_webhooks'));
} else {
local_webhooks_update_record($data);
redirect($managerservice, new lang_string('eventwebserviceservicecreated', 'local_webhooks'));
}
}
/* The page title */
$titlepage = new lang_string('externalservice', 'local_webhooks');
$PAGE->navbar->add($titlepage);
$PAGE->set_heading($titlepage);
$PAGE->set_title($titlepage);
echo $OUTPUT->header();
/* Displays the form */
$mform->display();
echo $OUTPUT->footer();
+3 -119
View File
@@ -23,124 +23,8 @@
*/ */
require_once(__DIR__ . '/../../config.php'); require_once(__DIR__ . '/../../config.php');
require_once(__DIR__ . '/lib.php');
require_once($CFG->libdir . '/adminlib.php'); require_login();
require_once($CFG->libdir . '/tablelib.php'); require_capability('moodle/site:config', context_system::instance());
/* Optional parameters */ throw new moodle_exception('legacyuidisabled', 'local_webhooks');
$backupservices = optional_param('getbackup', 0, PARAM_BOOL);
$deleteid = optional_param('deleteid', 0, PARAM_INT);
$hideshowid = optional_param('hideshowid', 0, PARAM_INT);
/* Link generation */
$editservice = '/local/webhooks/editservice.php';
$managerservice = '/local/webhooks/index.php';
$restorebackup = '/local/webhooks/restorebackup.php';
$baseurl = new moodle_url($managerservice);
/* Configure the context of the page */
admin_externalpage_setup('local_webhooks', '', null, $baseurl);
$context = context_system::instance();
/* Delete the service */
if ((bool) $deleteid) {
local_webhooks_remove_record($deleteid);
redirect($PAGE->url, new lang_string('eventwebserviceservicedeleted', 'local_webhooks'));
}
/* Retrieving a list of services */
$callbacks = local_webhooks_get_list_records();
/* Upload settings as a file */
if ((bool) $backupservices) {
$filecontent = local_webhooks_create_backup();
$filename = 'webhooks_' . date('U') . '.backup';
send_file($filecontent, $filename, 0, 0, true, true);
}
/* Switching the status of the service */
if ((bool) $hideshowid) {
$callback = $callbacks[$hideshowid];
if (!empty($callback)) {
$callback->enable = !(bool) $callback->enable;
local_webhooks_update_record($callback, false);
redirect($PAGE->url, new lang_string('eventwebserviceserviceupdated', 'local_webhooks'));
}
}
/* The page title */
$titlepage = new lang_string('pluginname', 'local_webhooks');
$PAGE->set_heading($titlepage);
$PAGE->set_title($titlepage);
echo $OUTPUT->header();
/* Table declaration */
$table = new flexible_table('webhooks-service-table');
/* Customize the table */
$table->define_columns(
[
'title',
'url',
'actions',
]
);
$table->define_headers(
[
new lang_string('name', 'local_webhooks'),
new lang_string('url', 'local_webhooks'),
new lang_string('actions', 'local_webhooks'),
]
);
$table->define_baseurl($baseurl);
$table->setup();
foreach ($callbacks as $callback) {
/* Filling of information columns */
$titlecallback = html_writer::div($callback->title, 'title');
$urlcallback = html_writer::div($callback->url, 'url');
/* Defining service status */
$hideshowicon = 't/show';
$hideshowstring = new lang_string('enable', 'local_webhooks');
if ((bool) $callback->enable) {
$hideshowicon = 't/hide';
$hideshowstring = new lang_string('disable', 'local_webhooks');
}
/* Link to enable / disable the service */
$hideshowlink = new moodle_url($managerservice, ['hideshowid' => $callback->id]);
$hideshowitem = $OUTPUT->action_icon($hideshowlink, new pix_icon($hideshowicon, $hideshowstring));
/* Link for editing */
$editlink = new moodle_url($editservice, ['serviceid' => $callback->id]);
$edititem = $OUTPUT->action_icon($editlink, new pix_icon('t/edit', new lang_string('edit', 'local_webhooks')));
/* Link to remove */
$deletelink = new moodle_url($managerservice, ['deleteid' => $callback->id]);
$deleteitem = $OUTPUT->action_icon($deletelink, new pix_icon('t/delete', new lang_string('delete', 'local_webhooks')));
/* Adding data to the table */
$table->add_data([$titlecallback, $urlcallback, $hideshowitem . $edititem . $deleteitem]);
}
/* Display the table */
$table->print_html();
/* Add service button */
$addserviceurl = new moodle_url($editservice);
echo $OUTPUT->single_button($addserviceurl, new lang_string('addaservice', 'local_webhooks'), 'get');
/* Button to get a backup */
$backupurl = new moodle_url($managerservice, ['getbackup' => true]);
echo $OUTPUT->single_button($backupurl, new lang_string('backup', 'local_webhooks'), 'get');
/* Button for restoring settings */
$restorebackupurl = new moodle_url($restorebackup);
echo $OUTPUT->single_button($restorebackupurl, new lang_string('restore', 'local_webhooks'), 'get');
echo $OUTPUT->footer();
+1
View File
@@ -41,6 +41,7 @@ $string['eventwebserviceservicedeleted'] = 'Web service deleted';
$string['eventwebserviceserviceupdated'] = 'Web service updated'; $string['eventwebserviceserviceupdated'] = 'Web service updated';
$string['externalservice'] = 'External service'; $string['externalservice'] = 'External service';
$string['file'] = 'File'; $string['file'] = 'File';
$string['legacyuidisabled'] = 'Legacy webhook management is disabled during the 6.0 upgrade.';
$string['name'] = 'Name'; $string['name'] = 'Name';
$string['pluginname'] = 'WebHooks'; $string['pluginname'] = 'WebHooks';
$string['privacy:metadata'] = 'WebHooks does not store any personal data.'; $string['privacy:metadata'] = 'WebHooks does not store any personal data.';
-160
View File
@@ -22,10 +22,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__ . '/locallib.php');
/** /**
* Returns available event classes grouped by component. * Returns available event classes grouped by component.
* *
@@ -67,159 +63,3 @@ function local_webhooks_get_event_choices() {
return $choices; return $choices;
} }
/**
* Getting a list of all services.
*
* @param int $limitfrom
* @param int $limitnum
*
* @return array
* @throws \dml_exception
*/
function local_webhooks_get_list_records($limitfrom = 0, $limitnum = 0) {
global $DB;
$listservices = $DB->get_records('local_webhooks_service', null, 'id', '*', $limitfrom, $limitnum);
foreach ($listservices as $servicerecord) {
if (!empty($servicerecord->events)) {
$servicerecord->events = local_webhooks_unarchive_data($servicerecord->events);
}
}
return $listservices;
}
/**
* Getting information about the service.
*
* @param int $serviceid
*
* @return object
* @throws \dml_exception
*/
function local_webhooks_get_record($serviceid = 0) {
global $DB;
$servicerecord = $DB->get_record('local_webhooks_service', ['id' => $serviceid], '*', MUST_EXIST);
if (!empty($servicerecord->events)) {
$servicerecord->events = local_webhooks_unarchive_data($servicerecord->events);
}
return $servicerecord;
}
/**
* Clear the database table.
*
* @throws \dml_exception
*/
function local_webhooks_remove_list_records() {
global $DB;
$DB->delete_records('local_webhooks_service');
}
/**
* Delete the record.
*
* @param int $serviceid
*
* @throws \dml_exception
* @throws \coding_exception
*/
function local_webhooks_remove_record($serviceid = 0) {
global $DB;
$DB->delete_records('local_webhooks_service', ['id' => $serviceid]);
local_webhooks_events::service_deleted($serviceid);
}
/**
* Update the record in the database.
*
* @param object $data
* @param boolean $insert
*
* @return boolean
* @throws \dml_exception
* @throws \coding_exception
*/
function local_webhooks_update_record($data, $insert = true) {
global $DB;
if (empty($data->events)) {
$data->events = [];
}
$data->events = local_webhooks_archiving_data($data->events);
if ((bool) $insert) {
$result = $DB->insert_record('local_webhooks_service', $data);
local_webhooks_events::service_added($result);
} else {
$result = $DB->update_record('local_webhooks_service', $data);
local_webhooks_events::service_updated($data->id);
}
return (bool) $result;
}
/**
* Make a backup copy of all the services.
*
* @return string
* @throws \dml_exception
* @throws \coding_exception
*/
function local_webhooks_create_backup() {
$listservices = local_webhooks_get_list_records();
$listservices = local_webhooks_archiving_data($listservices);
local_webhooks_events::backup_performed();
return $listservices;
}
/**
* Restore the data from the backup.
*
* @param string $listservices
*
* @throws \dml_exception
* @throws \coding_exception
*/
function local_webhooks_restore_backup($listservices = '') {
$listservices = local_webhooks_unarchive_data($listservices);
local_webhooks_remove_list_records();
foreach ($listservices as $servicerecord) {
local_webhooks_update_record($servicerecord);
}
local_webhooks_events::backup_restored();
}
/**
* Compress an array into a string.
*
* @param array $data
*
* @return string
*/
function local_webhooks_archiving_data(array $data = []) {
return base64_encode(gzcompress(serialize($data), 3));
}
/**
* Gets an array from a compressed string.
*
* @param string $data
*
* @return array
*/
function local_webhooks_unarchive_data($data = '') {
return unserialize(gzuncompress(base64_decode($data)));
}
-151
View File
@@ -1,151 +0,0 @@
<?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/>.
/**
* Classes of modules.
*
* @package local_webhooks
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Description of functions of the call of events
*
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class local_webhooks_events {
/**
* Call the event when creating a backup.
*
* @throws \coding_exception
* @throws \dml_exception
*/
public static function backup_performed() {
$context = context_system::instance();
$event = local_webhooks\event\backup_performed::create(
[
'context' => $context,
'objectid' => 0,
]
);
$event->trigger();
}
/**
* Call the event when restoring from a backup.
*
* @throws \coding_exception
* @throws \dml_exception
*/
public static function backup_restored() {
$context = context_system::instance();
$event = local_webhooks\event\backup_restored::create(
[
'context' => $context,
'objectid' => 0,
]
);
$event->trigger();
}
/**
* Call event when the response is received from the service
*
* @param int $objectid Service ID
* @param array $response Server response
*
* @throws \coding_exception
* @throws \dml_exception
*/
public static function response_answer($objectid = 0, array $response = []) {
$context = context_system::instance();
$status = get_string('errorsendingrequest', 'local_webhooks');
if (!empty($response['HTTP/1.1'])) {
$status = $response['HTTP/1.1'];
}
$event = local_webhooks\event\response_answer::create(
[
'context' => $context,
'objectid' => $objectid,
'other' => ['status' => $status],
]
);
$event->trigger();
}
/**
* Call the event when the service is added.
*
* @param int $objectid Service ID
*
* @throws \coding_exception
* @throws \dml_exception
*/
public static function service_added($objectid = 0) {
$context = context_system::instance();
$event = local_webhooks\event\service_added::create(
compact('context', 'objectid')
);
$event->trigger();
}
/**
* Call the event when the service is deleted.
*
* @param int $objectid Service ID
*
* @throws \coding_exception
* @throws \dml_exception
*/
public static function service_deleted($objectid = 0) {
$context = context_system::instance();
$event = local_webhooks\event\service_deleted::create(
compact('context', 'objectid')
);
$event->trigger();
}
/**
* Call event when the service is updated.
*
* @param int $objectid Service ID
*
* @throws \coding_exception
* @throws \dml_exception
*/
public static function service_updated($objectid = 0) {
$context = context_system::instance();
$event = local_webhooks\event\service_updated::create(
compact('context', 'objectid')
);
$event->trigger();
}
}
+3 -37
View File
@@ -23,42 +23,8 @@
*/ */
require_once(__DIR__ . '/../../config.php'); require_once(__DIR__ . '/../../config.php');
require_once(__DIR__ . '/classes/service_form.php');
require_once(__DIR__ . '/lib.php');
require_once($CFG->libdir . '/adminlib.php'); require_login();
require_capability('moodle/site:config', context_system::instance());
/* Link generation */ throw new moodle_exception('legacyuidisabled', 'local_webhooks');
$baseurl = new moodle_url('/local/webhooks/restorebackup.php');
$managerservice = new moodle_url('/local/webhooks/index.php');
/* Configure the context of the page */
admin_externalpage_setup('local_webhooks', '', null, $baseurl);
$context = context_system::instance();
/* Create an editing form */
$mform = new service_backup_form($PAGE->url);
/* Cancel processing */
if ($mform->is_cancelled()) {
redirect($managerservice);
}
/* Processing the received file */
if (!empty($data = $mform->get_data())) {
$content = $mform->get_file_content('backupfile');
local_webhooks_restore_backup($content);
redirect($managerservice, new lang_string('restorefinished', 'local_webhooks'));
}
/* The page title */
$titlepage = new lang_string('backup', 'local_webhooks');
$PAGE->navbar->add($titlepage);
$PAGE->set_heading($titlepage);
$PAGE->set_title($titlepage);
echo $OUTPUT->header();
/* Displays the form */
$mform->display();
echo $OUTPUT->footer();
+1 -11
View File
@@ -22,15 +22,5 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
// phpcs:ignore moodle.Files.MoodleInternal.MoodleInternalNotNeeded -- Intentional inert upgrade tombstone.
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
if ($hassiteconfig) {
$ADMIN->add(
'server',
new admin_externalpage(
'local_webhooks',
new lang_string('pluginname', 'local_webhooks'),
new moodle_url('/local/webhooks/index.php')
)
);
}
-6
View File
@@ -36,7 +36,6 @@ final class autonomy_test extends \advanced_testcase {
global $CFG; global $CFG;
require_once($CFG->dirroot . '/local/webhooks/lib.php'); require_once($CFG->dirroot . '/local/webhooks/lib.php');
require_once($CFG->dirroot . '/local/webhooks/classes/service_edit_form.php');
$debugsettings = [$CFG->debug, $CFG->debugdisplay, $CFG->debugdeveloper]; $debugsettings = [$CFG->debug, $CFG->debugdisplay, $CFG->debugdeveloper];
$choices = \local_webhooks_get_event_choices(); $choices = \local_webhooks_get_event_choices();
@@ -82,10 +81,5 @@ final class autonomy_test extends \advanced_testcase {
} }
$this->assertFalse(class_exists('report_eventlist_list_generator', false)); $this->assertFalse(class_exists('report_eventlist_list_generator', false));
$form = new \service_edit_form(new \moodle_url('/local/webhooks/editservice.php'));
$html = $form->render();
$this->assertStringContainsString($coreevent, $html);
$this->assertStringContainsString($localevent, $html);
$this->assertFalse(class_exists('report_eventlist_list_generator', false));
} }
} }
+104
View File
@@ -0,0 +1,104 @@
<?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/>.
/**
* Legacy management surface tests.
*
* @package local_webhooks
* @copyright 2026 "Valentin Popov" <info@valentineus.link>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_webhooks;
/**
* Legacy management surface tests.
*/
#[\PHPUnit\Framework\Attributes\CoversNothing]
final class legacy_ui_test extends \advanced_testcase {
/**
* Legacy management is unavailable without leaving dead links or write helpers.
*/
public function test_legacy_management_is_retired(): void {
global $CFG;
$this->resetAfterTest();
$user = $this->getDataGenerator()->create_user();
$this->setUser($user);
foreach (['index.php', 'editservice.php', 'restorebackup.php'] as $entrypoint) {
try {
require($CFG->dirroot . '/local/webhooks/' . $entrypoint);
$this->fail($entrypoint . ' allowed a user without site configuration capability.');
} catch (\required_capability_exception $exception) {
$this->assertSame('nopermissions', $exception->errorcode);
}
}
$this->setAdminUser();
foreach (['index.php', 'editservice.php', 'restorebackup.php'] as $entrypoint) {
try {
require($CFG->dirroot . '/local/webhooks/' . $entrypoint);
$this->fail($entrypoint . ' did not fail closed.');
} catch (\moodle_exception $exception) {
$this->assertSame('legacyuidisabled', $exception->errorcode);
}
}
require_once($CFG->libdir . '/adminlib.php');
$this->assertNull(admin_get_root(true)->locate('local_webhooks'));
foreach (['classes/service_edit_form.php', 'classes/service_form.php', 'locallib.php'] as $file) {
$this->assertFileDoesNotExist($CFG->dirroot . '/local/webhooks/' . $file);
}
require_once($CFG->dirroot . '/local/webhooks/lib.php');
$this->assertTrue(function_exists('local_webhooks_get_event_choices'));
$helpers = [
'local_webhooks_get_list_records',
'local_webhooks_get_record',
'local_webhooks_remove_list_records',
'local_webhooks_remove_record',
'local_webhooks_update_record',
'local_webhooks_create_backup',
'local_webhooks_restore_backup',
'local_webhooks_archiving_data',
'local_webhooks_unarchive_data',
];
foreach ($helpers as $helper) {
$this->assertFalse(function_exists($helper), $helper . ' is still callable.');
}
$context = \context_system::instance();
$events = [
event\backup_performed::create(['context' => $context, 'objectid' => 0]),
event\backup_restored::create(['context' => $context, 'objectid' => 0]),
event\response_answer::create([
'context' => $context,
'objectid' => 1,
'other' => ['status' => 'disabled'],
]),
event\service_added::create(['context' => $context, 'objectid' => 1]),
event\service_deleted::create(['context' => $context, 'objectid' => 1]),
event\service_updated::create(['context' => $context, 'objectid' => 1]),
];
foreach ($events as $event) {
$this->assertNull($event->get_url());
}
}
}