Description:
fix error when problem.full_score is nil. More has to be done to prevent problem.full_score being nil
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r523:e5c66a78e3f9 - - 2 files changed: 27 inserted, 26 deleted

@@ -1,337 +1,337
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 19 list
20 20 render :action => 'list'
21 21 end
22 22
23 23 def list
24 24 @user_count = User.count
25 25 if params[:page] == 'all'
26 26 @users = User.all
27 27 @paginated = false
28 28 else
29 29 @users = User.paginate :page => params[:page]
30 30 @paginated = true
31 31 end
32 32 @hidden_columns = ['hashed_password', 'salt', 'created_at', 'updated_at']
33 33 @contests = Contest.enabled
34 34 end
35 35
36 36 def active
37 37 sessions = ActiveRecord::SessionStore::Session.find(:all, :conditions => ["updated_at >= ?", 60.minutes.ago])
38 38 @users = []
39 39 sessions.each do |session|
40 40 if session.data[:user_id]
41 41 @users << User.find(session.data[:user_id])
42 42 end
43 43 end
44 44 end
45 45
46 46 def show
47 47 @user = User.find(params[:id])
48 48 end
49 49
50 50 def new
51 51 @user = User.new
52 52 end
53 53
54 54 def create
55 55 @user = User.new(params[:user])
56 56 @user.activated = true
57 57 if @user.save
58 58 flash[:notice] = 'User was successfully created.'
59 59 redirect_to :action => 'list'
60 60 else
61 61 render :action => 'new'
62 62 end
63 63 end
64 64
65 65 def create_from_list
66 66 lines = params[:user_list]
67 67
68 68 note = []
69 69
70 70 lines.split("\n").each do |line|
71 71 items = line.chomp.split(',')
72 72 if items.length>=2
73 73 login = items[0]
74 74 full_name = items[1]
75 75
76 76 added_random_password = false
77 77 if items.length>=3
78 78 password = items[2].chomp(" ")
79 79 user_alias = (items.length>=4) ? items[3] : login
80 80 else
81 81 password = random_password
82 82 user_alias = (items.length>=4) ? items[3] : login
83 83 added_random_password = true
84 84 end
85 85
86 86 user = User.find_by_login(login)
87 87 if (user)
88 88 user.full_name = full_name
89 89 user.password = password
90 90 else
91 91 user = User.new({:login => login,
92 92 :full_name => full_name,
93 93 :password => password,
94 94 :password_confirmation => password,
95 95 :alias => user_alias})
96 96 end
97 97 user.activated = true
98 98 user.save
99 99
100 100 if added_random_password
101 101 note << "'#{login}' (+)"
102 102 else
103 103 note << login
104 104 end
105 105 end
106 106 end
107 107 flash[:notice] = 'User(s) ' + note.join(', ') +
108 108 ' were successfully created. ' +
109 109 '( (+) - created with random passwords.)'
110 110 redirect_to :action => 'list'
111 111 end
112 112
113 113 def edit
114 114 @user = User.find(params[:id])
115 115 end
116 116
117 117 def update
118 118 @user = User.find(params[:id])
119 119 if @user.update_attributes(params[:user])
120 120 flash[:notice] = 'User was successfully updated.'
121 121 redirect_to :action => 'show', :id => @user
122 122 else
123 123 render :action => 'edit'
124 124 end
125 125 end
126 126
127 127 def destroy
128 128 User.find(params[:id]).destroy
129 129 redirect_to :action => 'list'
130 130 end
131 131
132 132 def user_stat
133 133 if params[:commit] == 'download csv'
134 134 @problems = Problem.all
135 135 else
136 136 @problems = Problem.find_available_problems
137 137 end
138 138 @users = User.find(:all, :include => [:contests, :contest_stat])
139 139 @scorearray = Array.new
140 140 @users.each do |u|
141 141 ustat = Array.new
142 142 ustat[0] = u
143 143 @problems.each do |p|
144 144 sub = Submission.find_last_by_user_and_problem(u.id,p.id)
145 - if (sub!=nil) and (sub.points!=nil)
145 + if (sub!=nil) and (sub.points!=nil) and p and p.full_score
146 146 ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)]
147 147 else
148 148 ustat << [0,false]
149 149 end
150 150 end
151 151 @scorearray << ustat
152 152 end
153 153 if params[:commit] == 'download csv' then
154 154 csv = gen_csv_from_scorearray(@scorearray,@problems)
155 155 send_data csv, filename: 'last_score.csv'
156 156 else
157 157 render template: 'user_admin/user_stat'
158 158 end
159 159 end
160 160
161 161 def user_stat_max
162 162 if params[:commit] == 'download csv'
163 163 @problems = Problem.all
164 164 else
165 165 @problems = Problem.find_available_problems
166 166 end
167 167 @users = User.find(:all, :include => [:contests, :contest_stat])
168 168 @scorearray = Array.new
169 169 #set up range from param
170 170 since_id = params.fetch(:since_id, 0).to_i
171 171 until_id = params.fetch(:until_id, 0).to_i
172 172 @users.each do |u|
173 173 ustat = Array.new
174 174 ustat[0] = u
175 175 @problems.each do |p|
176 176 max_points = 0
177 177 Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub|
178 178 max_points = sub.points if sub and sub.points and (sub.points > max_points)
179 179 end
180 180 ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)]
181 181 end
182 182 @scorearray << ustat
183 183 end
184 184
185 185 if params[:commit] == 'download csv' then
186 186 csv = gen_csv_from_scorearray(@scorearray,@problems)
187 187 send_data csv, filename: 'max_score.csv'
188 188 else
189 189 render template: 'user_admin/user_stat'
190 190 end
191 191 end
192 192
193 193 def import
194 194 if params[:file]==''
195 195 flash[:notice] = 'Error importing no file'
196 196 redirect_to :action => 'list' and return
197 197 end
198 198 import_from_file(params[:file])
199 199 end
200 200
201 201 def random_all_passwords
202 202 users = User.find(:all)
203 203 @prefix = params[:prefix] || ''
204 204 @non_admin_users = User.find_non_admin_with_prefix(@prefix)
205 205 @changed = false
206 206 if request.request_method == 'POST'
207 207 @non_admin_users.each do |user|
208 208 password = random_password
209 209 user.password = password
210 210 user.password_confirmation = password
211 211 user.save
212 212 end
213 213 @changed = true
214 214 end
215 215 end
216 216
217 217 # contest management
218 218
219 219 def contests
220 220 @contest, @users = find_contest_and_user_from_contest_id(params[:id])
221 221 @contests = Contest.enabled
222 222 end
223 223
224 224 def assign_from_list
225 225 contest_id = params[:users_contest_id]
226 226 org_contest, users = find_contest_and_user_from_contest_id(contest_id)
227 227 contest = Contest.find(params[:new_contest][:id])
228 228 if !contest
229 229 flash[:notice] = 'Error: no contest'
230 230 redirect_to :action => 'contests', :id =>contest_id
231 231 end
232 232
233 233 note = []
234 234 users.each do |u|
235 235 u.contests = [contest]
236 236 note << u.login
237 237 end
238 238 flash[:notice] = 'User(s) ' + note.join(', ') +
239 239 " were successfully reassigned to #{contest.title}."
240 240 redirect_to :action => 'contests', :id =>contest.id
241 241 end
242 242
243 243 def add_to_contest
244 244 user = User.find(params[:id])
245 245 contest = Contest.find(params[:contest_id])
246 246 if user and contest
247 247 user.contests << contest
248 248 end
249 249 redirect_to :action => 'list'
250 250 end
251 251
252 252 def remove_from_contest
253 253 user = User.find(params[:id])
254 254 contest = Contest.find(params[:contest_id])
255 255 if user and contest
256 256 user.contests.delete(contest)
257 257 end
258 258 redirect_to :action => 'list'
259 259 end
260 260
261 261 def contest_management
262 262 end
263 263
264 264 def manage_contest
265 265 contest = Contest.find(params[:contest][:id])
266 266 if !contest
267 267 flash[:notice] = 'You did not choose the contest.'
268 268 redirect_to :action => 'contest_management' and return
269 269 end
270 270
271 271 operation = params[:operation]
272 272
273 273 if not ['add','remove','assign'].include? operation
274 274 flash[:notice] = 'You did not choose the operation to perform.'
275 275 redirect_to :action => 'contest_management' and return
276 276 end
277 277
278 278 lines = params[:login_list]
279 279 if !lines or lines.blank?
280 280 flash[:notice] = 'You entered an empty list.'
281 281 redirect_to :action => 'contest_management' and return
282 282 end
283 283
284 284 note = []
285 285 users = []
286 286 lines.split("\n").each do |line|
287 287 user = User.find_by_login(line.chomp)
288 288 if user
289 289 if operation=='add'
290 290 if ! user.contests.include? contest
291 291 user.contests << contest
292 292 end
293 293 elsif operation=='remove'
294 294 user.contests.delete(contest)
295 295 else
296 296 user.contests = [contest]
297 297 end
298 298
299 299 if params[:reset_timer]
300 300 user.contest_stat.forced_logout = true
301 301 user.contest_stat.reset_timer_and_save
302 302 end
303 303
304 304 if params[:notification_emails]
305 305 send_contest_update_notification_email(user, contest)
306 306 end
307 307
308 308 note << user.login
309 309 users << user
310 310 end
311 311 end
312 312
313 313 if params[:reset_timer]
314 314 logout_users(users)
315 315 end
316 316
317 317 flash[:notice] = 'User(s) ' + note.join(', ') +
318 318 ' were successfully modified. '
319 319 redirect_to :action => 'contest_management'
320 320 end
321 321
322 322 # admin management
323 323
324 324 def admin
325 325 @admins = User.find(:all).find_all {|user| user.admin? }
326 326 end
327 327
328 328 def grant_admin
329 329 login = params[:login]
330 330 user = User.find_by_login(login)
331 331 if user!=nil
332 332 admin_role = Role.find_by_name('admin')
333 333 user.roles << admin_role
334 334 else
335 335 flash[:notice] = 'Unknown user'
336 336 end
337 337 flash[:notice] = 'User added as admins'
@@ -1,248 +1,249
1 1 # encoding: UTF-8
2 2 # This file is auto-generated from the current state of the database. Instead
3 3 # of editing this file, please use the migrations feature of Active Record to
4 4 # incrementally modify your database, and then regenerate this schema definition.
5 5 #
6 6 # Note that this schema.rb definition is the authoritative source for your
7 7 # database schema. If you need to create the application database on another
8 8 # system, you should be using db:schema:load, not running all the migrations
9 9 # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10 10 # you'll amass, the slower it'll run and the greater likelihood for issues).
11 11 #
12 12 # It's strongly recommended to check this file into your version control system.
13 13
14 14 ActiveRecord::Schema.define(:version => 20150203153534) do
15 15
16 16 create_table "announcements", :force => true do |t|
17 17 t.string "author"
18 - t.text "body"
18 + t.text "body", :limit => 16777215
19 19 t.boolean "published"
20 - t.datetime "created_at", :null => false
21 - t.datetime "updated_at", :null => false
22 - t.boolean "frontpage", :default => false
23 - t.boolean "contest_only", :default => false
20 + t.datetime "created_at", :null => false
21 + t.datetime "updated_at", :null => false
22 + t.boolean "frontpage", :default => false
23 + t.boolean "contest_only", :default => false
24 24 t.string "title"
25 25 t.string "notes"
26 26 end
27 27
28 28 create_table "contests", :force => true do |t|
29 29 t.string "title"
30 30 t.boolean "enabled"
31 31 t.datetime "created_at", :null => false
32 32 t.datetime "updated_at", :null => false
33 33 t.string "name"
34 34 end
35 35
36 36 create_table "contests_problems", :id => false, :force => true do |t|
37 37 t.integer "contest_id"
38 38 t.integer "problem_id"
39 39 end
40 40
41 41 create_table "contests_users", :id => false, :force => true do |t|
42 42 t.integer "contest_id"
43 43 t.integer "user_id"
44 44 end
45 45
46 46 create_table "countries", :force => true do |t|
47 47 t.string "name"
48 48 t.datetime "created_at", :null => false
49 49 t.datetime "updated_at", :null => false
50 50 end
51 51
52 52 create_table "descriptions", :force => true do |t|
53 - t.text "body"
53 + t.text "body", :limit => 16777215
54 54 t.boolean "markdowned"
55 - t.datetime "created_at", :null => false
56 - t.datetime "updated_at", :null => false
55 + t.datetime "created_at", :null => false
56 + t.datetime "updated_at", :null => false
57 57 end
58 58
59 59 create_table "grader_configurations", :force => true do |t|
60 60 t.string "key"
61 61 t.string "value_type"
62 62 t.string "value"
63 - t.datetime "created_at", :null => false
64 - t.datetime "updated_at", :null => false
65 - t.text "description"
63 + t.datetime "created_at", :null => false
64 + t.datetime "updated_at", :null => false
65 + t.text "description", :limit => 16777215
66 66 end
67 67
68 68 create_table "grader_processes", :force => true do |t|
69 69 t.string "host", :limit => 20
70 70 t.integer "pid"
71 71 t.string "mode"
72 72 t.boolean "active"
73 73 t.datetime "created_at", :null => false
74 74 t.datetime "updated_at", :null => false
75 75 t.integer "task_id"
76 76 t.string "task_type"
77 77 t.boolean "terminated"
78 78 end
79 79
80 80 add_index "grader_processes", ["host", "pid"], :name => "index_grader_processes_on_ip_and_pid"
81 81
82 82 create_table "languages", :force => true do |t|
83 83 t.string "name", :limit => 10
84 84 t.string "pretty_name"
85 85 t.string "ext", :limit => 10
86 86 t.string "common_ext"
87 87 end
88 88
89 89 create_table "logins", :force => true do |t|
90 90 t.string "user_id"
91 91 t.string "ip_address"
92 92 t.datetime "created_at", :null => false
93 93 t.datetime "updated_at", :null => false
94 94 end
95 95
96 96 create_table "messages", :force => true do |t|
97 97 t.integer "sender_id"
98 98 t.integer "receiver_id"
99 99 t.integer "replying_message_id"
100 - t.text "body"
100 + t.text "body", :limit => 16777215
101 101 t.boolean "replied"
102 - t.datetime "created_at", :null => false
103 - t.datetime "updated_at", :null => false
102 + t.datetime "created_at", :null => false
103 + t.datetime "updated_at", :null => false
104 104 end
105 105
106 106 create_table "problems", :force => true do |t|
107 107 t.string "name", :limit => 30
108 108 t.string "full_name"
109 109 t.integer "full_score"
110 110 t.date "date_added"
111 111 t.boolean "available"
112 112 t.string "url"
113 113 t.integer "description_id"
114 114 t.boolean "test_allowed"
115 115 t.boolean "output_only"
116 116 t.string "description_filename"
117 117 end
118 118
119 119 create_table "rights", :force => true do |t|
120 120 t.string "name"
121 121 t.string "controller"
122 122 t.string "action"
123 123 end
124 124
125 125 create_table "rights_roles", :id => false, :force => true do |t|
126 126 t.integer "right_id"
127 127 t.integer "role_id"
128 128 end
129 129
130 130 add_index "rights_roles", ["role_id"], :name => "index_rights_roles_on_role_id"
131 131
132 132 create_table "roles", :force => true do |t|
133 133 t.string "name"
134 134 end
135 135
136 136 create_table "roles_users", :id => false, :force => true do |t|
137 137 t.integer "role_id"
138 138 t.integer "user_id"
139 139 end
140 140
141 141 add_index "roles_users", ["user_id"], :name => "index_roles_users_on_user_id"
142 142
143 143 create_table "sessions", :force => true do |t|
144 144 t.string "session_id"
145 - t.text "data"
145 + t.text "data", :limit => 16777215
146 146 t.datetime "updated_at"
147 147 end
148 148
149 149 add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id"
150 150 add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"
151 151
152 152 create_table "sites", :force => true do |t|
153 153 t.string "name"
154 154 t.boolean "started"
155 155 t.datetime "start_time"
156 156 t.datetime "created_at", :null => false
157 157 t.datetime "updated_at", :null => false
158 158 t.integer "country_id"
159 159 t.string "password"
160 160 end
161 161
162 162 create_table "submissions", :force => true do |t|
163 163 t.integer "user_id"
164 164 t.integer "problem_id"
165 165 t.integer "language_id"
166 - t.text "source"
166 + t.text "source", :limit => 16777215
167 167 t.binary "binary"
168 168 t.datetime "submitted_at"
169 169 t.datetime "compiled_at"
170 - t.text "compiler_message"
170 + t.text "compiler_message", :limit => 16777215
171 171 t.datetime "graded_at"
172 172 t.integer "points"
173 - t.text "grader_comment"
173 + t.text "grader_comment", :limit => 16777215
174 174 t.integer "number"
175 175 t.string "source_filename"
176 176 t.float "max_runtime"
177 177 t.integer "peak_memory"
178 178 t.integer "effective_code_length"
179 179 t.string "ip_address"
180 180 end
181 181
182 182 add_index "submissions", ["user_id", "problem_id", "number"], :name => "index_submissions_on_user_id_and_problem_id_and_number", :unique => true
183 183 add_index "submissions", ["user_id", "problem_id"], :name => "index_submissions_on_user_id_and_problem_id"
184 184
185 185 create_table "tasks", :force => true do |t|
186 186 t.integer "submission_id"
187 187 t.datetime "created_at"
188 188 t.integer "status"
189 189 t.datetime "updated_at"
190 190 end
191 191
192 192 create_table "test_pairs", :force => true do |t|
193 193 t.integer "problem_id"
194 - t.text "input", :limit => 16777215
195 - t.text "solution", :limit => 16777215
196 - t.datetime "created_at", :null => false
197 - t.datetime "updated_at", :null => false
194 + t.text "input", :limit => 2147483647
195 + t.text "solution", :limit => 2147483647
196 + t.datetime "created_at", :null => false
197 + t.datetime "updated_at", :null => false
198 198 end
199 199
200 200 create_table "test_requests", :force => true do |t|
201 201 t.integer "user_id"
202 202 t.integer "problem_id"
203 203 t.integer "submission_id"
204 204 t.string "input_file_name"
205 205 t.string "output_file_name"
206 206 t.string "running_stat"
207 207 t.integer "status"
208 - t.datetime "updated_at", :null => false
208 + t.datetime "updated_at", :null => false
209 209 t.datetime "submitted_at"
210 210 t.datetime "compiled_at"
211 - t.text "compiler_message"
211 + t.text "compiler_message", :limit => 16777215
212 212 t.datetime "graded_at"
213 213 t.string "grader_comment"
214 - t.datetime "created_at", :null => false
214 + t.datetime "created_at", :null => false
215 215 t.float "running_time"
216 216 t.string "exit_status"
217 217 t.integer "memory_usage"
218 218 end
219 219
220 220 add_index "test_requests", ["user_id", "problem_id"], :name => "index_test_requests_on_user_id_and_problem_id"
221 221
222 222 create_table "user_contest_stats", :force => true do |t|
223 223 t.integer "user_id"
224 224 t.datetime "started_at"
225 225 t.datetime "created_at", :null => false
226 226 t.datetime "updated_at", :null => false
227 227 t.boolean "forced_logout"
228 228 end
229 229
230 230 create_table "users", :force => true do |t|
231 231 t.string "login", :limit => 50
232 232 t.string "full_name"
233 233 t.string "hashed_password"
234 234 t.string "salt", :limit => 5
235 235 t.string "alias"
236 236 t.string "email"
237 237 t.integer "site_id"
238 238 t.integer "country_id"
239 239 t.boolean "activated", :default => false
240 240 t.datetime "created_at"
241 241 t.datetime "updated_at"
242 + t.string "section"
242 243 t.boolean "enabled", :default => true
243 244 t.string "remark"
244 245 end
245 246
246 247 add_index "users", ["login"], :name => "index_users_on_login", :unique => true
247 248
248 249 end
You need to be logged in to leave comments. Login now