Skip to content

Commit

Permalink
MDL-49632 User preferences: Move preferences out of edit profile form.
Browse files Browse the repository at this point in the history
This is a super confusing place to change your default text editor. Lets
make these things easy to find.

Part of MDL-45774
  • Loading branch information
Damyon Wiese authored and abgreeve committed Apr 10, 2015
1 parent c78dbe0 commit 479fa47
Show file tree
Hide file tree
Showing 17 changed files with 633 additions and 40 deletions.
2 changes: 1 addition & 1 deletion lang/en/admin.php
Expand Up @@ -1082,7 +1082,7 @@
$string['updateavailableinstall'] = 'Install this update';
$string['updateavailablenot'] = 'Your Moodle code is up-to-date!';
$string['updatenotifications'] = 'Update notifications';
$string['updatenotificationfooter'] = 'Your Moodle site {$a->siteurl} is configured to automatically check for available updates. You are receiving this message as the administrator of the site. You can disable automatic checks for available updates in the Site administration section of the Administration block. You can customize the delivery of this message via your personal Messaging setting in the My profile settings section.';
$string['updatenotificationfooter'] = 'Your Moodle site {$a->siteurl} is configured to automatically check for available updates. You are receiving this message as the administrator of the site. You can disable automatic checks for available updates in the Site administration section of the Administration block. You can customize the delivery of this message via your personal Messaging setting in the My preferences section.';
$string['updatenotificationsubject'] = 'Moodle updates are available ({$a->siteurl})';
$string['updateautocheck'] = 'Automatically check for available updates';
$string['updateautocheck_desc'] = 'If enabled, your site will automatically check for available updates for both Moodle code and all additional plugins. If there is a new update available, a notification will be sent to site admins.';
Expand Down
2 changes: 2 additions & 0 deletions lang/en/moodle.php
Expand Up @@ -552,6 +552,7 @@
$string['editorenablespelling'] = 'Enable spellchecking';
$string['editorfontlist'] = 'Fontlist';
$string['editorfontsize'] = 'Default font-size';
$string['editorpreferences'] = 'Editor preferences';
$string['editorresettodefaults'] = 'Reset to default values';
$string['editorsettings'] = 'Editor settings';
$string['editorshortcutkeys'] = 'Editor shortcut keys';
Expand Down Expand Up @@ -818,6 +819,7 @@
$string['formatplain'] = 'Plain text format';
$string['formattext'] = 'Moodle auto-format';
$string['formattexttype'] = 'Formatting';
$string['forumpreferences'] = 'Forum preferences';
$string['framesetinfo'] = 'This frameset document contains:';
$string['from'] = 'From';
$string['frontpagecategorycombo'] = 'Combo list';
Expand Down
4 changes: 2 additions & 2 deletions lang/en/webservice.php
Expand Up @@ -182,7 +182,7 @@
$string['simpleauthlog'] = 'Simple authentication login';
$string['step'] = 'Step';
$string['supplyinfo'] = 'More details';
$string['testauserwithtestclientdescription'] = 'Simulate external access to the service using the web service test client. Before doing so, login as a user with the moodle/webservice:createtoken capability and obtain the security key (token) via My profile settings. You will use this token in the test client. In the test client, also choose an enabled protocol with the token authentication. <strong>WARNING: The functions that you test WILL BE EXECUTED for this user, so be careful what you choose to test!</strong>';
$string['testauserwithtestclientdescription'] = 'Simulate external access to the service using the web service test client. Before doing so, login as a user with the moodle/webservice:createtoken capability and obtain the security key (token) via My preferences settings. You will use this token in the test client. In the test client, also choose an enabled protocol with the token authentication. <strong>WARNING: The functions that you test WILL BE EXECUTED for this user, so be careful what you choose to test!</strong>';
$string['testclient'] = 'Web service test client';
$string['testclientdescription'] = '* The web service test client <strong>executes</strong> the functions for <strong>REAL</strong>. Do not test functions that you don\'t know. <br/>* All existing web service functions are not yet implemented into the test client. <br/>* In order to check that a user cannot access some functions, you can test some functions that you didn\'t allow.<br/>* To see clearer error messages set the debugging to <strong>{$a->mode}</strong> into {$a->atag}<br/>* Access the {$a->amfatag}.';
$string['testwithtestclient'] = 'Test the service';
Expand All @@ -197,7 +197,7 @@
$string['uploadfiles'] = 'Can upload files';
$string['uploadfiles_help'] = 'If enabled, any user can upload files with their security keys to their own private files area or a draft file area. Any user file quotas apply.';
$string['userasclients'] = 'Users as clients with token';
$string['userasclientsdescription'] = 'The following steps help you to set up the Moodle web service for users as clients. These steps also help to set up the recommended token (security keys) authentication method. In this use case, the user will generate his token from the security keys page via My profile settings.';
$string['userasclientsdescription'] = 'The following steps help you to set up the Moodle web service for users as clients. These steps also help to set up the recommended token (security keys) authentication method. In this use case, the user will generate his token from the security keys page via My preferences settings.';
$string['usermissingcaps'] = 'Missing capabilities: {$a}';
$string['usernameorid'] = 'Username / User id';
$string['usernameorid_help'] = 'Enter a username or a user id.';
Expand Down
27 changes: 27 additions & 0 deletions lib/navigationlib.php
Expand Up @@ -4357,6 +4357,33 @@ protected function generate_user_settings($courseid, $userid, $gstitle='usercurr
$useraccount->add(get_string("changepassword"), $passwordchangeurl, self::TYPE_SETTING, null, 'changepassword');
}

if (isloggedin() && !isguestuser($user) && !is_mnet_remote_user($user)) {
if ($currentuser && has_capability('moodle/user:editownprofile', $systemcontext) ||
has_capability('moodle/user:editprofile', $usercontext)) {
$url = new moodle_url('/user/language.php', array('id'=>$user->id, 'course'=>$course->id));
$useraccount->add(get_string('preferredlanguage'), $url, self::TYPE_SETTING);
}
}
$pluginmanager = core_plugin_manager::instance();
$enabled = $pluginmanager->get_enabled_plugins('mod');
if (isset($enabled['forum']) && isloggedin() && !isguestuser($user) && !is_mnet_remote_user($user)) {
if ($currentuser && has_capability('moodle/user:editownprofile', $systemcontext) ||
has_capability('moodle/user:editprofile', $usercontext)) {
$url = new moodle_url('/user/forum.php', array('id'=>$user->id, 'course'=>$course->id));
$useraccount->add(get_string('forumpreferences'), $url, self::TYPE_SETTING);
}
}
$editors = editors_get_enabled();
if (count($editors) > 1) {
if (isloggedin() && !isguestuser($user) && !is_mnet_remote_user($user)) {
if ($currentuser && has_capability('moodle/user:editownprofile', $systemcontext) ||
has_capability('moodle/user:editprofile', $usercontext)) {
$url = new moodle_url('/user/editor.php', array('id'=>$user->id, 'course'=>$course->id));
$useraccount->add(get_string('editorpreferences'), $url, self::TYPE_SETTING);
}
}
}

// View the roles settings.
if (has_any_capability(array('moodle/role:assign', 'moodle/role:safeoverride','moodle/role:override', 'moodle/role:manage'),
$usercontext)) {
Expand Down
8 changes: 7 additions & 1 deletion message/edit.php
Expand Up @@ -24,6 +24,7 @@

require_once(dirname(__FILE__) . '/../config.php');
require_once($CFG->dirroot . '/message/lib.php');
require_once($CFG->dirroot . '/user/lib.php');

$userid = optional_param('id', 0, PARAM_INT); // User id.
$disableall = optional_param('disableall', 0, PARAM_BOOL); //disable all of this user's notifications
Expand Down Expand Up @@ -129,6 +130,9 @@
print_error('cannotupdateusermsgpref');
}

$user->mailformat = $form->mailformat;
user_update_user($user, false, false);

redirect("$CFG->wwwroot/message/edit.php?id=$user->id");
}

Expand Down Expand Up @@ -161,11 +165,13 @@
//load general messaging preferences
$preferences->blocknoncontacts = get_user_preferences( 'message_blocknoncontacts', '', $user->id);
$preferences->beepnewmessage = get_user_preferences( 'message_beepnewmessage', '', $user->id);
$preferences->mailformat = $user->mailformat;
$preferences->mailcharset = get_user_preferences( 'mailcharset', '', $user->id);

/// Display page header
$strmessaging = get_string('messaging', 'message');
$PAGE->set_title($strmessaging);
$PAGE->set_heading(fullname($USER));
$PAGE->set_heading(fullname($user));

// Grab the renderer
$renderer = $PAGE->get_renderer('core', 'message');
Expand Down
4 changes: 2 additions & 2 deletions message/output/email/lang/en/message_email.php
Expand Up @@ -25,7 +25,7 @@
$string['allowattachments'] = 'Allow attachments';
$string['allowusermailcharset'] = 'Allow user to select character set';
$string['configallowattachments'] = 'If enabled, emails sent from the site can have attachments, such as badges.';
$string['configallowusermailcharset'] = 'If enabled, users can choose an email charset in their profile settings.';
$string['configallowusermailcharset'] = 'If enabled, users can choose an email charset in their messaging preferences.';
$string['configmailnewline'] = 'Newline characters used in mail messages. CRLF is required according to RFC 822bis, some mail servers do automatic conversion from LF to CRLF, other mail servers do incorrect conversion from CRLF to CRCRLF, yet others reject mails with bare LF (qmail for example). Try changing this setting if you are having problems with undelivered emails or double newlines.';
$string['confignoreplyaddress'] = 'Emails are sometimes sent out on behalf of a user (eg forum posts). The email address you specify here will be used as the "From" address in those cases when the recipients should not be able to reply directly to the user (eg when a user chooses to keep their address private).';
$string['configemailonlyfromnoreplyaddress'] = 'If enabled, all email will be sent using the no-reply address as the "from" address. This can be used to stop anti-spoofing controls in external mail systems blocking emails.';
Expand All @@ -46,4 +46,4 @@
$string['smtpmaxbulk'] = 'SMTP session limit';
$string['smtppass'] = 'SMTP password';
$string['smtpsecure'] = 'SMTP security';
$string['smtpuser'] = 'SMTP username';
$string['smtpuser'] = 'SMTP username';
48 changes: 38 additions & 10 deletions message/output/email/message_output_email.php
Expand Up @@ -108,20 +108,45 @@ function send_message($eventdata) {
*/
function config_form($preferences){
global $USER, $OUTPUT, $CFG;

if (empty($CFG->messagingallowemailoverride)) {
return null;
$string = '';

$choices = array();
$choices['0'] = get_string('textformat');
$choices['1'] = get_string('htmlformat');
$current = $preferences->mailformat;
$string .= $OUTPUT->container(html_writer::label(get_string('emailformat'), 'mailformat'));
$string .= $OUTPUT->container(html_writer::select($choices, 'mailformat', $current, false, array('id' => 'mailformat')));

if (!empty($CFG->allowusermailcharset)) {
$choices = array();
$charsets = get_list_of_charsets();
if (!empty($CFG->sitemailcharset)) {
$choices['0'] = get_string('site').' ('.$CFG->sitemailcharset.')';
} else {
$choices['0'] = get_string('site').' (UTF-8)';
}
$choices = array_merge($choices, $charsets);
$current = $preferences->mailcharset;
$string .= $OUTPUT->container(html_writer::label(get_string('emailcharset'), 'mailcharset'));
$string .= $OUTPUT->container(
html_writer::select($choices, 'preference_mailcharset', $current, false, array('id' => 'mailcharset'))
);
}

$inputattributes = array('size'=>'30', 'name'=>'email_email', 'value'=>$preferences->email_email);
$string = get_string('email','message_email') . ': ' . html_writer::empty_tag('input', $inputattributes);
if (!empty($CFG->messagingallowemailoverride)) {
$inputattributes = array('size'=>'30', 'name'=>'email_email', 'value'=>$preferences->email_email, 'id'=>'email_email');
$string .= html_writer::label(get_string('email','message_email'), 'email_email');
$string .= $OUTPUT->container(html_writer::empty_tag('input', $inputattributes));

if (empty($preferences->email_email) && !empty($preferences->userdefaultemail)) {
$string .= get_string('ifemailleftempty', 'message_email', $preferences->userdefaultemail);
}
if (empty($preferences->email_email) && !empty($preferences->userdefaultemail)) {
$string .= $OUTPUT->container(get_string('ifemailleftempty', 'message_email', $preferences->userdefaultemail));
}

if (!empty($preferences->email_email) && !validate_email($preferences->email_email)) {
$string .= $OUTPUT->container(get_string('invalidemail'), 'error');
}

if (!empty($preferences->email_email) && !validate_email($preferences->email_email)) {
$string .= $OUTPUT->container(get_string('invalidemail'), 'error');
$string .= '<br/>';
}

return $string;
Expand All @@ -137,6 +162,9 @@ function process_form($form, &$preferences){
if (isset($form->email_email)) {
$preferences['message_processor_email_email'] = $form->email_email;
}
if (isset($form->preference_mailcharset)) {
$preferences['mailcharset'] = $form->preference_mailcharset;
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion user/edit.php
Expand Up @@ -284,7 +284,7 @@
}

if (!$emailchanged || !$CFG->emailchangeconfirmation) {
redirect("$CFG->wwwroot/user/preferences.php?id=$user->id&course=$course->id");
redirect("$CFG->wwwroot/user/preferences.php?userid=$user->id");
}
}

Expand Down
10 changes: 0 additions & 10 deletions user/edit_form.php
Expand Up @@ -99,16 +99,6 @@ public function definition_after_data() {
$mform = $this->_form;
$userid = $mform->getElementValue('id');

// If language does not exist, use site default lang.
if ($langsel = $mform->getElementValue('lang')) {
$lang = reset($langsel);
// Check lang exists.
if (!get_string_manager()->translation_exists($lang, false)) {
$langel =& $mform->getElement('lang');
$langel->setValue($CFG->lang);
}
}

if ($user = $DB->get_record('user', array('id' => $userid))) {

// Remove description.
Expand Down
10 changes: 0 additions & 10 deletions user/editadvanced_form.php
Expand Up @@ -146,16 +146,6 @@ public function definition_after_data() {
$user = false;
}

// If language does not exist, use site default lang.
if ($langsel = $mform->getElementValue('lang')) {
$lang = reset($langsel);
// Check lang exists.
if (!get_string_manager()->translation_exists($lang, false)) {
$langel =& $mform->getElement('lang');
$langel->setValue($CFG->lang);
}
}

// User can not change own auth method.
if ($userid == $USER->id) {
$mform->hardFreeze('auth');
Expand Down
103 changes: 100 additions & 3 deletions user/editlib.php
Expand Up @@ -33,6 +33,99 @@ function cancel_email_update($userid) {
unset_user_preference('newemailattemptsleft', $userid);
}

/**
* Performs the common access checks and page setup for all
* user preference pages.
*
* @param int $userid The user id to edit taken from the page params.
* @param int $courseid The optional course id if we came from a course context.
* @return array containing the user and course records.
*/
function useredit_setup_preference_page($userid, $courseid) {
global $PAGE, $SESSION, $DB, $CFG, $OUTPUT, $USER;

// Guest can not edit.
if (isguestuser()) {
print_error('guestnoeditprofile');
}

if (!$course = $DB->get_record('course', array('id' => $courseid))) {
print_error('invalidcourseid');
}

if ($course->id != SITEID) {
require_login($course);
} else if (!isloggedin()) {
if (empty($SESSION->wantsurl)) {
$SESSION->wantsurl = $CFG->httpswwwroot.'/user/preferences.php';
}
redirect(get_login_url());
} else {
$PAGE->set_context(context_system::instance());
}

// The user profile we are editing.
if (!$user = $DB->get_record('user', array('id' => $userid))) {
print_error('invaliduserid');
}

// Guest can not be edited.
if (isguestuser($user)) {
print_error('guestnoeditprofile');
}

// Remote users cannot be edited.
if (is_mnet_remote_user($user)) {
if (user_not_fully_set_up($user)) {
$hostwwwroot = $DB->get_field('mnet_host', 'wwwroot', array('id' => $user->mnethostid));
print_error('usernotfullysetup', 'mnet', '', $hostwwwroot);
}
redirect($CFG->wwwroot . "/user/view.php?course={$course->id}");
}

$systemcontext = context_system::instance();
$personalcontext = context_user::instance($user->id);

// Check access control.
if ($user->id == $USER->id) {
// Editing own profile - require_login() MUST NOT be used here, it would result in infinite loop!
if (!has_capability('moodle/user:editownprofile', $systemcontext)) {
print_error('cannotedityourprofile');
}

} else {
// Teachers, parents, etc.
require_capability('moodle/user:editprofile', $personalcontext);
// No editing of guest user account.
if (isguestuser($user->id)) {
print_error('guestnoeditprofileother');
}
// No editing of primary admin!
if (is_siteadmin($user) and !is_siteadmin($USER)) { // Only admins may edit other admins.
print_error('useradmineditadmin');
}
}

if ($user->deleted) {
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('userdeleted'));
echo $OUTPUT->footer();
die;
}

$PAGE->set_pagelayout('admin');
$PAGE->set_context($personalcontext);
if ($USER->id != $user->id) {
$PAGE->navigation->extend_for_user($user);
} else {
if ($node = $PAGE->navigation->find('myprofile', navigation_node::TYPE_ROOTNODE)) {
$node->force_open();
}
}

return array($user, $course);
}

/**
* Loads the given users preferences into the given user object.
*
Expand Down Expand Up @@ -220,6 +313,13 @@ function useredit_shared_definition(&$mform, $editoroptions, $filemanageroptions
$mform->setType('email', PARAM_RAW_TRIMMED);
}

$choices = array();
$choices['0'] = get_string('emaildisplayno');
$choices['1'] = get_string('emaildisplayyes');
$choices['2'] = get_string('emaildisplaycourse');
$mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices);
$mform->setDefault('maildisplay', $CFG->defaultpreference_maildisplay);

$mform->addElement('text', 'city', get_string('city'), 'maxlength="120" size="21"');
$mform->setType('city', PARAM_TEXT);
if (!empty($CFG->defaultcity)) {
Expand Down Expand Up @@ -267,9 +367,6 @@ function useredit_shared_definition(&$mform, $editoroptions, $filemanageroptions
$mform->setType('description_editor', PARAM_CLEANHTML);
$mform->addHelpButton('description_editor', 'userdescription');

$mform->addElement('header', 'moodle_userpreferences', get_string('preferences'));
useredit_shared_definition_preferences($user, $mform, $editoroptions, $filemanageroptions);

if (empty($USER->newadminuser)) {
$mform->addElement('header', 'moodle_picture', get_string('pictureofuser'));

Expand Down

0 comments on commit 479fa47

Please sign in to comment.