MDL-77256 tool_uploaduser: fix get allowed roles for courses

During user upload the permission to assign roles is checked in the wrong context
This commit is contained in:
Roberto Bravo
2023-03-07 18:38:46 +01:00
parent 62cfa26cb9
commit 756f56492e
4 changed files with 263 additions and 13 deletions
+4 -1
View File
@@ -111,7 +111,10 @@ class cli_helper {
$form = new \admin_uploaduser_form1();
[$elements, $defaults] = $form->get_form_for_cli();
$options += $this->prepare_form_elements_for_cli($elements, $defaults);
$form = new \admin_uploaduser_form2(null, ['columns' => ['type1'], 'data' => []]);
// Specify pseudo-column 'type1' to force the form to populate the legacy role mapping selector
// but only if user is allowed to assign roles in courses (otherwise form validation will fail).
$columns = uu_allowed_roles() ? ['type1'] : [];
$form = new \admin_uploaduser_form2(null, ['columns' => $columns, 'data' => []]);
[$elements, $defaults] = $form->get_form_for_cli();
$options += $this->prepare_form_elements_for_cli($elements, $defaults);
return $options;