Description:
allow ta to set model submission
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r856:9a927c70d5aa - - 4 files changed: 13 inserted, 10 deleted

@@ -87,97 +87,97
87 87 false
88 88 end
89 89 end
90 90
91 91 def login_with_name
92 92 "[#{login}] #{full_name}"
93 93 end
94 94
95 95 def authenticated_by_cucas?(password)
96 96 url = URI.parse('https://www.cas.chula.ac.th/cas/api/?q=studentAuthenticate')
97 97 appid = '41508763e340d5858c00f8c1a0f5a2bb'
98 98 appsecret ='d9cbb5863091dbe186fded85722a1e31'
99 99 post_args = {
100 100 'appid' => appid,
101 101 'appsecret' => appsecret,
102 102 'username' => login,
103 103 'password' => password
104 104 }
105 105
106 106 #simple call
107 107 begin
108 108 http = Net::HTTP.new('www.cas.chula.ac.th', 443)
109 109 http.use_ssl = true
110 110 http.verify_mode = OpenSSL::SSL::VERIFY_NONE
111 111 result = [ ]
112 112 http.start do |http|
113 113 req = Net::HTTP::Post.new('/cas/api/?q=studentAuthenticate')
114 114 #req = Net::HTTP::Post.new('/appX/prod/?q=studentAuthenticate')
115 115 #req = Net::HTTP::Post.new('/app2/prod/api/?q=studentAuthenticate')
116 116 param = "appid=#{appid}&appsecret=#{appsecret}&username=#{login}&password=#{password}"
117 117 resp = http.request(req,param)
118 118 result = JSON.parse resp.body
119 119 puts result
120 120 end
121 121 return true if result["type"] == "beanStudent"
122 122 rescue => e
123 123 puts e
124 124 puts e.message
125 125 return false
126 126 end
127 127 return false
128 128 end
129 129
130 130 def admin?
131 131 has_role?('admin')
132 132 end
133 133
134 134 def has_role?(role)
135 - self.roles.where(name: role).count > 0
135 + self.roles.where(name: [role,'admin']).count > 0
136 136 end
137 137
138 138 def email_for_editing
139 139 if self.email==nil
140 140 "(unknown)"
141 141 elsif self.email==''
142 142 "(blank)"
143 143 else
144 144 self.email
145 145 end
146 146 end
147 147
148 148 def email_for_editing=(e)
149 149 self.email=e
150 150 end
151 151
152 152 def alias_for_editing
153 153 if self.alias==nil
154 154 "(unknown)"
155 155 elsif self.alias==''
156 156 "(blank)"
157 157 else
158 158 self.alias
159 159 end
160 160 end
161 161
162 162 def alias_for_editing=(e)
163 163 self.alias=e
164 164 end
165 165
166 166 def activation_key
167 167 if self.hashed_password==nil
168 168 encrypt_new_password
169 169 end
170 170 Digest::SHA1.hexdigest(self.hashed_password)[0..7]
171 171 end
172 172
173 173 def verify_activation_key(key)
174 174 key == activation_key
175 175 end
176 176
177 177 def self.random_password(length=5)
178 178 chars = 'abcdefghjkmnopqrstuvwxyz'
179 179 password = ''
180 180 length.times { password << chars[rand(chars.length - 1)] }
181 181 password
182 182 end
183 183
@@ -9,102 +9,104
9 9 text-align: left;
10 10 font-size: 1.0em;
11 11 color: black;
12 12 line-height: 1.1;
13 13 display: none;
14 14 min-width: 20em;
15 15 position: absolute;
16 16 left: 25px;
17 17 bottom: 5px;
18 18 border: 1px solid;
19 19 padding: 5px;
20 20 background-color: #FFF;
21 21 word-wrap: break-word;
22 22 z-index: 9999;
23 23 overflow: auto;
24 24 }
25 25
26 26
27 27 .container-fluid
28 28 .row
29 29 .col-md-8
30 30 .card
31 31 .card-body
32 32 %h2.card-title Submission History
33 33 %canvas#chart{height: '50px'}
34 34
35 35 .col-md-4
36 36 .card
37 37 .card-body
38 38 %h2.card-title General Info
39 39 .row
40 40 .col-sm-6
41 41 Subs
42 42 .col-sm-6
43 43 = @summary[:count]
44 44 .row
45 45 .col-sm-6
46 46 Solved/Attempted User
47 47 .col-sm-6
48 48 #{@summary[:solve]}/#{@summary[:attempt]} (#{(@summary[:solve]*100.0/@summary[:attempt]).round(1)}%)
49 49 .row
50 50 .col-md-4
51 51 .card
52 52 .card-body
53 53 %h2.card-title Model submission
54 54 %table.table.table-hover
55 55 %thead
56 56 %tr
57 - %th #Sub
57 + %th #Sub (lang)
58 58 %th Author
59 59 %tbody
60 60 - @model_subs.each do |sub|
61 61 %tr
62 - %td= link_to "##{sub.id}", submission_path(sub)
62 + %td
63 + = link_to "##{sub.id}", submission_path(sub)
64 + = "(#{sub.language.pretty_name})"
63 65 %td= sub.user.full_name
64 66 .col-md-8
65 67 - if @best
66 68 .card
67 69 .card-body
68 70 %h2.card-title Top Submissions
69 71 %table.table.table-hover
70 72 %thead
71 73 %tr
72 74 %th Language
73 75 %th Best runtime (ms)
74 76 %th Best memory (kbytes)
75 77 %th Shortest Code (bytes)
76 78 %th First solver
77 79 %tbody
78 80 %tr.bg-warning
79 81 %td
80 82 Overall
81 83 %td
82 84 by #{link_to @best[:runtime][:user], stat_user_path(@best[:runtime][:user_id])}
83 85 %br
84 86 using <span class="text-success">#{@best[:runtime][:lang]}</span>
85 87 %br
86 88 with <span class="text-success">#{@best[:runtime][:value] * 1000} milliseconds</span>
87 89 %br= link_to "#" + @best[:runtime][:sub_id].to_s, submission_path(@best[:runtime][:sub_id])
88 90 %td
89 91 by #{link_to @best[:memory][:user], stat_user_path(@best[:memory][:user_id])}
90 92 %br
91 93 using <span class="text-success">#{@best[:memory][:lang]}</span>
92 94 %br
93 95 with <span class="text-success">#{number_with_delimiter(@best[:memory][:value])} kbytes </span>
94 96 %br= link_to "#" + @best[:memory][:sub_id].to_s, submission_path(@best[:memory][:sub_id])
95 97 %td
96 98 by #{link_to @best[:length][:user], stat_user_path(@best[:length][:user_id])}
97 99 %br
98 100 using <span class="text-success">#{@best[:length][:lang]}</span>
99 101 %br
100 102 with <span class="text-success">#{@best[:length][:value]} bytes</span>
101 103 %br= link_to "#" + @best[:length][:sub_id].to_s, submission_path(@best[:length][:sub_id])
102 104 %td
103 105 - if @best[:first][:user] != '(NULL)'
104 106 #{link_to @best[:first][:user], stat_user_path(@best[:first][:user_id])} is the first solver
105 107 %br
106 108 using <span class="text-success">#{@best[:first][:lang]}</span>
107 109 %br
108 110 on <span class="text-success">#{@best[:first][:value]}</span>
109 111 %br= link_to "#" + @best[:first][:sub_id].to_s, submission_path( @best[:first][:sub_id])
110 112 - else
@@ -1,29 +1,30
1 1
2 2 /- if params[:id]
3 3 / %h1 Tasks Hall of Fame
4 4 / = link_to('[back to All-Time Hall of Fame]', action: 'problem_hof', id: nil )
5 5 /- else
6 6 / %h1 All-Time Hall of Fame
7 7
8 8 .panel.panel-info
9 9 .panel-heading
10 10 Select Task
11 11 .panel-body
12 12 .form-inline
13 13 = select 'report',
14 14 'problem_id',
15 15 @problems.collect {|p| ["[#{p.name}] #{p.full_name}", problem_hof_report_path(p)]},
16 16 {:selected => problem_hof_report_path(@problem)},
17 17 { class: 'select2 form-control' }
18 18 %button.btn.btn-primary.btn-sm.go-button#problem_go{data: {source: "#report_problem_id"}} Go
19 19
20 20
21 21 - unless params[:id]
22 22 /=render partial: 'all_time_hof'
23 23 Please select a problem.
24 24 - else
25 - %h1 [#{Problem.find(params[:id]).name}] #{Problem.find(params[:id]).full_name}
26 - -# %h2 Submission History
27 - -# =render partial: 'application/bar_graph', locals: { histogram: @histogram }
25 + %h1
26 + [#{Problem.find(params[:id]).name}] #{Problem.find(params[:id]).full_name}
27 + - if @current_user.has_role?('ta')
28 + %a{href:stat_problem_path(@problem)} (stat)
28 29 =render partial: 'task_hof'
29 30
@@ -49,80 +49,80
49 49 - else
50 50 = "(n/a)"
51 51 %tr
52 52 %td.text-right
53 53 %strong Tries
54 54 %td= @submission.number
55 55 %tr
56 56 %td.text-right
57 57 %strong Language
58 58 %td= @submission.language.pretty_name
59 59 %tr
60 60 %td.text-right
61 61 %strong Submitted
62 62 %td #{time_ago_in_words(@submission.submitted_at)} ago (at #{@submission.submitted_at.to_formatted_s(:long)})
63 63 %tr
64 64 %td.text-right
65 65 %strong Graded
66 66 - if @submission.graded_at
67 67 %td #{time_ago_in_words(@submission.graded_at)} ago (at #{@submission.graded_at.to_formatted_s(:long)})
68 68 - else
69 69 %td -
70 70 %tr
71 71 %td.text-right
72 72 %strong Points
73 73 %td #{@submission.points}/#{@submission.try(:problem).try(:full_score)}
74 74 %tr
75 75 %td.text-right
76 76 %strong Comment
77 77 %td #{@submission.grader_comment}
78 78 %tr
79 79 %td.text-right
80 80 %strong Runtime (s)
81 81 %td #{@submission.max_runtime}
82 82 %tr
83 83 %td.text-right
84 84 %strong Memory (kb)
85 85 %td #{@submission.peak_memory}
86 86 %tr
87 87 %td.text-right
88 88 %strong Compiler result
89 89 %td
90 90 %button.btn.btn-info.btn-xs{type: 'button', data: {toggle: 'modal', target: '#compiler'}}
91 91 view
92 92 %tr
93 93 %td.text-right
94 94 %strong Grading Task Status
95 95 %td
96 96 = @task.status_str if @task
97 - - if session[:admin]
97 + - if @current_user.admin?
98 98 = link_to "rejudge", rejudge_submission_path, data: {remote: true}, class: 'btn btn-info btn-xs'
99 - - if session[:admin]
99 + - if @current_user.has_role?('ta')
100 100 %tr
101 101 %td.text-right
102 102 %strong IP
103 103 %td #{@submission.ip_address}
104 104 %tr
105 105 %td.text-right
106 106 %strong Model solution
107 107 %td
108 108 - if @submission.tag_model?
109 109 YES
110 - - if session[:admin]
110 + - if @current_user.has_role?('ta')
111 111 = link_to "remove model status", set_tag_submission_path(@submission, tag: :default), class: 'btn btn-warning btn-xs'
112 112 - else
113 113 No
114 - - if session[:admin]
114 + - if @current_user.has_role?('ta')
115 115 = link_to "set as model solution", set_tag_submission_path(@submission, tag: :model), class: 'btn btn-success btn-xs'
116 116
117 117
118 118 .modal.fade#compiler{tabindex: -1,role: 'dialog'}
119 119 .modal-dialog.modal-lg{role:'document'}
120 120 .modal-content
121 121 .modal-header
122 122 %button.close{type: 'button', data: {dismissed: :modal}, aria: {label: 'close'}}
123 123 %span{aria: {hidden: 'true'}, data: {dismiss: 'modal'}} &times;
124 124 %h4 Compiler message
125 125 .modal-body
126 126 %pre#compiler_msg= @submission.compiler_message
127 127 .modal-footer
128 128 %button.btn.btn-default{type: 'button', data: {dismiss: 'modal'}} Close
You need to be logged in to leave comments. Login now