Description:
- change user_admin default action from list to index
- remove duplicate button in grader control
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r588:8bdb0ec71018 - - 4 files changed: 21 inserted, 23 deleted
@@ -1,122 +1,123 | |||
|
1 | 1 | class GradersController < ApplicationController |
|
2 | 2 | |
|
3 | 3 | before_filter :admin_authorization, except: [ :submission ] |
|
4 | 4 | before_filter(only: [:submission]) { |
|
5 | 5 | return false unless authenticate |
|
6 | 6 | |
|
7 | 7 | if GraderConfiguration["right.user_view_submission"] |
|
8 | 8 | return true; |
|
9 | 9 | end |
|
10 | 10 | |
|
11 | 11 | admin_authorization |
|
12 | 12 | } |
|
13 | 13 | |
|
14 | 14 | verify :method => :post, :only => ['clear_all', |
|
15 | 15 | 'start_exam', |
|
16 | 16 | 'start_grading', |
|
17 | 17 | 'stop_all', |
|
18 | 18 | 'clear_terminated'], |
|
19 | 19 | :redirect_to => {:action => 'index'} |
|
20 | 20 | |
|
21 | 21 | def index |
|
22 | 22 | redirect_to :action => 'list' |
|
23 | 23 | end |
|
24 | 24 | |
|
25 | 25 | def list |
|
26 | 26 | @grader_processes = GraderProcess.find_running_graders |
|
27 | 27 | @stalled_processes = GraderProcess.find_stalled_process |
|
28 | 28 | |
|
29 | 29 | @terminated_processes = GraderProcess.find_terminated_graders |
|
30 | 30 | |
|
31 | 31 | @last_task = Task.find(:first, |
|
32 | 32 | :order => 'created_at DESC') |
|
33 | 33 | @last_test_request = TestRequest.find(:first, |
|
34 | 34 | :order => 'created_at DESC') |
|
35 | 35 | @submission = Submission.order("id desc").limit(20) |
|
36 | + @backlog_submission = Submission.where('graded_at is null') | |
|
36 | 37 | end |
|
37 | 38 | |
|
38 | 39 | def clear |
|
39 | 40 | grader_proc = GraderProcess.find(params[:id]) |
|
40 | 41 | grader_proc.destroy if grader_proc!=nil |
|
41 | 42 | redirect_to :action => 'list' |
|
42 | 43 | end |
|
43 | 44 | |
|
44 | 45 | def clear_terminated |
|
45 | 46 | GraderProcess.find_terminated_graders.each do |p| |
|
46 | 47 | p.destroy |
|
47 | 48 | end |
|
48 | 49 | redirect_to :action => 'list' |
|
49 | 50 | end |
|
50 | 51 | |
|
51 | 52 | def clear_all |
|
52 | 53 | GraderProcess.find(:all).each do |p| |
|
53 | 54 | p.destroy |
|
54 | 55 | end |
|
55 | 56 | redirect_to :action => 'list' |
|
56 | 57 | end |
|
57 | 58 | |
|
58 | 59 | def view |
|
59 | 60 | if params[:type]=='Task' |
|
60 | 61 | redirect_to :action => 'task', :id => params[:id] |
|
61 | 62 | else |
|
62 | 63 | redirect_to :action => 'test_request', :id => params[:id] |
|
63 | 64 | end |
|
64 | 65 | end |
|
65 | 66 | |
|
66 | 67 | def test_request |
|
67 | 68 | @test_request = TestRequest.find(params[:id]) |
|
68 | 69 | end |
|
69 | 70 | |
|
70 | 71 | def task |
|
71 | 72 | @task = Task.find(params[:id]) |
|
72 | 73 | end |
|
73 | 74 | |
|
74 | 75 | def submission |
|
75 | 76 | @submission = Submission.find(params[:id]) |
|
76 | 77 | formatter = Rouge::Formatters::HTML.new(css_class: 'highlight', line_numbers: true ) |
|
77 | 78 | lexer = case @submission.language.name |
|
78 | 79 | when "c" then Rouge::Lexers::C.new |
|
79 | 80 | when "cpp" then Rouge::Lexers::Cpp.new |
|
80 | 81 | when "pas" then Rouge::Lexers::Pas.new |
|
81 | 82 | when "ruby" then Rouge::Lexers::Ruby.new |
|
82 | 83 | when "python" then Rouge::Lexers::Python.new |
|
83 | 84 | when "java" then Rouge::Lexers::Java.new |
|
84 | 85 | when "php" then Rouge::Lexers::PHP.new |
|
85 | 86 | end |
|
86 | 87 | @formatted_code = formatter.format(lexer.lex(@submission.source)) |
|
87 | 88 | @css_style = Rouge::Themes::ThankfulEyes.render(scope: '.highlight') |
|
88 | 89 | |
|
89 | 90 | user = User.find(session[:user_id]) |
|
90 | 91 | SubmissionViewLog.create(user_id: session[:user_id],submission_id: @submission.id) unless user.admin? |
|
91 | 92 | |
|
92 | 93 | end |
|
93 | 94 | |
|
94 | 95 | # various grader controls |
|
95 | 96 | |
|
96 | 97 | def stop |
|
97 | 98 | grader_proc = GraderProcess.find(params[:id]) |
|
98 | 99 | GraderScript.stop_grader(grader_proc.pid) |
|
99 | 100 | flash[:notice] = 'Grader stopped. It may not disappear now, but it should disappear shortly.' |
|
100 | 101 | redirect_to :action => 'list' |
|
101 | 102 | end |
|
102 | 103 | |
|
103 | 104 | def stop_all |
|
104 | 105 | GraderScript.stop_graders(GraderProcess.find_running_graders + |
|
105 | 106 | GraderProcess.find_stalled_process) |
|
106 | 107 | flash[:notice] = 'Graders stopped. They may not disappear now, but they should disappear shortly.' |
|
107 | 108 | redirect_to :action => 'list' |
|
108 | 109 | end |
|
109 | 110 | |
|
110 | 111 | def start_grading |
|
111 | 112 | GraderScript.start_grader('grading') |
|
112 | 113 | flash[:notice] = '2 graders in grading env started, one for grading queue tasks, another for grading test request' |
|
113 | 114 | redirect_to :action => 'list' |
|
114 | 115 | end |
|
115 | 116 | |
|
116 | 117 | def start_exam |
|
117 | 118 | GraderScript.start_grader('exam') |
|
118 | 119 | flash[:notice] = '2 graders in grading env started, one for grading queue tasks, another for grading test request' |
|
119 | 120 | redirect_to :action => 'list' |
|
120 | 121 | end |
|
121 | 122 | |
|
122 | 123 | end |
@@ -1,407 +1,402 | |||
|
1 | 1 | require 'csv' |
|
2 | 2 | |
|
3 | 3 | class UserAdminController < ApplicationController |
|
4 | 4 | |
|
5 | 5 | include MailHelperMethods |
|
6 | 6 | |
|
7 | 7 | before_filter :admin_authorization |
|
8 | 8 | |
|
9 | 9 | # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) |
|
10 | 10 | verify :method => :post, :only => [ :destroy, |
|
11 | 11 | :create, :create_from_list, |
|
12 | 12 | :update, |
|
13 | 13 | :manage_contest, |
|
14 | 14 | :bulk_mail |
|
15 | 15 | ], |
|
16 | 16 | :redirect_to => { :action => :list } |
|
17 | 17 | |
|
18 | 18 | def index |
|
19 | - list | |
|
20 | - render :action => 'list' | |
|
21 | - end | |
|
22 | - | |
|
23 | - def list | |
|
24 | 19 | @user_count = User.count |
|
25 | 20 | if params[:page] == 'all' |
|
26 | 21 | @users = User.all |
|
27 | 22 | @paginated = false |
|
28 | 23 | else |
|
29 | 24 | @users = User.paginate :page => params[:page] |
|
30 | 25 | @paginated = true |
|
31 | 26 | end |
|
32 | 27 | @hidden_columns = ['hashed_password', 'salt', 'created_at', 'updated_at'] |
|
33 | 28 | @contests = Contest.enabled |
|
34 | 29 | end |
|
35 | 30 | |
|
36 | 31 | def active |
|
37 | 32 | sessions = ActiveRecord::SessionStore::Session.find(:all, :conditions => ["updated_at >= ?", 60.minutes.ago]) |
|
38 | 33 | @users = [] |
|
39 | 34 | sessions.each do |session| |
|
40 | 35 | if session.data[:user_id] |
|
41 | 36 | @users << User.find(session.data[:user_id]) |
|
42 | 37 | end |
|
43 | 38 | end |
|
44 | 39 | end |
|
45 | 40 | |
|
46 | 41 | def show |
|
47 | 42 | @user = User.find(params[:id]) |
|
48 | 43 | end |
|
49 | 44 | |
|
50 | 45 | def new |
|
51 | 46 | @user = User.new |
|
52 | 47 | end |
|
53 | 48 | |
|
54 | 49 | def create |
|
55 | 50 | @user = User.new(params[:user]) |
|
56 | 51 | @user.activated = true |
|
57 | 52 | if @user.save |
|
58 | 53 | flash[:notice] = 'User was successfully created.' |
|
59 | 54 | redirect_to :action => 'index' |
|
60 | 55 | else |
|
61 | 56 | render :action => 'new' |
|
62 | 57 | end |
|
63 | 58 | end |
|
64 | 59 | |
|
65 | 60 | def clear_last_ip |
|
66 | 61 | @user = User.find(params[:id]) |
|
67 | 62 | @user.last_ip = nil |
|
68 | 63 | @user.save |
|
69 | 64 | redirect_to action: 'index', page: params[:page] |
|
70 | 65 | end |
|
71 | 66 | |
|
72 | 67 | def create_from_list |
|
73 | 68 | lines = params[:user_list] |
|
74 | 69 | |
|
75 | 70 | note = [] |
|
76 | 71 | |
|
77 | 72 | lines.split("\n").each do |line| |
|
78 | 73 | items = line.chomp.split(',') |
|
79 | 74 | if items.length>=2 |
|
80 | 75 | login = items[0] |
|
81 | 76 | full_name = items[1] |
|
82 | 77 | |
|
83 | 78 | added_random_password = false |
|
84 | 79 | if items.length>=3 |
|
85 | 80 | password = items[2].chomp(" ") |
|
86 | 81 | user_alias = (items.length>=4) ? items[3] : login |
|
87 | 82 | else |
|
88 | 83 | password = random_password |
|
89 | 84 | user_alias = (items.length>=4) ? items[3] : login |
|
90 | 85 | added_random_password = true |
|
91 | 86 | end |
|
92 | 87 | |
|
93 | 88 | user = User.find_by_login(login) |
|
94 | 89 | if (user) |
|
95 | 90 | user.full_name = full_name |
|
96 | 91 | user.password = password |
|
97 | 92 | else |
|
98 | 93 | user = User.new({:login => login, |
|
99 | 94 | :full_name => full_name, |
|
100 | 95 | :password => password, |
|
101 | 96 | :password_confirmation => password, |
|
102 | 97 | :alias => user_alias}) |
|
103 | 98 | end |
|
104 | 99 | user.activated = true |
|
105 | 100 | user.save |
|
106 | 101 | |
|
107 | 102 | if added_random_password |
|
108 | 103 | note << "'#{login}' (+)" |
|
109 | 104 | else |
|
110 | 105 | note << login |
|
111 | 106 | end |
|
112 | 107 | end |
|
113 | 108 | end |
|
114 | 109 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
115 | 110 | ' were successfully created. ' + |
|
116 | 111 | '( (+) - created with random passwords.)' |
|
117 | 112 | redirect_to :action => 'index' |
|
118 | 113 | end |
|
119 | 114 | |
|
120 | 115 | def edit |
|
121 | 116 | @user = User.find(params[:id]) |
|
122 | 117 | end |
|
123 | 118 | |
|
124 | 119 | def update |
|
125 | 120 | @user = User.find(params[:id]) |
|
126 | 121 | if @user.update_attributes(params[:user]) |
|
127 | 122 | flash[:notice] = 'User was successfully updated.' |
|
128 | 123 | redirect_to :action => 'show', :id => @user |
|
129 | 124 | else |
|
130 | 125 | render :action => 'edit' |
|
131 | 126 | end |
|
132 | 127 | end |
|
133 | 128 | |
|
134 | 129 | def destroy |
|
135 | 130 | User.find(params[:id]).destroy |
|
136 | 131 | redirect_to :action => 'index' |
|
137 | 132 | end |
|
138 | 133 | |
|
139 | 134 | def user_stat |
|
140 | 135 | if params[:commit] == 'download csv' |
|
141 | 136 | @problems = Problem.all |
|
142 | 137 | else |
|
143 | 138 | @problems = Problem.find_available_problems |
|
144 | 139 | end |
|
145 | 140 | @users = User.includes(:contests, :contest_stat).where(enabled: true) #find(:all, :include => [:contests, :contest_stat]).where(enabled: true) |
|
146 | 141 | @scorearray = Array.new |
|
147 | 142 | @users.each do |u| |
|
148 | 143 | ustat = Array.new |
|
149 | 144 | ustat[0] = u |
|
150 | 145 | @problems.each do |p| |
|
151 | 146 | sub = Submission.find_last_by_user_and_problem(u.id,p.id) |
|
152 | 147 | if (sub!=nil) and (sub.points!=nil) and p and p.full_score |
|
153 | 148 | ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)] |
|
154 | 149 | else |
|
155 | 150 | ustat << [0,false] |
|
156 | 151 | end |
|
157 | 152 | end |
|
158 | 153 | @scorearray << ustat |
|
159 | 154 | end |
|
160 | 155 | if params[:commit] == 'download csv' then |
|
161 | 156 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
162 | 157 | send_data csv, filename: 'last_score.csv' |
|
163 | 158 | else |
|
164 | 159 | render template: 'user_admin/user_stat' |
|
165 | 160 | end |
|
166 | 161 | end |
|
167 | 162 | |
|
168 | 163 | def user_stat_max |
|
169 | 164 | if params[:commit] == 'download csv' |
|
170 | 165 | @problems = Problem.all |
|
171 | 166 | else |
|
172 | 167 | @problems = Problem.find_available_problems |
|
173 | 168 | end |
|
174 | 169 | @users = User.find(:all, :include => [:contests, :contest_stat]) |
|
175 | 170 | @scorearray = Array.new |
|
176 | 171 | #set up range from param |
|
177 | 172 | since_id = params.fetch(:since_id, 0).to_i |
|
178 | 173 | until_id = params.fetch(:until_id, 0).to_i |
|
179 | 174 | @users.each do |u| |
|
180 | 175 | ustat = Array.new |
|
181 | 176 | ustat[0] = u |
|
182 | 177 | @problems.each do |p| |
|
183 | 178 | max_points = 0 |
|
184 | 179 | Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub| |
|
185 | 180 | max_points = sub.points if sub and sub.points and (sub.points > max_points) |
|
186 | 181 | end |
|
187 | 182 | ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)] |
|
188 | 183 | end |
|
189 | 184 | @scorearray << ustat |
|
190 | 185 | end |
|
191 | 186 | |
|
192 | 187 | if params[:commit] == 'download csv' then |
|
193 | 188 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
194 | 189 | send_data csv, filename: 'max_score.csv' |
|
195 | 190 | else |
|
196 | 191 | render template: 'user_admin/user_stat' |
|
197 | 192 | end |
|
198 | 193 | end |
|
199 | 194 | |
|
200 | 195 | def import |
|
201 | 196 | if params[:file]=='' |
|
202 | 197 | flash[:notice] = 'Error importing no file' |
|
203 | 198 | redirect_to :action => 'index' and return |
|
204 | 199 | end |
|
205 | 200 | import_from_file(params[:file]) |
|
206 | 201 | end |
|
207 | 202 | |
|
208 | 203 | def random_all_passwords |
|
209 | 204 | users = User.find(:all) |
|
210 | 205 | @prefix = params[:prefix] || '' |
|
211 | 206 | @non_admin_users = User.find_non_admin_with_prefix(@prefix) |
|
212 | 207 | @changed = false |
|
213 | 208 | if request.request_method == 'POST' |
|
214 | 209 | @non_admin_users.each do |user| |
|
215 | 210 | password = random_password |
|
216 | 211 | user.password = password |
|
217 | 212 | user.password_confirmation = password |
|
218 | 213 | user.save |
|
219 | 214 | end |
|
220 | 215 | @changed = true |
|
221 | 216 | end |
|
222 | 217 | end |
|
223 | 218 | |
|
224 | 219 | # contest management |
|
225 | 220 | |
|
226 | 221 | def contests |
|
227 | 222 | @contest, @users = find_contest_and_user_from_contest_id(params[:id]) |
|
228 | 223 | @contests = Contest.enabled |
|
229 | 224 | end |
|
230 | 225 | |
|
231 | 226 | def assign_from_list |
|
232 | 227 | contest_id = params[:users_contest_id] |
|
233 | 228 | org_contest, users = find_contest_and_user_from_contest_id(contest_id) |
|
234 | 229 | contest = Contest.find(params[:new_contest][:id]) |
|
235 | 230 | if !contest |
|
236 | 231 | flash[:notice] = 'Error: no contest' |
|
237 | 232 | redirect_to :action => 'contests', :id =>contest_id |
|
238 | 233 | end |
|
239 | 234 | |
|
240 | 235 | note = [] |
|
241 | 236 | users.each do |u| |
|
242 | 237 | u.contests = [contest] |
|
243 | 238 | note << u.login |
|
244 | 239 | end |
|
245 | 240 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
246 | 241 | " were successfully reassigned to #{contest.title}." |
|
247 | 242 | redirect_to :action => 'contests', :id =>contest.id |
|
248 | 243 | end |
|
249 | 244 | |
|
250 | 245 | def add_to_contest |
|
251 | 246 | user = User.find(params[:id]) |
|
252 | 247 | contest = Contest.find(params[:contest_id]) |
|
253 | 248 | if user and contest |
|
254 | 249 | user.contests << contest |
|
255 | 250 | end |
|
256 | 251 | redirect_to :action => 'index' |
|
257 | 252 | end |
|
258 | 253 | |
|
259 | 254 | def remove_from_contest |
|
260 | 255 | user = User.find(params[:id]) |
|
261 | 256 | contest = Contest.find(params[:contest_id]) |
|
262 | 257 | if user and contest |
|
263 | 258 | user.contests.delete(contest) |
|
264 | 259 | end |
|
265 | 260 | redirect_to :action => 'index' |
|
266 | 261 | end |
|
267 | 262 | |
|
268 | 263 | def contest_management |
|
269 | 264 | end |
|
270 | 265 | |
|
271 | 266 | def manage_contest |
|
272 | 267 | contest = Contest.find(params[:contest][:id]) |
|
273 | 268 | if !contest |
|
274 | 269 | flash[:notice] = 'You did not choose the contest.' |
|
275 | 270 | redirect_to :action => 'contest_management' and return |
|
276 | 271 | end |
|
277 | 272 | |
|
278 | 273 | operation = params[:operation] |
|
279 | 274 | |
|
280 | 275 | if not ['add','remove','assign'].include? operation |
|
281 | 276 | flash[:notice] = 'You did not choose the operation to perform.' |
|
282 | 277 | redirect_to :action => 'contest_management' and return |
|
283 | 278 | end |
|
284 | 279 | |
|
285 | 280 | lines = params[:login_list] |
|
286 | 281 | if !lines or lines.blank? |
|
287 | 282 | flash[:notice] = 'You entered an empty list.' |
|
288 | 283 | redirect_to :action => 'contest_management' and return |
|
289 | 284 | end |
|
290 | 285 | |
|
291 | 286 | note = [] |
|
292 | 287 | users = [] |
|
293 | 288 | lines.split("\n").each do |line| |
|
294 | 289 | user = User.find_by_login(line.chomp) |
|
295 | 290 | if user |
|
296 | 291 | if operation=='add' |
|
297 | 292 | if ! user.contests.include? contest |
|
298 | 293 | user.contests << contest |
|
299 | 294 | end |
|
300 | 295 | elsif operation=='remove' |
|
301 | 296 | user.contests.delete(contest) |
|
302 | 297 | else |
|
303 | 298 | user.contests = [contest] |
|
304 | 299 | end |
|
305 | 300 | |
|
306 | 301 | if params[:reset_timer] |
|
307 | 302 | user.contest_stat.forced_logout = true |
|
308 | 303 | user.contest_stat.reset_timer_and_save |
|
309 | 304 | end |
|
310 | 305 | |
|
311 | 306 | if params[:notification_emails] |
|
312 | 307 | send_contest_update_notification_email(user, contest) |
|
313 | 308 | end |
|
314 | 309 | |
|
315 | 310 | note << user.login |
|
316 | 311 | users << user |
|
317 | 312 | end |
|
318 | 313 | end |
|
319 | 314 | |
|
320 | 315 | if params[:reset_timer] |
|
321 | 316 | logout_users(users) |
|
322 | 317 | end |
|
323 | 318 | |
|
324 | 319 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
325 | 320 | ' were successfully modified. ' |
|
326 | 321 | redirect_to :action => 'contest_management' |
|
327 | 322 | end |
|
328 | 323 | |
|
329 | 324 | # admin management |
|
330 | 325 | |
|
331 | 326 | def admin |
|
332 | 327 | @admins = User.find(:all).find_all {|user| user.admin? } |
|
333 | 328 | end |
|
334 | 329 | |
|
335 | 330 | def grant_admin |
|
336 | 331 | login = params[:login] |
|
337 | 332 | user = User.find_by_login(login) |
|
338 | 333 | if user!=nil |
|
339 | 334 | admin_role = Role.find_by_name('admin') |
|
340 | 335 | user.roles << admin_role |
|
341 | 336 | else |
|
342 | 337 | flash[:notice] = 'Unknown user' |
|
343 | 338 | end |
|
344 | 339 | flash[:notice] = 'User added as admins' |
|
345 | 340 | redirect_to :action => 'admin' |
|
346 | 341 | end |
|
347 | 342 | |
|
348 | 343 | def revoke_admin |
|
349 | 344 | user = User.find(params[:id]) |
|
350 | 345 | if user==nil |
|
351 | 346 | flash[:notice] = 'Unknown user' |
|
352 | 347 | redirect_to :action => 'admin' and return |
|
353 | 348 | elsif user.login == 'root' |
|
354 | 349 | flash[:notice] = 'You cannot revoke admisnistrator permission from root.' |
|
355 | 350 | redirect_to :action => 'admin' and return |
|
356 | 351 | end |
|
357 | 352 | |
|
358 | 353 | admin_role = Role.find_by_name('admin') |
|
359 | 354 | user.roles.delete(admin_role) |
|
360 | 355 | flash[:notice] = 'User permission revoked' |
|
361 | 356 | redirect_to :action => 'admin' |
|
362 | 357 | end |
|
363 | 358 | |
|
364 | 359 | # mass mailing |
|
365 | 360 | |
|
366 | 361 | def mass_mailing |
|
367 | 362 | end |
|
368 | 363 | |
|
369 | 364 | def bulk_mail |
|
370 | 365 | lines = params[:login_list] |
|
371 | 366 | if !lines or lines.blank? |
|
372 | 367 | flash[:notice] = 'You entered an empty list.' |
|
373 | 368 | redirect_to :action => 'mass_mailing' and return |
|
374 | 369 | end |
|
375 | 370 | |
|
376 | 371 | mail_subject = params[:subject] |
|
377 | 372 | if !mail_subject or mail_subject.blank? |
|
378 | 373 | flash[:notice] = 'You entered an empty mail subject.' |
|
379 | 374 | redirect_to :action => 'mass_mailing' and return |
|
380 | 375 | end |
|
381 | 376 | |
|
382 | 377 | mail_body = params[:email_body] |
|
383 | 378 | if !mail_body or mail_body.blank? |
|
384 | 379 | flash[:notice] = 'You entered an empty mail body.' |
|
385 | 380 | redirect_to :action => 'mass_mailing' and return |
|
386 | 381 | end |
|
387 | 382 | |
|
388 | 383 | note = [] |
|
389 | 384 | users = [] |
|
390 | 385 | lines.split("\n").each do |line| |
|
391 | 386 | user = User.find_by_login(line.chomp) |
|
392 | 387 | if user |
|
393 | 388 | send_mail(user.email, mail_subject, mail_body) |
|
394 | 389 | note << user.login |
|
395 | 390 | end |
|
396 | 391 | end |
|
397 | 392 | |
|
398 | 393 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
399 | 394 | ' were successfully modified. ' |
|
400 | 395 | redirect_to :action => 'mass_mailing' |
|
401 | 396 | end |
|
402 | 397 | |
|
403 | 398 | protected |
|
404 | 399 | |
|
405 | 400 | def random_password(length=5) |
|
406 | 401 | chars = 'abcdefghijkmnopqrstuvwxyz23456789' |
|
407 | 402 | newpass = "" |
@@ -1,198 +1,199 | |||
|
1 | 1 | # Methods added to this helper will be available to all templates in the application. |
|
2 | 2 | module ApplicationHelper |
|
3 | 3 | |
|
4 | + #new bootstrap header | |
|
4 | 5 | def navbar_user_header |
|
5 | 6 | left_menu = '' |
|
6 | 7 | right_menu = '' |
|
7 | 8 | user = User.find(session[:user_id]) |
|
8 | 9 | |
|
9 | 10 | if (user!=nil) and (GraderConfiguration.show_tasks_to?(user)) |
|
10 | 11 | left_menu << add_menu("#{I18n.t 'menu.tasks'}", 'tasks', 'list') |
|
11 | 12 | left_menu << add_menu("#{I18n.t 'menu.submissions'}", 'main', 'submission') |
|
12 | 13 | left_menu << add_menu("#{I18n.t 'menu.test'}", 'test', 'index') |
|
13 | 14 | end |
|
14 | 15 | |
|
15 | 16 | if GraderConfiguration['right.user_hall_of_fame'] |
|
16 | 17 | left_menu << add_menu("#{I18n.t 'menu.hall_of_fame'}", 'report', 'problem_hof') |
|
17 | 18 | end |
|
18 | 19 | |
|
19 | 20 | right_menu << add_menu("#{content_tag(:span,'',class: 'glyphicon glyphicon-question-sign')}".html_safe, 'main', 'help') |
|
20 | 21 | right_menu << add_menu("#{content_tag(:span,'',class: 'glyphicon glyphicon-comment')}".html_safe, 'messages', 'list', {title: I18n.t('menu.messages'), data: {toggle: 'tooltip'}}) |
|
21 | 22 | if GraderConfiguration['system.user_setting_enabled'] |
|
22 | 23 | right_menu << add_menu("#{content_tag(:span,'',class: 'glyphicon glyphicon-cog')}".html_safe, 'users', 'index', {title: I18n.t('menu.settings'), data: {toggle: 'tooltip'}}) |
|
23 | 24 | end |
|
24 | 25 | right_menu << add_menu("#{content_tag(:span,'',class: 'glyphicon glyphicon-log-out')} #{user.full_name}".html_safe, 'main', 'login', {title: I18n.t('menu.log_out'), data: {toggle: 'tooltip'}}) |
|
25 | 26 | |
|
26 | 27 | |
|
27 | 28 | result = content_tag(:ul,left_menu.html_safe,class: 'nav navbar-nav') + content_tag(:ul,right_menu.html_safe,class: 'nav navbar-nav navbar-right') |
|
28 | 29 | end |
|
29 | 30 | |
|
30 | 31 | def add_menu(title, controller, action,html_option = {}) |
|
31 | 32 | link_option = {controller: controller, action: action} |
|
32 | 33 | html_option[:class] = (html_option[:class] || '') + " active" if current_page?(link_option) |
|
33 | 34 | content_tag(:li, link_to(title,link_option),html_option) |
|
34 | 35 | end |
|
35 | 36 | |
|
36 | 37 | def user_header |
|
37 | 38 | menu_items = '' |
|
38 | 39 | user = User.find(session[:user_id]) |
|
39 | 40 | |
|
40 | 41 | if (user!=nil) and (session[:admin]) |
|
41 | 42 | # admin menu |
|
42 | 43 | menu_items << "<b>Administrative task:</b> " |
|
43 | 44 | append_to menu_items, '[Announcements]', 'announcements', 'index' |
|
44 | 45 | append_to menu_items, '[Msg console]', 'messages', 'console' |
|
45 | 46 | append_to menu_items, '[Problems]', 'problems', 'index' |
|
46 | 47 | append_to menu_items, '[Users]', 'user_admin', 'index' |
|
47 | 48 | append_to menu_items, '[Results]', 'user_admin', 'user_stat' |
|
48 | 49 | append_to menu_items, '[Report]', 'report', 'multiple_login' |
|
49 | 50 | append_to menu_items, '[Graders]', 'graders', 'list' |
|
50 | 51 | append_to menu_items, '[Contests]', 'contest_management', 'index' |
|
51 | 52 | append_to menu_items, '[Sites]', 'sites', 'index' |
|
52 | 53 | append_to menu_items, '[System config]', 'configurations', 'index' |
|
53 | 54 | menu_items << "<br/>" |
|
54 | 55 | end |
|
55 | 56 | |
|
56 | 57 | # main page |
|
57 | 58 | append_to menu_items, "[#{I18n.t 'menu.main'}]", 'main', 'list' |
|
58 | 59 | append_to menu_items, "[#{I18n.t 'menu.messages'}]", 'messages', 'list' |
|
59 | 60 | |
|
60 | 61 | if (user!=nil) and (GraderConfiguration.show_tasks_to?(user)) |
|
61 | 62 | append_to menu_items, "[#{I18n.t 'menu.tasks'}]", 'tasks', 'list' |
|
62 | 63 | append_to menu_items, "[#{I18n.t 'menu.submissions'}]", 'main', 'submission' |
|
63 | 64 | append_to menu_items, "[#{I18n.t 'menu.test'}]", 'test', 'index' |
|
64 | 65 | end |
|
65 | 66 | |
|
66 | 67 | if GraderConfiguration['right.user_hall_of_fame'] |
|
67 | 68 | append_to menu_items, "[#{I18n.t 'menu.hall_of_fame'}]", 'report', 'problem_hof' |
|
68 | 69 | end |
|
69 | 70 | append_to menu_items, "[#{I18n.t 'menu.help'}]", 'main', 'help' |
|
70 | 71 | |
|
71 | 72 | if GraderConfiguration['system.user_setting_enabled'] |
|
72 | 73 | append_to menu_items, "[#{I18n.t 'menu.settings'}]", 'users', 'index' |
|
73 | 74 | end |
|
74 | 75 | append_to menu_items, "[#{I18n.t 'menu.log_out'}]", 'main', 'login' |
|
75 | 76 | |
|
76 | 77 | menu_items.html_safe |
|
77 | 78 | end |
|
78 | 79 | |
|
79 | 80 | def append_to(option,label, controller, action) |
|
80 | 81 | option << ' ' if option!='' |
|
81 | 82 | option << link_to_unless_current(label, |
|
82 | 83 | :controller => controller, |
|
83 | 84 | :action => action) |
|
84 | 85 | end |
|
85 | 86 | |
|
86 | 87 | def format_short_time(time) |
|
87 | 88 | now = Time.now.gmtime |
|
88 | 89 | st = '' |
|
89 | 90 | if (time.yday != now.yday) or |
|
90 | 91 | (time.year != now.year) |
|
91 | 92 | st = time.strftime("%x ") |
|
92 | 93 | end |
|
93 | 94 | st + time.strftime("%X") |
|
94 | 95 | end |
|
95 | 96 | |
|
96 | 97 | def format_short_duration(duration) |
|
97 | 98 | return '' if duration==nil |
|
98 | 99 | d = duration.to_f |
|
99 | 100 | return Time.at(d).gmtime.strftime("%X") |
|
100 | 101 | end |
|
101 | 102 | |
|
102 | 103 | def read_textfile(fname,max_size=2048) |
|
103 | 104 | begin |
|
104 | 105 | File.open(fname).read(max_size) |
|
105 | 106 | rescue |
|
106 | 107 | nil |
|
107 | 108 | end |
|
108 | 109 | end |
|
109 | 110 | |
|
110 | 111 | def toggle_button(on,toggle_url,id, option={}) |
|
111 | 112 | btn_size = option[:size] || 'btn-xs' |
|
112 | 113 | link_to (on ? "Yes" : "No"), toggle_url, |
|
113 | 114 | {class: "btn btn-block #{btn_size} btn-#{on ? 'success' : 'default'} ajax-toggle", |
|
114 | 115 | id: id, |
|
115 | 116 | data: {remote: true, method: 'get'}} |
|
116 | 117 | end |
|
117 | 118 | |
|
118 | 119 | def get_ace_mode(language) |
|
119 | 120 | # return ace mode string from Language |
|
120 | 121 | |
|
121 | 122 | case language.pretty_name |
|
122 | 123 | when 'Pascal' |
|
123 | 124 | 'ace/mode/pascal' |
|
124 | 125 | when 'C++','C' |
|
125 | 126 | 'ace/mode/c_cpp' |
|
126 | 127 | when 'Ruby' |
|
127 | 128 | 'ace/mode/ruby' |
|
128 | 129 | when 'Python' |
|
129 | 130 | 'ace/mode/python' |
|
130 | 131 | when 'Java' |
|
131 | 132 | 'ace/mode/java' |
|
132 | 133 | else |
|
133 | 134 | 'ace/mode/c_cpp' |
|
134 | 135 | end |
|
135 | 136 | end |
|
136 | 137 | |
|
137 | 138 | |
|
138 | 139 | def user_title_bar(user) |
|
139 | 140 | header = '' |
|
140 | 141 | time_left = '' |
|
141 | 142 | |
|
142 | 143 | # |
|
143 | 144 | # if the contest is over |
|
144 | 145 | if GraderConfiguration.time_limit_mode? |
|
145 | 146 | if user.contest_finished? |
|
146 | 147 | header = <<CONTEST_OVER |
|
147 | 148 | <tr><td colspan="2" align="center"> |
|
148 | 149 | <span class="contest-over-msg">THE CONTEST IS OVER</span> |
|
149 | 150 | </td></tr> |
|
150 | 151 | CONTEST_OVER |
|
151 | 152 | end |
|
152 | 153 | if !user.contest_started? |
|
153 | 154 | time_left = " " + (t 'title_bar.contest_not_started') |
|
154 | 155 | else |
|
155 | 156 | time_left = " " + (t 'title_bar.remaining_time') + |
|
156 | 157 | " #{format_short_duration(user.contest_time_left)}" |
|
157 | 158 | end |
|
158 | 159 | end |
|
159 | 160 | |
|
160 | 161 | # |
|
161 | 162 | # if the contest is in the anaysis mode |
|
162 | 163 | if GraderConfiguration.analysis_mode? |
|
163 | 164 | header = <<ANALYSISMODE |
|
164 | 165 | <tr><td colspan="2" align="center"> |
|
165 | 166 | <span class="contest-over-msg">ANALYSIS MODE</span> |
|
166 | 167 | </td></tr> |
|
167 | 168 | ANALYSISMODE |
|
168 | 169 | end |
|
169 | 170 | |
|
170 | 171 | contest_name = GraderConfiguration['contest.name'] |
|
171 | 172 | |
|
172 | 173 | # |
|
173 | 174 | # build real title bar |
|
174 | 175 | result = <<TITLEBAR |
|
175 | 176 | <div class="title"> |
|
176 | 177 | <table> |
|
177 | 178 | #{header} |
|
178 | 179 | <tr> |
|
179 | 180 | <td class="left-col"> |
|
180 | 181 | #{user.full_name}<br/> |
|
181 | 182 | #{t 'title_bar.current_time'} #{format_short_time(Time.zone.now)} |
|
182 | 183 | #{time_left} |
|
183 | 184 | <br/> |
|
184 | 185 | </td> |
|
185 | 186 | <td class="right-col">#{contest_name}</td> |
|
186 | 187 | </tr> |
|
187 | 188 | </table> |
|
188 | 189 | </div> |
|
189 | 190 | TITLEBAR |
|
190 | 191 | result.html_safe |
|
191 | 192 | end |
|
192 | 193 | |
|
193 | 194 | def markdown(text) |
|
194 | 195 | markdown = RDiscount.new(text) |
|
195 | 196 | markdown.to_html.html_safe |
|
196 | 197 | end |
|
197 | 198 | |
|
198 | 199 | end |
@@ -1,81 +1,82 | |||
|
1 | 1 | - content_for :head do |
|
2 | 2 | <meta http-equiv ="refresh" content="60"/> |
|
3 | 3 | |
|
4 | 4 | %h1 Grader information |
|
5 | 5 | |
|
6 | 6 | %p |
|
7 | 7 | = link_to 'Refresh', { :action => 'list' }, class: 'btn btn-info' |
|
8 | 8 | |
|
9 | 9 | .panel.panel-primary |
|
10 | 10 | .panel-heading |
|
11 | 11 | Grader control: |
|
12 | 12 | .panel-body |
|
13 | 13 | =link_to 'Start Graders in grading env', { action: 'start_grading'}, class: 'btn btn-default', method: 'post' |
|
14 | 14 | =link_to 'Start Graders in exam env', { action: 'start_exam'}, class: 'btn btn-default', method: 'post' |
|
15 | 15 | =link_to 'Stop all running Graders', { action: 'stop_all'}, class: 'btn btn-default', method: 'post' |
|
16 | 16 | =link_to 'Clear all data', { action: 'clear_all'}, class: 'btn btn-default', method: 'post' |
|
17 | 17 | |
|
18 | - .submitbox | |
|
19 | - .item | |
|
20 | - Grader control: | |
|
21 | - .item | |
|
22 | - = form_for :clear, :url => {:action => 'start_grading'} do |f| | |
|
23 | - = submit_tag 'Start graders in grading env' | |
|
24 | - .item | |
|
25 | - = form_for :clear, :url => {:action => 'start_exam'} do |f| | |
|
26 | - = submit_tag 'Start graders in exam env' | |
|
27 | - .item | |
|
28 | - = form_for :clear, :url => {:action => 'stop_all'} do |f| | |
|
29 | - = submit_tag 'Stop all running graders' | |
|
30 | - .item | |
|
31 | - = form_for :clear, :url => {:action => 'clear_all'} do |f| | |
|
32 | - = submit_tag 'Clear all data' | |
|
33 | - %br{:style => 'clear:both'}/ | |
|
34 | - | |
|
35 | 18 | .row |
|
36 | 19 | .col-md-6 |
|
37 | 20 | - if @last_task |
|
38 | 21 | Last task: |
|
39 | 22 | = link_to "#{@last_task.id}", :action => 'view', :id => @last_task.id, :type => 'Task' |
|
40 | 23 | |
|
41 | 24 | %br/ |
|
42 | 25 | |
|
43 | 26 | - if @last_test_request |
|
44 | 27 | Last test_request: |
|
45 | 28 | = link_to "#{@last_test_request.id}", :action => 'view', :id => @last_test_request.id, :type => 'TestRequest' |
|
46 | 29 | |
|
47 | 30 | %h2 Current graders |
|
48 | 31 | |
|
49 | 32 | = render :partial => 'grader_list', :locals => {:grader_list => @grader_processes} |
|
50 | 33 | |
|
51 | 34 | %h2 Stalled graders |
|
52 | 35 | |
|
53 | 36 | = render :partial => 'grader_list', :locals => {:grader_list => @stalled_processes} |
|
54 | 37 | |
|
55 | 38 | %h2 Terminated graders |
|
56 | 39 | |
|
57 | 40 | %p= link_to 'Clear data for terminated graders', { action: 'clear_terminated'}, class: 'btn btn-default', method: 'post' |
|
58 | 41 | |
|
59 | 42 | = render :partial => 'grader_list', :locals => {:grader_list => @terminated_processes} |
|
60 | 43 | .col-md-6 |
|
61 | 44 | %h2 Last 20 submissions |
|
62 | 45 | %table.table.table-striped.table-condensed |
|
63 | 46 | %thead |
|
64 | 47 | %th ID |
|
65 | 48 | %th User |
|
66 | 49 | %th Problem |
|
67 | 50 | %th Submitted |
|
68 | 51 | %th Graded |
|
69 | 52 | %th Result |
|
70 | - %th | |
|
71 | 53 | %tbody |
|
72 | 54 | - @submission.each do |sub| |
|
73 | 55 | %tr.inactive |
|
74 | 56 | %td= link_to sub.id, controller: 'graders' ,action: 'submission', id: sub.id |
|
75 | 57 | %td= sub.try(:user).try(:full_name) |
|
76 | 58 | %td= sub.try(:problem).try(:full_name) |
|
77 | 59 | %td= "#{time_ago_in_words(sub.submitted_at)} ago" |
|
78 | 60 | %td= sub.graded_at ? "#{time_ago_in_words(sub.graded_at)} ago" : " " |
|
79 | 61 | %td= sub.grader_comment |
|
62 | + %h2 Ungraded submission | |
|
63 | + %table.table.table-striped.table-condensed | |
|
64 | + %thead | |
|
65 | + %th ID | |
|
66 | + %th User | |
|
67 | + %th Problem | |
|
68 | + %th Submitted | |
|
69 | + %th Graded | |
|
70 | + %th Result | |
|
71 | + %tbody | |
|
72 | + - @backlog_submission.each do |sub| | |
|
73 | + %tr.inactive | |
|
74 | + %td= link_to sub.id, controller: 'graders' ,action: 'submission', id: sub.id | |
|
75 | + %td= sub.try(:user).try(:full_name) | |
|
76 | + %td= sub.try(:problem).try(:full_name) | |
|
77 | + %td= "#{time_ago_in_words(sub.submitted_at)} ago" | |
|
78 | + %td= sub.graded_at ? "#{time_ago_in_words(sub.graded_at)} ago" : " " | |
|
79 | + %td= sub.grader_comment | |
|
80 | 80 | |
|
81 | 81 | |
|
82 | + |
You need to be logged in to leave comments.
Login now