Description:
add TA roles
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r799:584294790340 - - 6 files changed: 82 inserted, 53 deleted

@@ -1,112 +1,111
1 class SubmissionsController < ApplicationController
1 class SubmissionsController < ApplicationController
2 before_action :check_valid_login
2 before_action :check_valid_login
3 before_action :submission_authorization, only: [:show, :download, :edit]
3 before_action :submission_authorization, only: [:show, :download, :edit]
4 before_action :admin_authorization, only: [:rejudge]
4 before_action :admin_authorization, only: [:rejudge]
5
5
6 # GET /submissions
6 # GET /submissions
7 # GET /submissions.json
7 # GET /submissions.json
8 # Show problem selection and user's submission of that problem
8 # Show problem selection and user's submission of that problem
9 def index
9 def index
10 @user = @current_user
10 @user = @current_user
11 @problems = @user.available_problems
11 @problems = @user.available_problems
12
12
13 if params[:problem_id]==nil
13 if params[:problem_id]==nil
14 @problem = nil
14 @problem = nil
15 @submissions = nil
15 @submissions = nil
16 else
16 else
17 @problem = Problem.find_by_id(params[:problem_id])
17 @problem = Problem.find_by_id(params[:problem_id])
18 if (@problem == nil) or (not @problem.available)
18 if (@problem == nil) or (not @problem.available)
19 redirect_to list_main_path
19 redirect_to list_main_path
20 flash[:error] = 'Authorization error: You have no right to view submissions for this problem'
20 flash[:error] = 'Authorization error: You have no right to view submissions for this problem'
21 return
21 return
22 end
22 end
23 @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id).order(id: :desc)
23 @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id).order(id: :desc)
24 end
24 end
25 end
25 end
26
26
27 # GET /submissions/1
27 # GET /submissions/1
28 # GET /submissions/1.json
28 # GET /submissions/1.json
29 def show
29 def show
30 @submission = Submission.find(params[:id])
30 @submission = Submission.find(params[:id])
31
31
32 #log the viewing
32 #log the viewing
33 user = User.find(session[:user_id])
33 user = User.find(session[:user_id])
34 SubmissionViewLog.create(user_id: session[:user_id],submission_id: @submission.id) unless user.admin?
34 SubmissionViewLog.create(user_id: session[:user_id],submission_id: @submission.id) unless user.admin?
35
35
36 @task = @submission.task
36 @task = @submission.task
37 end
37 end
38
38
39 def download
39 def download
40 @submission = Submission.find(params[:id])
40 @submission = Submission.find(params[:id])
41 send_data(@submission.source, {:filename => @submission.download_filename, :type => 'text/plain'})
41 send_data(@submission.source, {:filename => @submission.download_filename, :type => 'text/plain'})
42 end
42 end
43
43
44 def compiler_msg
44 def compiler_msg
45 @submission = Submission.find(params[:id])
45 @submission = Submission.find(params[:id])
46 respond_to do |format|
46 respond_to do |format|
47 format.js
47 format.js
48 end
48 end
49 end
49 end
50
50
51 #on-site new submission on specific problem
51 #on-site new submission on specific problem
52 def direct_edit_problem
52 def direct_edit_problem
53 @problem = Problem.find(params[:problem_id])
53 @problem = Problem.find(params[:problem_id])
54 unless @current_user.can_view_problem?(@problem)
54 unless @current_user.can_view_problem?(@problem)
55 unauthorized_redirect
55 unauthorized_redirect
56 return
56 return
57 end
57 end
58 @source = ''
58 @source = ''
59 if (params[:view_latest])
59 if (params[:view_latest])
60 sub = Submission.find_last_by_user_and_problem(@current_user.id,@problem.id)
60 sub = Submission.find_last_by_user_and_problem(@current_user.id,@problem.id)
61 @source = @submission.source.to_s if @submission and @submission.source
61 @source = @submission.source.to_s if @submission and @submission.source
62 end
62 end
63 render 'edit'
63 render 'edit'
64 end
64 end
65
65
66 # GET /submissions/1/edit
66 # GET /submissions/1/edit
67 def edit
67 def edit
68 @submission = Submission.find(params[:id])
68 @submission = Submission.find(params[:id])
69 @source = @submission.source.to_s
69 @source = @submission.source.to_s
70 @problem = @submission.problem
70 @problem = @submission.problem
71 @lang_id = @submission.language.id
71 @lang_id = @submission.language.id
72 end
72 end
73
73
74
74
75 def get_latest_submission_status
75 def get_latest_submission_status
76 @problem = Problem.find(params[:pid])
76 @problem = Problem.find(params[:pid])
77 @submission = Submission.find_last_by_user_and_problem(params[:uid],params[:pid])
77 @submission = Submission.find_last_by_user_and_problem(params[:uid],params[:pid])
78 respond_to do |format|
78 respond_to do |format|
79 format.js
79 format.js
80 end
80 end
81 end
81 end
82
82
83 # GET /submissions/:id/rejudge
83 # GET /submissions/:id/rejudge
84 def rejudge
84 def rejudge
85 @submission = Submission.find(params[:id])
85 @submission = Submission.find(params[:id])
86 @task = @submission.task
86 @task = @submission.task
87 @task.status_inqueue! if @task
87 @task.status_inqueue! if @task
88 respond_to do |format|
88 respond_to do |format|
89 format.js
89 format.js
90 end
90 end
91 end
91 end
92
92
93 protected
93 protected
94
94
95 def submission_authorization
95 def submission_authorization
96 #admin always has privileged
96 #admin always has privileged
97 - if @current_user.admin?
97 + return true if @current_user.admin?
98 - return true
98 + return true if @current_user.has_role?('TA') && (['show','download'].include? action_name)
99 - end
100
99
101 sub = Submission.find(params[:id])
100 sub = Submission.find(params[:id])
102 if @current_user.available_problems.include? sub.problem
101 if @current_user.available_problems.include? sub.problem
103 return true if GraderConfiguration["right.user_view_submission"] or sub.user == @current_user
102 return true if GraderConfiguration["right.user_view_submission"] or sub.user == @current_user
104 end
103 end
105
104
106 #default to NO
105 #default to NO
107 unauthorized_redirect
106 unauthorized_redirect
108 return false
107 return false
109 end
108 end
110
109
111
110
112 end
111 end
@@ -269,222 +269,219
269 flash[:notice] = 'Error: no contest'
269 flash[:notice] = 'Error: no contest'
270 redirect_to :action => 'contests', :id =>contest_id
270 redirect_to :action => 'contests', :id =>contest_id
271 end
271 end
272
272
273 note = []
273 note = []
274 users.each do |u|
274 users.each do |u|
275 u.contests = [contest]
275 u.contests = [contest]
276 note << u.login
276 note << u.login
277 end
277 end
278 flash[:notice] = 'User(s) ' + note.join(', ') +
278 flash[:notice] = 'User(s) ' + note.join(', ') +
279 " were successfully reassigned to #{contest.title}."
279 " were successfully reassigned to #{contest.title}."
280 redirect_to :action => 'contests', :id =>contest.id
280 redirect_to :action => 'contests', :id =>contest.id
281 end
281 end
282
282
283 def add_to_contest
283 def add_to_contest
284 user = User.find(params[:id])
284 user = User.find(params[:id])
285 contest = Contest.find(params[:contest_id])
285 contest = Contest.find(params[:contest_id])
286 if user and contest
286 if user and contest
287 user.contests << contest
287 user.contests << contest
288 end
288 end
289 redirect_to :action => 'index'
289 redirect_to :action => 'index'
290 end
290 end
291
291
292 def remove_from_contest
292 def remove_from_contest
293 user = User.find(params[:id])
293 user = User.find(params[:id])
294 contest = Contest.find(params[:contest_id])
294 contest = Contest.find(params[:contest_id])
295 if user and contest
295 if user and contest
296 user.contests.delete(contest)
296 user.contests.delete(contest)
297 end
297 end
298 redirect_to :action => 'index'
298 redirect_to :action => 'index'
299 end
299 end
300
300
301 def contest_management
301 def contest_management
302 end
302 end
303
303
304 def manage_contest
304 def manage_contest
305 contest = Contest.find(params[:contest][:id])
305 contest = Contest.find(params[:contest][:id])
306 if !contest
306 if !contest
307 flash[:notice] = 'You did not choose the contest.'
307 flash[:notice] = 'You did not choose the contest.'
308 redirect_to :action => 'contest_management' and return
308 redirect_to :action => 'contest_management' and return
309 end
309 end
310
310
311 operation = params[:operation]
311 operation = params[:operation]
312
312
313 if not ['add','remove','assign'].include? operation
313 if not ['add','remove','assign'].include? operation
314 flash[:notice] = 'You did not choose the operation to perform.'
314 flash[:notice] = 'You did not choose the operation to perform.'
315 redirect_to :action => 'contest_management' and return
315 redirect_to :action => 'contest_management' and return
316 end
316 end
317
317
318 lines = params[:login_list]
318 lines = params[:login_list]
319 if !lines or lines.blank?
319 if !lines or lines.blank?
320 flash[:notice] = 'You entered an empty list.'
320 flash[:notice] = 'You entered an empty list.'
321 redirect_to :action => 'contest_management' and return
321 redirect_to :action => 'contest_management' and return
322 end
322 end
323
323
324 note = []
324 note = []
325 users = []
325 users = []
326 lines.split("\n").each do |line|
326 lines.split("\n").each do |line|
327 user = User.find_by_login(line.chomp)
327 user = User.find_by_login(line.chomp)
328 if user
328 if user
329 if operation=='add'
329 if operation=='add'
330 if ! user.contests.include? contest
330 if ! user.contests.include? contest
331 user.contests << contest
331 user.contests << contest
332 end
332 end
333 elsif operation=='remove'
333 elsif operation=='remove'
334 user.contests.delete(contest)
334 user.contests.delete(contest)
335 else
335 else
336 user.contests = [contest]
336 user.contests = [contest]
337 end
337 end
338
338
339 if params[:reset_timer]
339 if params[:reset_timer]
340 user.contest_stat.forced_logout = true
340 user.contest_stat.forced_logout = true
341 user.contest_stat.reset_timer_and_save
341 user.contest_stat.reset_timer_and_save
342 end
342 end
343
343
344 if params[:notification_emails]
344 if params[:notification_emails]
345 send_contest_update_notification_email(user, contest)
345 send_contest_update_notification_email(user, contest)
346 end
346 end
347
347
348 note << user.login
348 note << user.login
349 users << user
349 users << user
350 end
350 end
351 end
351 end
352
352
353 if params[:reset_timer]
353 if params[:reset_timer]
354 logout_users(users)
354 logout_users(users)
355 end
355 end
356
356
357 flash[:notice] = 'User(s) ' + note.join(', ') +
357 flash[:notice] = 'User(s) ' + note.join(', ') +
358 ' were successfully modified. '
358 ' were successfully modified. '
359 redirect_to :action => 'contest_management'
359 redirect_to :action => 'contest_management'
360 end
360 end
361
361
362 # admin management
362 # admin management
363
363
364 def admin
364 def admin
365 - @admins = User.all.find_all {|user| user.admin? }
365 + @admins = Role.where(name: 'admin').take.users
366 + @tas = Role.where(name: 'ta').take.users
366 end
367 end
367
368
368 - def grant_admin
369 + def modify_role
369 - login = params[:login]
370 + user = User.find_by_login(params[:login])
370 - user = User.find_by_login(login)
371 + role = Role.find_by_name(params[:role])
371 - if user!=nil
372 + unless user && role
372 - admin_role = Role.find_by_name('admin')
373 + flash[:error] = 'Unknown user or role'
373 - user.roles << admin_role
374 + redirect_to admin_user_admin_index_path
374 - else
375 + return
375 - flash[:notice] = 'Unknown user'
376 end
376 end
377 - flash[:notice] = 'User added as admins'
377 + if params[:commit] == 'Grant'
378 - redirect_to :action => 'admin'
378 + #grant role
379 - end
379 + user.roles << role
380 -
380 + flash[:notice] = "User '#{user.login}' has been granted the role '#{role.name}'"
381 - def revoke_admin
381 + else
382 - user = User.find(params[:id])
382 + #revoke role
383 - if user==nil
383 + if user.login == 'root' && role.name == 'admin'
384 - flash[:notice] = 'Unknown user'
384 + flash[:error] = 'You cannot revoke admisnistrator permission from root.'
385 - redirect_to :action => 'admin' and return
385 + redirect_to admin_user_admin_index_path
386 - elsif user.login == 'root'
386 + return
387 - flash[:notice] = 'You cannot revoke admisnistrator permission from root.'
387 + end
388 - redirect_to :action => 'admin' and return
388 + user.roles.delete(role)
389 + flash[:notice] = "The role '#{role.name}' has been revoked from User '#{user.login}'"
389 end
390 end
390 -
391 + redirect_to admin_user_admin_index_path
391 - admin_role = Role.find_by_name('admin')
392 - user.roles.delete(admin_role)
393 - flash[:notice] = 'User permission revoked'
394 - redirect_to :action => 'admin'
395 end
392 end
396
393
397 # mass mailing
394 # mass mailing
398
395
399 def mass_mailing
396 def mass_mailing
400 end
397 end
401
398
402 def bulk_mail
399 def bulk_mail
403 lines = params[:login_list]
400 lines = params[:login_list]
404 if !lines or lines.blank?
401 if !lines or lines.blank?
405 flash[:notice] = 'You entered an empty list.'
402 flash[:notice] = 'You entered an empty list.'
406 redirect_to :action => 'mass_mailing' and return
403 redirect_to :action => 'mass_mailing' and return
407 end
404 end
408
405
409 mail_subject = params[:subject]
406 mail_subject = params[:subject]
410 if !mail_subject or mail_subject.blank?
407 if !mail_subject or mail_subject.blank?
411 flash[:notice] = 'You entered an empty mail subject.'
408 flash[:notice] = 'You entered an empty mail subject.'
412 redirect_to :action => 'mass_mailing' and return
409 redirect_to :action => 'mass_mailing' and return
413 end
410 end
414
411
415 mail_body = params[:email_body]
412 mail_body = params[:email_body]
416 if !mail_body or mail_body.blank?
413 if !mail_body or mail_body.blank?
417 flash[:notice] = 'You entered an empty mail body.'
414 flash[:notice] = 'You entered an empty mail body.'
418 redirect_to :action => 'mass_mailing' and return
415 redirect_to :action => 'mass_mailing' and return
419 end
416 end
420
417
421 note = []
418 note = []
422 users = []
419 users = []
423 lines.split("\n").each do |line|
420 lines.split("\n").each do |line|
424 user = User.find_by_login(line.chomp)
421 user = User.find_by_login(line.chomp)
425 if user
422 if user
426 send_mail(user.email, mail_subject, mail_body)
423 send_mail(user.email, mail_subject, mail_body)
427 note << user.login
424 note << user.login
428 end
425 end
429 end
426 end
430
427
431 flash[:notice] = 'User(s) ' + note.join(', ') +
428 flash[:notice] = 'User(s) ' + note.join(', ') +
432 ' were successfully modified. '
429 ' were successfully modified. '
433 redirect_to :action => 'mass_mailing'
430 redirect_to :action => 'mass_mailing'
434 end
431 end
435
432
436 #bulk manage
433 #bulk manage
437 def bulk_manage
434 def bulk_manage
438
435
439 begin
436 begin
440 @users = User.where('(login REGEXP ?) OR (remark REGEXP ?)',params[:regex],params[:regex]) if params[:regex]
437 @users = User.where('(login REGEXP ?) OR (remark REGEXP ?)',params[:regex],params[:regex]) if params[:regex]
441 @users.count if @users #i don't know why I have to call count, but if I won't exception is not raised
438 @users.count if @users #i don't know why I have to call count, but if I won't exception is not raised
442 rescue Exception
439 rescue Exception
443 flash[:error] = 'Regular Expression is malformed'
440 flash[:error] = 'Regular Expression is malformed'
444 @users = nil
441 @users = nil
445 end
442 end
446
443
447 if params[:commit]
444 if params[:commit]
448 @action = {}
445 @action = {}
449 @action[:set_enable] = params[:enabled]
446 @action[:set_enable] = params[:enabled]
450 @action[:enabled] = params[:enable] == "1"
447 @action[:enabled] = params[:enable] == "1"
451 @action[:gen_password] = params[:gen_password]
448 @action[:gen_password] = params[:gen_password]
452 @action[:add_group] = params[:add_group]
449 @action[:add_group] = params[:add_group]
453 @action[:group_name] = params[:group_name]
450 @action[:group_name] = params[:group_name]
454 end
451 end
455
452
456 if params[:commit] == "Perform"
453 if params[:commit] == "Perform"
457 if @action[:set_enable]
454 if @action[:set_enable]
458 @users.update_all(enabled: @action[:enabled])
455 @users.update_all(enabled: @action[:enabled])
459 end
456 end
460 if @action[:gen_password]
457 if @action[:gen_password]
461 @users.each do |u|
458 @users.each do |u|
462 password = random_password
459 password = random_password
463 u.password = password
460 u.password = password
464 u.password_confirmation = password
461 u.password_confirmation = password
465 u.save
462 u.save
466 end
463 end
467 end
464 end
468 if @action[:add_group] and @action[:group_name]
465 if @action[:add_group] and @action[:group_name]
469 @group = Group.find(@action[:group_name])
466 @group = Group.find(@action[:group_name])
470 ok = []
467 ok = []
471 failed = []
468 failed = []
472 @users.each do |user|
469 @users.each do |user|
473 begin
470 begin
474 @group.users << user
471 @group.users << user
475 ok << user.login
472 ok << user.login
476 rescue => e
473 rescue => e
477 failed << user.login
474 failed << user.login
478 end
475 end
479 end
476 end
480 flash[:success] = "The following users are added to the 'group #{@group.name}': " + ok.join(', ') if ok.count > 0
477 flash[:success] = "The following users are added to the 'group #{@group.name}': " + ok.join(', ') if ok.count > 0
481 flash[:alert] = "The following users are already in the 'group #{@group.name}': " + failed.join(', ') if failed.count > 0
478 flash[:alert] = "The following users are already in the 'group #{@group.name}': " + failed.join(', ') if failed.count > 0
482 end
479 end
483 end
480 end
484 end
481 end
485
482
486 protected
483 protected
487
484
488 def random_password(length=5)
485 def random_password(length=5)
489 chars = 'abcdefghijkmnopqrstuvwxyz23456789'
486 chars = 'abcdefghijkmnopqrstuvwxyz23456789'
490 newpass = ""
487 newpass = ""
@@ -1,180 +1,184
1 require 'digest/sha1'
1 require 'digest/sha1'
2 require 'net/pop'
2 require 'net/pop'
3 require 'net/https'
3 require 'net/https'
4 require 'net/http'
4 require 'net/http'
5 require 'json'
5 require 'json'
6
6
7 class User < ActiveRecord::Base
7 class User < ActiveRecord::Base
8
8
9 has_and_belongs_to_many :roles
9 has_and_belongs_to_many :roles
10
10
11 #has_and_belongs_to_many :groups
11 #has_and_belongs_to_many :groups
12 has_many :groups_users, class_name: 'GroupUser'
12 has_many :groups_users, class_name: 'GroupUser'
13 has_many :groups, :through => :groups_users
13 has_many :groups, :through => :groups_users
14
14
15 has_many :test_requests, -> {order(submitted_at: :desc)}
15 has_many :test_requests, -> {order(submitted_at: :desc)}
16
16
17 has_many :messages, -> { order(created_at: :desc) },
17 has_many :messages, -> { order(created_at: :desc) },
18 :class_name => "Message",
18 :class_name => "Message",
19 :foreign_key => "sender_id"
19 :foreign_key => "sender_id"
20
20
21 has_many :replied_messages, -> { order(created_at: :desc) },
21 has_many :replied_messages, -> { order(created_at: :desc) },
22 :class_name => "Message",
22 :class_name => "Message",
23 :foreign_key => "receiver_id"
23 :foreign_key => "receiver_id"
24
24
25 has_one :contest_stat, :class_name => "UserContestStat", :dependent => :destroy
25 has_one :contest_stat, :class_name => "UserContestStat", :dependent => :destroy
26
26
27 belongs_to :site
27 belongs_to :site
28 belongs_to :country
28 belongs_to :country
29
29
30 has_and_belongs_to_many :contests, -> { order(:name)}
30 has_and_belongs_to_many :contests, -> { order(:name)}
31
31
32 scope :activated_users, -> {where activated: true}
32 scope :activated_users, -> {where activated: true}
33
33
34 validates_presence_of :login
34 validates_presence_of :login
35 validates_uniqueness_of :login
35 validates_uniqueness_of :login
36 validates_format_of :login, :with => /\A[\_A-Za-z0-9]+\z/
36 validates_format_of :login, :with => /\A[\_A-Za-z0-9]+\z/
37 validates_length_of :login, :within => 3..30
37 validates_length_of :login, :within => 3..30
38
38
39 validates_presence_of :full_name
39 validates_presence_of :full_name
40 validates_length_of :full_name, :minimum => 1
40 validates_length_of :full_name, :minimum => 1
41
41
42 validates_presence_of :password, :if => :password_required?
42 validates_presence_of :password, :if => :password_required?
43 validates_length_of :password, :within => 4..50, :if => :password_required?
43 validates_length_of :password, :within => 4..50, :if => :password_required?
44 validates_confirmation_of :password, :if => :password_required?
44 validates_confirmation_of :password, :if => :password_required?
45
45
46 validates_format_of :email,
46 validates_format_of :email,
47 :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i,
47 :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i,
48 :if => :email_validation?
48 :if => :email_validation?
49 validate :uniqueness_of_email_from_activated_users,
49 validate :uniqueness_of_email_from_activated_users,
50 :if => :email_validation?
50 :if => :email_validation?
51 validate :enough_time_interval_between_same_email_registrations,
51 validate :enough_time_interval_between_same_email_registrations,
52 :if => :email_validation?
52 :if => :email_validation?
53
53
54 # these are for ytopc
54 # these are for ytopc
55 # disable for now
55 # disable for now
56 #validates_presence_of :province
56 #validates_presence_of :province
57
57
58 attr_accessor :password
58 attr_accessor :password
59
59
60 before_save :encrypt_new_password
60 before_save :encrypt_new_password
61 before_save :assign_default_site
61 before_save :assign_default_site
62 before_save :assign_default_contest
62 before_save :assign_default_contest
63
63
64 # this is for will_paginate
64 # this is for will_paginate
65 cattr_reader :per_page
65 cattr_reader :per_page
66 @@per_page = 50
66 @@per_page = 50
67
67
68 def self.authenticate(login, password)
68 def self.authenticate(login, password)
69 user = find_by_login(login)
69 user = find_by_login(login)
70 if user
70 if user
71 return user if user.authenticated?(password)
71 return user if user.authenticated?(password)
72 end
72 end
73 end
73 end
74
74
75 def authenticated?(password)
75 def authenticated?(password)
76 if self.activated
76 if self.activated
77 hashed_password == User.encrypt(password,self.salt)
77 hashed_password == User.encrypt(password,self.salt)
78 else
78 else
79 false
79 false
80 end
80 end
81 end
81 end
82
82
83 def admin?
83 def admin?
84 - self.roles.where(name: 'admin').count > 0
84 + has_role?('admin')
85 + end
86 +
87 + def has_role?(role)
88 + self.roles.where(name: role).count > 0
85 end
89 end
86
90
87 def email_for_editing
91 def email_for_editing
88 if self.email==nil
92 if self.email==nil
89 "(unknown)"
93 "(unknown)"
90 elsif self.email==''
94 elsif self.email==''
91 "(blank)"
95 "(blank)"
92 else
96 else
93 self.email
97 self.email
94 end
98 end
95 end
99 end
96
100
97 def email_for_editing=(e)
101 def email_for_editing=(e)
98 self.email=e
102 self.email=e
99 end
103 end
100
104
101 def alias_for_editing
105 def alias_for_editing
102 if self.alias==nil
106 if self.alias==nil
103 "(unknown)"
107 "(unknown)"
104 elsif self.alias==''
108 elsif self.alias==''
105 "(blank)"
109 "(blank)"
106 else
110 else
107 self.alias
111 self.alias
108 end
112 end
109 end
113 end
110
114
111 def alias_for_editing=(e)
115 def alias_for_editing=(e)
112 self.alias=e
116 self.alias=e
113 end
117 end
114
118
115 def activation_key
119 def activation_key
116 if self.hashed_password==nil
120 if self.hashed_password==nil
117 encrypt_new_password
121 encrypt_new_password
118 end
122 end
119 Digest::SHA1.hexdigest(self.hashed_password)[0..7]
123 Digest::SHA1.hexdigest(self.hashed_password)[0..7]
120 end
124 end
121
125
122 def verify_activation_key(key)
126 def verify_activation_key(key)
123 key == activation_key
127 key == activation_key
124 end
128 end
125
129
126 def self.random_password(length=5)
130 def self.random_password(length=5)
127 chars = 'abcdefghjkmnopqrstuvwxyz'
131 chars = 'abcdefghjkmnopqrstuvwxyz'
128 password = ''
132 password = ''
129 length.times { password << chars[rand(chars.length - 1)] }
133 length.times { password << chars[rand(chars.length - 1)] }
130 password
134 password
131 end
135 end
132
136
133 def self.find_non_admin_with_prefix(prefix='')
137 def self.find_non_admin_with_prefix(prefix='')
134 users = User.all
138 users = User.all
135 return users.find_all { |u| !(u.admin?) and u.login.index(prefix)==0 }
139 return users.find_all { |u| !(u.admin?) and u.login.index(prefix)==0 }
136 end
140 end
137
141
138 # Contest information
142 # Contest information
139
143
140 def self.find_users_with_no_contest()
144 def self.find_users_with_no_contest()
141 users = User.all
145 users = User.all
142 return users.find_all { |u| u.contests.length == 0 }
146 return users.find_all { |u| u.contests.length == 0 }
143 end
147 end
144
148
145
149
146 def contest_time_left
150 def contest_time_left
147 if GraderConfiguration.contest_mode?
151 if GraderConfiguration.contest_mode?
148 return nil if site==nil
152 return nil if site==nil
149 return site.time_left
153 return site.time_left
150 elsif GraderConfiguration.indv_contest_mode?
154 elsif GraderConfiguration.indv_contest_mode?
151 time_limit = GraderConfiguration.contest_time_limit
155 time_limit = GraderConfiguration.contest_time_limit
152 if time_limit == nil
156 if time_limit == nil
153 return nil
157 return nil
154 end
158 end
155 if contest_stat==nil or contest_stat.started_at==nil
159 if contest_stat==nil or contest_stat.started_at==nil
156 return (Time.now.gmtime + time_limit) - Time.now.gmtime
160 return (Time.now.gmtime + time_limit) - Time.now.gmtime
157 else
161 else
158 finish_time = contest_stat.started_at + time_limit
162 finish_time = contest_stat.started_at + time_limit
159 current_time = Time.now.gmtime
163 current_time = Time.now.gmtime
160 if current_time > finish_time
164 if current_time > finish_time
161 return 0
165 return 0
162 else
166 else
163 return finish_time - current_time
167 return finish_time - current_time
164 end
168 end
165 end
169 end
166 else
170 else
167 return nil
171 return nil
168 end
172 end
169 end
173 end
170
174
171 def contest_finished?
175 def contest_finished?
172 if GraderConfiguration.contest_mode?
176 if GraderConfiguration.contest_mode?
173 return false if site==nil
177 return false if site==nil
174 return site.finished?
178 return site.finished?
175 elsif GraderConfiguration.indv_contest_mode?
179 elsif GraderConfiguration.indv_contest_mode?
176 return false if self.contest_stat==nil
180 return false if self.contest_stat==nil
177 return contest_time_left == 0
181 return contest_time_left == 0
178 else
182 else
179 return false
183 return false
180 end
184 end
@@ -1,25 +1,54
1 - %h1 Administrators
1 + %h1 Modify Role
2 + .row
3 + .col-md-6
4 + %h4 Administrators
5 + = form_tag modify_role_user_admin_index_path, method: 'post', class: 'form-inline' do
6 + = hidden_field_tag :role, 'admin'
7 + .form-group
8 + = label_tag :login, 'Grant admin role to:'
9 + = text_field_tag 'login',nil, class: 'form-control'
10 + .form-group
11 + = submit_tag 'Grant', class: 'btn btn-primary'
12 + %br
13 + %table.table.table-condense.table-hover.table-striped.table-bordered
14 + %thead{:class => 'info-head'}
15 + %th #
16 + %th Login
17 + %th Full name
18 + %th
19 + - @admins.each_with_index do |user, i|
20 + %tr
21 + %td= i+1
22 + %td= user.login
23 + %td= user.full_name
24 + %td
25 + - if user.login!='root'
26 + = link_to '[revoke]', modify_role_user_admin_index_path( login: user.login, role: 'admin', commit: 'revoke')
27 + .col-md-6
28 + %h4 Teacher Assistants (TA)
29 + = form_tag modify_role_user_admin_index_path, method: 'post', class: 'form-inline' do
30 + = hidden_field_tag :role, 'TA'
31 + .form-group
32 + = label_tag :login, 'Grant TA role to:'
33 + = text_field_tag 'login',nil, class: 'form-control'
34 + .form-group
35 + = submit_tag 'Grant', class: 'btn btn-primary'
36 + %br
37 + %table.table.table-condense.table-hover.table-striped.table-bordered
38 + %thead{:class => 'info-head'}
39 + %th #
40 + %th Login
41 + %th Full name
42 + %th
43 + - @tas.each_with_index do |user, i|
44 + %tr
45 + %td= i+1
46 + %td= user.login
47 + %td= user.full_name
48 + %td
49 + - if user.login!='root'
50 + = link_to '[revoke]', modify_role_user_admin_index_path( login: user.login, role: 'TA', commit: 'revoke')
2
51
3 - %table{:class => 'info'}
4 - %tr{:class => 'info-head'}
5 - %th #
6 - %th Login
7 - %th Full name
8 - %th
9 - - @admins.each_with_index do |user, i|
10 - %tr
11 - %td= i+1
12 - %td= user.login
13 - %td= user.full_name
14 - %td
15 - - if user.login!='root'
16 - = link_to '[revoke]', :action => 'revoke_admin', :id => user.id
17 - %hr
18 -
19 - = form_tag :action => 'grant_admin' do
20 - = label_tag :login, 'Grant admin permission to:'
21 - = text_field_tag 'login',nil, class: 'input-field'
22 - = submit_tag 'Grant', class: 'btn btn-primary'
23
52
24 %hr/
53 %hr/
25 = link_to '[go back to index]', :action => 'index'
54 = link_to '[go back to index]', :action => 'index'
@@ -20,185 +20,184
20 get 'console'
20 get 'console'
21 get 'list_all'
21 get 'list_all'
22 end
22 end
23 end
23 end
24
24
25 resources :announcements do
25 resources :announcements do
26 member do
26 member do
27 get 'toggle','toggle_front'
27 get 'toggle','toggle_front'
28 end
28 end
29 end
29 end
30
30
31 resources :problems do
31 resources :problems do
32 member do
32 member do
33 get 'toggle'
33 get 'toggle'
34 get 'toggle_test'
34 get 'toggle_test'
35 get 'toggle_view_testcase'
35 get 'toggle_view_testcase'
36 get 'stat'
36 get 'stat'
37 end
37 end
38 collection do
38 collection do
39 get 'turn_all_off'
39 get 'turn_all_off'
40 get 'turn_all_on'
40 get 'turn_all_on'
41 get 'import'
41 get 'import'
42 get 'manage'
42 get 'manage'
43 get 'quick_create'
43 get 'quick_create'
44 post 'do_manage'
44 post 'do_manage'
45 post 'do_import'
45 post 'do_import'
46 end
46 end
47 end
47 end
48
48
49 resources :groups do
49 resources :groups do
50 member do
50 member do
51 post 'add_user', to: 'groups#add_user', as: 'add_user'
51 post 'add_user', to: 'groups#add_user', as: 'add_user'
52 delete 'remove_user/:user_id', to: 'groups#remove_user', as: 'remove_user'
52 delete 'remove_user/:user_id', to: 'groups#remove_user', as: 'remove_user'
53 delete 'remove_all_user', to: 'groups#remove_all_user', as: 'remove_all_user'
53 delete 'remove_all_user', to: 'groups#remove_all_user', as: 'remove_all_user'
54 post 'add_problem', to: 'groups#add_problem', as: 'add_problem'
54 post 'add_problem', to: 'groups#add_problem', as: 'add_problem'
55 delete 'remove_problem/:problem_id', to: 'groups#remove_problem', as: 'remove_problem'
55 delete 'remove_problem/:problem_id', to: 'groups#remove_problem', as: 'remove_problem'
56 delete 'remove_all_problem', to: 'groups#remove_all_problem', as: 'remove_all_problem'
56 delete 'remove_all_problem', to: 'groups#remove_all_problem', as: 'remove_all_problem'
57 get 'toggle'
57 get 'toggle'
58 end
58 end
59 collection do
59 collection do
60
60
61 end
61 end
62 end
62 end
63
63
64 resources :testcases, only: [] do
64 resources :testcases, only: [] do
65 member do
65 member do
66 get 'download_input'
66 get 'download_input'
67 get 'download_sol'
67 get 'download_sol'
68 end
68 end
69 collection do
69 collection do
70 get 'show_problem/:problem_id(/:test_num)' => 'testcases#show_problem', as: 'show_problem'
70 get 'show_problem/:problem_id(/:test_num)' => 'testcases#show_problem', as: 'show_problem'
71 end
71 end
72 end
72 end
73
73
74 resources :grader_configuration, controller: 'configurations' do
74 resources :grader_configuration, controller: 'configurations' do
75 collection do
75 collection do
76 get 'set_exam_right(/:value)', action: 'set_exam_right', as: 'set_exam_right'
76 get 'set_exam_right(/:value)', action: 'set_exam_right', as: 'set_exam_right'
77 end
77 end
78 end
78 end
79
79
80 resources :users do
80 resources :users do
81 member do
81 member do
82 get 'toggle_activate', 'toggle_enable'
82 get 'toggle_activate', 'toggle_enable'
83 get 'stat'
83 get 'stat'
84 end
84 end
85 collection do
85 collection do
86 get 'profile'
86 get 'profile'
87 post 'chg_passwd'
87 post 'chg_passwd'
88 end
88 end
89 end
89 end
90
90
91 resources :submissions do
91 resources :submissions do
92 member do
92 member do
93 get 'download'
93 get 'download'
94 get 'compiler_msg'
94 get 'compiler_msg'
95 get 'rejudge'
95 get 'rejudge'
96 end
96 end
97 collection do
97 collection do
98 get 'prob/:problem_id', to: 'submissions#index', as: 'problem'
98 get 'prob/:problem_id', to: 'submissions#index', as: 'problem'
99 get 'direct_edit_problem/:problem_id(/:user_id)', to: 'submissions#direct_edit_problem', as: 'direct_edit_problem'
99 get 'direct_edit_problem/:problem_id(/:user_id)', to: 'submissions#direct_edit_problem', as: 'direct_edit_problem'
100 get 'get_latest_submission_status/:uid/:pid', to: 'submissions#get_latest_submission_status', as: 'get_latest_submission_status'
100 get 'get_latest_submission_status/:uid/:pid', to: 'submissions#get_latest_submission_status', as: 'get_latest_submission_status'
101 end
101 end
102 end
102 end
103
103
104
104
105 #user admin
105 #user admin
106 resources :user_admin do
106 resources :user_admin do
107 collection do
107 collection do
108 match 'bulk_manage', via: [:get, :post]
108 match 'bulk_manage', via: [:get, :post]
109 get 'bulk_mail'
109 get 'bulk_mail'
110 get 'user_stat'
110 get 'user_stat'
111 get 'import'
111 get 'import'
112 get 'new_list'
112 get 'new_list'
113 get 'admin'
113 get 'admin'
114 get 'active'
114 get 'active'
115 get 'mass_mailing'
115 get 'mass_mailing'
116 - get 'revoke_admin'
116 + match 'modify_role', via: [:get, :post]
117 - post 'grant_admin'
118 match 'create_from_list', via: [:get, :post]
117 match 'create_from_list', via: [:get, :post]
119 match 'random_all_passwords', via: [:get, :post]
118 match 'random_all_passwords', via: [:get, :post]
120 end
119 end
121 member do
120 member do
122 get 'clear_last_ip'
121 get 'clear_last_ip'
123 end
122 end
124 end
123 end
125
124
126 resources :contest_management, only: [:index] do
125 resources :contest_management, only: [:index] do
127 collection do
126 collection do
128 get 'user_stat'
127 get 'user_stat'
129 get 'clear_stat'
128 get 'clear_stat'
130 get 'clear_all_stat'
129 get 'clear_all_stat'
131 get 'change_contest_mode'
130 get 'change_contest_mode'
132 end
131 end
133 end
132 end
134
133
135 #get 'user_admin', to: 'user_admin#index'
134 #get 'user_admin', to: 'user_admin#index'
136 #get 'user_admin/bulk_manage', to: 'user_admin#bulk_manage', as: 'bulk_manage_user_admin'
135 #get 'user_admin/bulk_manage', to: 'user_admin#bulk_manage', as: 'bulk_manage_user_admin'
137 #post 'user_admin', to: 'user_admin#create'
136 #post 'user_admin', to: 'user_admin#create'
138 #delete 'user_admin/:id', to: 'user_admin#destroy', as: 'user_admin_destroy'
137 #delete 'user_admin/:id', to: 'user_admin#destroy', as: 'user_admin_destroy'
139
138
140 #singular resource
139 #singular resource
141 #---- BEWARE ---- singular resource maps to plural controller by default, we can override by provide controller name directly
140 #---- BEWARE ---- singular resource maps to plural controller by default, we can override by provide controller name directly
142 #report
141 #report
143 resource :report, only: [], controller: 'report' do
142 resource :report, only: [], controller: 'report' do
144 get 'login'
143 get 'login'
145 get 'multiple_login'
144 get 'multiple_login'
146 get 'problem_hof(/:id)', action: 'problem_hof', as: 'problem_hof'
145 get 'problem_hof(/:id)', action: 'problem_hof', as: 'problem_hof'
147 get 'current_score(/:group_id)', action: 'current_score', as: 'current_score'
146 get 'current_score(/:group_id)', action: 'current_score', as: 'current_score'
148 get 'max_score'
147 get 'max_score'
149 post 'show_max_score'
148 post 'show_max_score'
150 get 'stuck'
149 get 'stuck'
151 get 'cheat_report'
150 get 'cheat_report'
152 post 'cheat_report'
151 post 'cheat_report'
153 get 'cheat_scruntinize'
152 get 'cheat_scruntinize'
154 post 'cheat_scruntinize'
153 post 'cheat_scruntinize'
155 end
154 end
156 #get 'report/current_score', to: 'report#current_score', as: 'report_current_score'
155 #get 'report/current_score', to: 'report#current_score', as: 'report_current_score'
157 #get 'report/problem_hof(/:id)', to: 'report#problem_hof', as: 'report_problem_hof'
156 #get 'report/problem_hof(/:id)', to: 'report#problem_hof', as: 'report_problem_hof'
158 #get "report/login"
157 #get "report/login"
159 #get 'report/max_score', to: 'report#max_score', as: 'report_max_score'
158 #get 'report/max_score', to: 'report#max_score', as: 'report_max_score'
160 #post 'report/show_max_score', to: 'report#show_max_score', as: 'report_show_max_score'
159 #post 'report/show_max_score', to: 'report#show_max_score', as: 'report_show_max_score'
161
160
162 resource :main, only: [], controller: 'main' do
161 resource :main, only: [], controller: 'main' do
163 get 'login'
162 get 'login'
164 get 'logout'
163 get 'logout'
165 get 'list'
164 get 'list'
166 get 'submission(/:id)', action: 'submission', as: 'main_submission'
165 get 'submission(/:id)', action: 'submission', as: 'main_submission'
167 get 'announcements'
166 get 'announcements'
168 get 'help'
167 get 'help'
169 post 'submit'
168 post 'submit'
170 end
169 end
171 #main
170 #main
172 #get "main/list"
171 #get "main/list"
173 #get 'main/submission(/:id)', to: 'main#submission', as: 'main_submission'
172 #get 'main/submission(/:id)', to: 'main#submission', as: 'main_submission'
174 #post 'main/submit', to: 'main#submit'
173 #post 'main/submit', to: 'main#submit'
175 #get 'main/announcements', to: 'main#announcements'
174 #get 'main/announcements', to: 'main#announcements'
176
175
177
176
178 #
177 #
179 get 'tasks/view/:file.:ext' => 'tasks#view'
178 get 'tasks/view/:file.:ext' => 'tasks#view'
180 get 'tasks/download/:id/:file.:ext' => 'tasks#download', as: 'download_task'
179 get 'tasks/download/:id/:file.:ext' => 'tasks#download', as: 'download_task'
181 get 'heartbeat/:id/edit' => 'heartbeat#edit'
180 get 'heartbeat/:id/edit' => 'heartbeat#edit'
182
181
183 #grader
182 #grader
184 get 'graders/list', to: 'graders#list', as: 'grader_list'
183 get 'graders/list', to: 'graders#list', as: 'grader_list'
185 namespace :graders do
184 namespace :graders do
186 get 'task/:id/:type', action: 'task', as: 'task'
185 get 'task/:id/:type', action: 'task', as: 'task'
187 get 'view/:id/:type', action: 'view', as: 'view'
186 get 'view/:id/:type', action: 'view', as: 'view'
188 get 'clear/:id', action: 'clear', as: 'clear'
187 get 'clear/:id', action: 'clear', as: 'clear'
189 get 'stop'
188 get 'stop'
190 get 'stop_all'
189 get 'stop_all'
191 get 'clear_all'
190 get 'clear_all'
192 get 'clear_terminated'
191 get 'clear_terminated'
193 get 'start_grading'
192 get 'start_grading'
194 get 'start_exam'
193 get 'start_exam'
195
194
196 end
195 end
197
196
198
197
199 # See how all your routes lay out with "rake routes"
198 # See how all your routes lay out with "rake routes"
200
199
201 # This is a legacy wild controller route that's not recommended for RESTful applications.
200 # This is a legacy wild controller route that's not recommended for RESTful applications.
202 # Note: This route will make all actions in every controller accessible via GET requests.
201 # Note: This route will make all actions in every controller accessible via GET requests.
203 # match ':controller(/:action(/:id))(.:format)', via: [:get, :post]
202 # match ':controller(/:action(/:id))(.:format)', via: [:get, :post]
204 end
203 end
@@ -132,157 +132,158
132 },
132 },
133
133
134 {
134 {
135 :key => 'system.user_setting_enabled',
135 :key => 'system.user_setting_enabled',
136 :value_type => 'boolean',
136 :value_type => 'boolean',
137 :default_value => 'true',
137 :default_value => 'true',
138 :description => 'If this option is true, users can change their settings'
138 :description => 'If this option is true, users can change their settings'
139 },
139 },
140
140
141 {
141 {
142 :key => 'system.user_setting_enabled',
142 :key => 'system.user_setting_enabled',
143 :value_type => 'boolean',
143 :value_type => 'boolean',
144 :default_value => 'true',
144 :default_value => 'true',
145 :description => 'If this option is true, users can change their settings'
145 :description => 'If this option is true, users can change their settings'
146 },
146 },
147
147
148 # If Configuration['contest.test_request.early_timeout'] is true
148 # If Configuration['contest.test_request.early_timeout'] is true
149 # the user will not be able to use test request at 30 minutes
149 # the user will not be able to use test request at 30 minutes
150 # before the contest ends.
150 # before the contest ends.
151 {
151 {
152 :key => 'contest.test_request.early_timeout',
152 :key => 'contest.test_request.early_timeout',
153 :value_type => 'boolean',
153 :value_type => 'boolean',
154 :default_value => 'false'
154 :default_value => 'false'
155 },
155 },
156
156
157 {
157 {
158 :key => 'system.multicontests',
158 :key => 'system.multicontests',
159 :value_type => 'boolean',
159 :value_type => 'boolean',
160 :default_value => 'false'
160 :default_value => 'false'
161 },
161 },
162
162
163 {
163 {
164 :key => 'contest.confirm_indv_contest_start',
164 :key => 'contest.confirm_indv_contest_start',
165 :value_type => 'boolean',
165 :value_type => 'boolean',
166 :default_value => 'false'
166 :default_value => 'false'
167 },
167 },
168
168
169 {
169 {
170 :key => 'contest.default_contest_name',
170 :key => 'contest.default_contest_name',
171 :value_type => 'string',
171 :value_type => 'string',
172 :default_value => 'none',
172 :default_value => 'none',
173 :description => "New user will be assigned to this contest automatically, if it exists. Set to 'none' if there is no default contest."
173 :description => "New user will be assigned to this contest automatically, if it exists. Set to 'none' if there is no default contest."
174 },
174 },
175
175
176 {
176 {
177 :key => 'system.use_problem_group',
177 :key => 'system.use_problem_group',
178 :value_type => 'boolean',
178 :value_type => 'boolean',
179 :default_value => 'false',
179 :default_value => 'false',
180 :description => "If true, available problem to the user will be only ones associated with the group of the user."
180 :description => "If true, available problem to the user will be only ones associated with the group of the user."
181 },
181 },
182
182
183
183
184 {
184 {
185 :key => 'right.whitelist_ignore',
185 :key => 'right.whitelist_ignore',
186 :value_type => 'boolean',
186 :value_type => 'boolean',
187 :default_value => 'true',
187 :default_value => 'true',
188 :description => "If true, no IP check against whitelist_ip is perform. However, when false, non-admin user must have their ip in 'whitelist_ip' to be able to login."
188 :description => "If true, no IP check against whitelist_ip is perform. However, when false, non-admin user must have their ip in 'whitelist_ip' to be able to login."
189 },
189 },
190
190
191 {
191 {
192 :key => 'right.whitelist_ip',
192 :key => 'right.whitelist_ip',
193 :value_type => 'string',
193 :value_type => 'string',
194 :default_value => '0.0.0.0/0',
194 :default_value => '0.0.0.0/0',
195 :description => "list of whitelist ip, given in comma separated CIDR notation. For example '192.168.90.0/23, 192.168.1.23/32'"
195 :description => "list of whitelist ip, given in comma separated CIDR notation. For example '192.168.90.0/23, 192.168.1.23/32'"
196 },
196 },
197
197
198 ]
198 ]
199
199
200
200
201 def create_configuration_key(key,
201 def create_configuration_key(key,
202 value_type,
202 value_type,
203 default_value,
203 default_value,
204 description='')
204 description='')
205 conf = (GraderConfiguration.find_by_key(key) ||
205 conf = (GraderConfiguration.find_by_key(key) ||
206 GraderConfiguration.new(:key => key,
206 GraderConfiguration.new(:key => key,
207 :value_type => value_type,
207 :value_type => value_type,
208 :value => default_value))
208 :value => default_value))
209 conf.description = description
209 conf.description = description
210 conf.save
210 conf.save
211 end
211 end
212
212
213 def seed_config
213 def seed_config
214 CONFIGURATIONS.each do |conf|
214 CONFIGURATIONS.each do |conf|
215 if conf.has_key? :description
215 if conf.has_key? :description
216 desc = conf[:description]
216 desc = conf[:description]
217 else
217 else
218 desc = ''
218 desc = ''
219 end
219 end
220 create_configuration_key(conf[:key],
220 create_configuration_key(conf[:key],
221 conf[:value_type],
221 conf[:value_type],
222 conf[:default_value],
222 conf[:default_value],
223 desc)
223 desc)
224 end
224 end
225 end
225 end
226
226
227 def seed_roles
227 def seed_roles
228 + Role.find_or_create_by(name: 'TA')
228 return if Role.find_by_name('admin')
229 return if Role.find_by_name('admin')
229
230
230 role = Role.create(:name => 'admin')
231 role = Role.create(:name => 'admin')
231 user_admin_right = Right.create(:name => 'user_admin',
232 user_admin_right = Right.create(:name => 'user_admin',
232 :controller => 'user_admin',
233 :controller => 'user_admin',
233 :action => 'all')
234 :action => 'all')
234 problem_admin_right = Right.create(:name=> 'problem_admin',
235 problem_admin_right = Right.create(:name=> 'problem_admin',
235 :controller => 'problems',
236 :controller => 'problems',
236 :action => 'all')
237 :action => 'all')
237
238
238 graders_right = Right.create(:name => 'graders_admin',
239 graders_right = Right.create(:name => 'graders_admin',
239 :controller => 'graders',
240 :controller => 'graders',
240 :action => 'all')
241 :action => 'all')
241
242
242 role.rights << user_admin_right;
243 role.rights << user_admin_right;
243 role.rights << problem_admin_right;
244 role.rights << problem_admin_right;
244 role.rights << graders_right;
245 role.rights << graders_right;
245 role.save
246 role.save
246 end
247 end
247
248
248 def seed_root
249 def seed_root
249 return if User.find_by_login('root')
250 return if User.find_by_login('root')
250
251
251 root = User.new(:login => 'root',
252 root = User.new(:login => 'root',
252 :full_name => 'Administrator',
253 :full_name => 'Administrator',
253 :alias => 'root')
254 :alias => 'root')
254 root.password = 'ioionrails';
255 root.password = 'ioionrails';
255
256
256 class << root
257 class << root
257 public :encrypt_new_password
258 public :encrypt_new_password
258 def valid?(context=nil)
259 def valid?(context=nil)
259 true
260 true
260 end
261 end
261 end
262 end
262
263
263 root.encrypt_new_password
264 root.encrypt_new_password
264
265
265 root.roles << Role.find_by_name('admin')
266 root.roles << Role.find_by_name('admin')
266
267
267 root.activated = true
268 root.activated = true
268 root.save
269 root.save
269 end
270 end
270
271
271 def seed_users_and_roles
272 def seed_users_and_roles
272 seed_roles
273 seed_roles
273 seed_root
274 seed_root
274 end
275 end
275
276
276 def seed_more_languages
277 def seed_more_languages
277 #Language.delete_all
278 #Language.delete_all
278 Language.find_or_create_by( name: 'c', pretty_name: 'C', ext: 'c', common_ext: 'c' )
279 Language.find_or_create_by( name: 'c', pretty_name: 'C', ext: 'c', common_ext: 'c' )
279 Language.find_or_create_by( name: 'cpp', pretty_name: 'C++', ext: 'cpp', common_ext: 'cpp,cc' )
280 Language.find_or_create_by( name: 'cpp', pretty_name: 'C++', ext: 'cpp', common_ext: 'cpp,cc' )
280 Language.find_or_create_by( name: 'pas', pretty_name: 'Pascal', ext: 'pas', common_ext: 'pas' )
281 Language.find_or_create_by( name: 'pas', pretty_name: 'Pascal', ext: 'pas', common_ext: 'pas' )
281 Language.find_or_create_by( name: 'ruby', pretty_name: 'Ruby', ext: 'rb', common_ext: 'rb' )
282 Language.find_or_create_by( name: 'ruby', pretty_name: 'Ruby', ext: 'rb', common_ext: 'rb' )
282 Language.find_or_create_by( name: 'python', pretty_name: 'Python', ext: 'py', common_ext: 'py' )
283 Language.find_or_create_by( name: 'python', pretty_name: 'Python', ext: 'py', common_ext: 'py' )
283 Language.find_or_create_by( name: 'java', pretty_name: 'Java', ext: 'java', common_ext: 'java' )
284 Language.find_or_create_by( name: 'java', pretty_name: 'Java', ext: 'java', common_ext: 'java' )
284 end
285 end
285
286
286 seed_config
287 seed_config
287 seed_users_and_roles
288 seed_users_and_roles
288 seed_more_languages
289 seed_more_languages
You need to be logged in to leave comments. Login now