Datasets:

Modalities:
Text
Formats:
json
Languages:
code
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
File size: 4,306 Bytes
eb67da4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// 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:
        type: "POST",
        url: get_url(action.method),
        data: pdata,
        success: function(data){
            var text = _.template(action.success_msg, {interpolate: /\{(.+?)\}/g})(
                {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_string(action.locationName)).html(html);

        },
        dataType: 'json'
    });
  };

  reset = function(locname, location){
    this.do_idash_action({
        locationName: locname,
        location: location,
        method: 'reset_student_attempts',
        success_msg: gettext('Successfully reset the attempts for user {user}'),
        error_msg: gettext('Failed to reset attempts.'),
        delete_module: false
    });
  };

  sdelete = function(locname, location){
    this.do_idash_action({
        locationName: locname,
        location: location,
        method: 'reset_student_attempts',
        success_msg: gettext('Successfully deleted student state for user {user}'),
        error_msg: gettext('Failed to delete student state.'),
        delete_module: true
    });
  };

  rescore = function(locname, location){
    this.do_idash_action({
        locationName: locname,
        location: location,
        method: 'rescore_problem',
        success_msg: gettext('Successfully rescored problem for user {user}'),
        error_msg: gettext('Failed to rescore problem.'),
        delete_module: false
    });
  };

  return {
      reset: reset,
      sdelete: sdelete,
      rescore: rescore,
      do_idash_action: do_idash_action,
      get_current_url: get_current_url,
      get_url: get_url,
      get_user: get_user,
      sanitized_string:sanitized_string
  }; })();

// Register click handlers
$(document).ready(function() {

    var $courseContent = $('.course-content');
    $courseContent.on("click", '.staff-debug-reset', function() {
        StaffDebug.reset($(this).parent().data('location-name'), $(this).parent().data('location'));
        return false;
    });
    $courseContent.on("click", '.staff-debug-sdelete', function() {
        StaffDebug.sdelete($(this).parent().data('location-name'), $(this).parent().data('location'));
        return false;
    });
    $courseContent.on("click", '.staff-debug-rescore', function() {
        StaffDebug.rescore($(this).parent().data('location-name'), $(this).parent().data('location'));
        return false;
    });
});