Moodle

Allow JavaScript to set user preferences

Details

  • Type: Sub-task Sub-task
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 2.0
  • Fix Version/s: 2.0
  • Component/s: AJAX
  • Labels:
    None
  • Affected Branches:
    MOODLE_20_STABLE
  • Fixed Branches:
    MOODLE_20_STABLE

Description

Sometimes JavaScript will need to set user preferences, for example to remember whether the user likes certain things collapsed or expanded. To this end, I propose a new script:

.../lib/ajax/setuserpref.php?sesskey=XXXX&pref=[prefname]&value=[value]

To avoid security problems, this scrip will only process an update if you have previously called a PHP function

user_preference_allow_ajax_update($name, PARAM_XXX);

This sets $USER->ajax_updatable_user_prefs[$name] = PARAM_XXX;

and sesskey will only update user preferences where the appropriate key is set in the session, and it will clean the value as specified there before doing the update.

Activity

Hide
Tim Hunt added a comment -

I will also write a JavaScript function set_user_preference(name, value) in javascript_static.js.

Show
Tim Hunt added a comment - I will also write a JavaScript function set_user_preference(name, value) in javascript_static.js.
Hide
Tim Hunt added a comment -

Petr, I would be grateful if, when you have a moment, you could give this a security review. Thanks.

Show
Tim Hunt added a comment - Petr, I would be grateful if, when you have a moment, you could give this a security review. Thanks.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: