<fim-prefix>// Build StaffDebug object
var StaffDebug = (function (){

  get_current_url = function() {
    return window.location.pathname;
  };

  get_url = function(action){
    var pathname = this.get_current_url();
    var url = pathname.substr(0,pathname.indexOf('/courseware')) + '/instructor/api/' + action;
    return url;
  };

  sanitized_string = function(string) {
    return string.replace(/[.*+?^:${}()|[\]\\]/g, "\\$&");
  };

  get_user = function(locname){
    locname = sanitized_string(locname);
    var uname = $('#sd_fu_' + locname).val();
    if (uname===""){
        uname =  $('#sd_fu_' + locname).attr('placeholder');
    }
    return uname;
  };

  do_idash_action = function(action){
    var pdata = {
        'problem_to_reset': action.location,
        'unique_student_identifier': get_user(action.locationName),
        'delete_module': action.delete_module
    };
    $.ajax({
        // BUG: CWE-352 Cross-Site Request Forgery (CSRF)
        // type: "GET",
        // FIXED:
 <fim-middle>       type: "POST",
        url: get_url(action.method),
        data: pdata,
        success: function(data){
            var text = _.template(action.success_msg, {interpolate: /\{(.+?)\}/g})(
     <fix-suffix>           {user: data.student}
            );
            var html = _.template('<p id="idash_msg" class="success">{text}</p>', {interpolate: /\{(.+?)\}/g})(
                {text: text}
            );
            $("#result_"+sanitized_string(action.locationName)).html(html);
        },
        error: function(request, status, error) {
            var response_json;
            try {
                response_json = $.parseJSON(request.responseText);
            } catch(e) {
                response_json = { error: gettext('Unknown Error Occurred.') };
            }
            var text = _.template('{error_msg} {error}', {interpolate: /\{(.+?)\}/g})(
                {
                    error_msg: action.error_msg,
                    error: response_json.error
                }
            );
            var html = _.template('<p id="idash_msg" class="error">{text}</p>', {interpolate: /\{(.+?)\}/g})(
                {text: text}
            );
            $("#result_"+sanitized_str<|endoftext|>