91334a46b5
Co-authored-by: Cursor <cursoragent@cursor.com>
70 lines
2.2 KiB
PHP
70 lines
2.2 KiB
PHP
<?php
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
/**
|
|
* Reset site access settings (role mapping or feature matrix) to built-in defaults.
|
|
*
|
|
* @package mod_meetletacbfree
|
|
* @copyright 2026 MeetLet
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
*/
|
|
|
|
define('AJAX_SCRIPT', true);
|
|
|
|
require_once('../../../config.php');
|
|
|
|
use mod_meetletacbfree\local\featureaccess;
|
|
use mod_meetletacbfree\local\roles;
|
|
|
|
require_login();
|
|
require_capability('moodle/site:config', context_system::instance());
|
|
require_sesskey();
|
|
|
|
\mod_meetletacbfree\registration\manager::require_registered();
|
|
|
|
$section = required_param('section', PARAM_ALPHA);
|
|
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
|
|
try {
|
|
if ($section === 'rolemapping') {
|
|
$rules = roles::builtin_site_defaults();
|
|
$json = json_encode($rules, JSON_UNESCAPED_UNICODE);
|
|
set_config('default_participants', $json, 'meetletacbfree');
|
|
echo json_encode([
|
|
'success' => true,
|
|
'section' => 'rolemapping',
|
|
'matrix' => roles::matrix_from_rules($rules),
|
|
'message' => get_string('reset_success_rolemapping', 'meetletacbfree'),
|
|
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
|
exit;
|
|
}
|
|
|
|
if ($section === 'featureaccess') {
|
|
$matrix = featureaccess::builtin_defaults();
|
|
$json = json_encode($matrix, JSON_UNESCAPED_UNICODE);
|
|
set_config('featureaccess', $json, 'meetletacbfree');
|
|
echo json_encode([
|
|
'success' => true,
|
|
'section' => 'featureaccess',
|
|
'matrix' => $matrix,
|
|
'message' => get_string('reset_success_featureaccess', 'meetletacbfree'),
|
|
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
|
exit;
|
|
}
|
|
|
|
throw new moodle_exception('invalidparameter');
|
|
} catch (Throwable $e) {
|
|
$error = $e->getMessage();
|
|
if ($e instanceof moodle_exception) {
|
|
$info = get_exception_info($e);
|
|
if (!empty($info->message)) {
|
|
$error = (string)$info->message;
|
|
}
|
|
}
|
|
echo json_encode([
|
|
'success' => false,
|
|
'error' => $error !== '' ? $error : get_string('reset_error', 'meetletacbfree'),
|
|
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
|
}
|