From b1ee0c8690a07621d09ed994f0a73fcea25ce86e Mon Sep 17 00:00:00 2001 From: stronk7 Date: Wed, 17 Dec 2008 23:36:10 +0000 Subject: [PATCH] MDL-17009 restore of mnet users - Prevent teachers to restore this type of backups to different sites. Merged from 19_STABLE --- backup/restore_check.html | 48 +++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/backup/restore_check.html b/backup/restore_check.html index 6c2a4c6bd3..350885d5ea 100644 --- a/backup/restore_check.html +++ b/backup/restore_check.html @@ -270,6 +270,8 @@ print_error("cannotrestoreadminoredit"); } $show_continue_button = true; + $messages = array(); + //Check if we've selected any mod's user info and restore->users //is set to none. Change it to course and inform. if ($restore->users == 2) { @@ -285,36 +287,52 @@ $changed = 1; } if ($changed) { - echo get_string ("noteuserschangednonetocourse"); - echo "
"; + $messages[] = get_string ("noteuserschangednonetocourse"); $restore->users = 1; } } + + /// If restoring users and backup has mnet remote users and we are restoring to different site, forbid restore to non-admins. MDL-17009 + if ($restore->users != 2 && /// If restoring users + !empty($info->mnet_remoteusers) && $info->mnet_remoteusers === 'true' && /// and backup contains remote users + $info->original_wwwroot !== $CFG->wwwroot) { /// and backup is being restored to different site + + /// If user is admin (by 'moodle/user:create' cap), warn about conversion to local auth if missing mnet hosts and continue restore + if (has_capability('moodle/user:create', get_context_instance(CONTEXT_SYSTEM))) { + $messages[] = get_string('mnetrestore_extusers_admin', 'admin'); + $show_continue_button = true; + + /// else, notify about the thing (suggesting to ask admin) and stop restore + } else { + $messages[] = get_string('mnetrestore_extusers_noadmin', 'admin'); + $show_continue_button = false; + } + } + //Save the restore session object $SESSION->restore = $restore; + + echo "
"; + + /// Printout messages + foreach ($messages as $message) { + echo '

' . $message . '

'; + } + + /// Warning and button if ($show_continue_button) { //Print the continue button to execute the restore NOW !!!! //All is prepared !!! - echo "
"; $hidden["launch"] = "execute"; $hidden["file"] = $file; $hidden["id"] = $id; print_string('longtimewarning','admin'); - if ($restore->users && !empty($info->mnet_remoteusers) - && $info->mnet_remoteusers === 'true') { - if ($info->original_wwwroot === $CFG->wwwroot) { - print '

'.get_string('mnetrestore_extusers','admin').'

'; - } else { - print '

'. get_string('mnetrestore_extusers_mismatch','admin').'

'; - } - } + + /// Restore button print_single_button("restore.php", $hidden, get_string("restorecoursenow"),"post"); - echo "
"; - } else { - //Show error - print_error('error'); } + echo "
"; //If we are here. Something must be wrong. Debug !!! } else { -- 2.39.5