MDL-80190 core_courseformat: prevent delegated sections loops

This patch prevent dropping an activity with delegated sections inside
another delegated section. Without this patch the teacher can create a
deadlock drag&droping the subsection inside itself. We won't allow
subsections inside subsections so any activity with subsection cannot
be dropped inside a subsección.
This commit is contained in:
Ferran Recio
2024-02-07 12:14:59 +01:00
parent d244a206a3
commit 34ce0eddc0
15 changed files with 62 additions and 12 deletions
+24 -2
View File
@@ -49,10 +49,32 @@ abstract class sectiondelegate {
if (empty($sectioninfo->component)) {
return null;
}
$classname = $sectioninfo->component . '\courseformat\sectiondelegate';
if (!class_exists($classname)) {
$classname = self::get_delegate_class_name($sectioninfo->component);
if ($classname === null) {
return null;
}
return new $classname($sectioninfo);
}
/**
* Return the delgate class name of a plugin, if any.
* @param string $pluginname
* @return string|null the delegate class name or null if not found.
*/
protected static function get_delegate_class_name(string $pluginname): ?string {
$classname = $pluginname . '\courseformat\sectiondelegate';
if (!class_exists($classname)) {
return null;
}
return $classname;
}
/**
* Check if a plugin has a delegate class.
* @param string $pluginname
* @return bool
*/
public static function has_delegate_class(string $pluginname): bool {
return self::get_delegate_class_name($pluginname) !== null;
}
}