Skip to content

Commit 38f7c94

Browse files
committed
fix: check perms before installing library during restore
1 parent 75cdc6b commit 38f7c94

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

backup/moodle2/restore_hvp_stepslib.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,24 @@ protected function process_hvp_library($data) {
202202

203203
$libraryid = self::get_library_id($data);
204204
if (!$libraryid) {
205+
// If this library is not installed, ensure that the user has
206+
// permission to install it before proceeding.
207+
$params = ['machine_name' => $data->machine_name];
208+
if (!$DB->record_exists('hvp_libraries', $params)) {
209+
$systemctx = \core\context\system::instance();
210+
$caninstall = has_capability('mod/hvp:updatelibraries', $systemctx);
211+
212+
$librarycache = $DB->get_record('hvp_libraries_hub_cache', $params, 'id, is_recommended');
213+
if ($librarycache && $librarycache->is_recommended) {
214+
$coursectx = \core\context\course::instance($this->get_courseid());
215+
$caninstall = $caninstall || has_capability('mod/hvp:installrecommendedh5plibraries', $coursectx);
216+
}
217+
218+
if (!$caninstall) {
219+
throw new \core\exception\moodle_exception('restoreinstalldenied', 'hvp', '', $data->title);
220+
}
221+
}
222+
205223
// There is no updating of libraries. If an older patch version exists
206224
// on the site that one will be used instead of the new one in the backup.
207225
// This is due to the default behavior when files are restored in Moodle.

lang/en/hvp.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,3 +694,6 @@
694694
// Export libraries.
695695
$string['exportlibraries'] = 'Export libraries';
696696
$string['exportlibrarieserror'] = 'An error occured while export the libraries.';
697+
698+
// Restore H5P library.
699+
$string['restoreinstalldenied'] = 'You do not have permission to install missing content type \'{$a}\'. Please contact your site administrator.';

version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

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

26-
$plugin->version = 2024120900;
26+
$plugin->version = 2024120901;
2727
$plugin->requires = 2022112800; // 4.1.0
2828
$plugin->cron = 0;
2929
$plugin->component = 'mod_hvp';

0 commit comments

Comments
 (0)