Description:
Merge branch 'master' into codejom (user stat reset) Conflicts: app/models/user.rb
Commit status:
[Not Reviewed]
References:
merge default
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r248:0f32f3dd1054 - - 2 files changed: 9 inserted, 1 deleted

@@ -1,30 +1,38
1 class ContestsController < ApplicationController
1 class ContestsController < ApplicationController
2
2
3 before_filter :admin_authorization
3 before_filter :admin_authorization
4
4
5 def index
5 def index
6 end
6 end
7
7
8 def user_stat
8 def user_stat
9 if not Configuration.indv_contest_mode?
9 if not Configuration.indv_contest_mode?
10 redirect_to :action => 'index' and return
10 redirect_to :action => 'index' and return
11 end
11 end
12
12
13 @users = User.find(:all)
13 @users = User.find(:all)
14 @start_times = {}
14 @start_times = {}
15 UserContestStat.find(:all).each do |stat|
15 UserContestStat.find(:all).each do |stat|
16 @start_times[stat.user_id] = stat.started_at
16 @start_times[stat.user_id] = stat.started_at
17 end
17 end
18 end
18 end
19
19
20 + def clear_stat
21 + user = User.find(params[:id])
22 + if user.contest_stat!=nil
23 + user.contest_stat.destroy
24 + end
25 + redirect_to :action => 'user_stat'
26 + end
27 +
20 def clear_all_stat
28 def clear_all_stat
21 if not Configuration.indv_contest_mode?
29 if not Configuration.indv_contest_mode?
22 redirect_to :action => 'index' and return
30 redirect_to :action => 'index' and return
23 end
31 end
24
32
25 UserContestStat.delete_all()
33 UserContestStat.delete_all()
26 flash[:notice] = 'All start time statistic cleared.'
34 flash[:notice] = 'All start time statistic cleared.'
27 redirect_to :action => 'index'
35 redirect_to :action => 'index'
28 end
36 end
29
37
30 end
38 end
@@ -1,119 +1,119
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 require 'digest/sha1'
2 require 'digest/sha1'
3
3
4 class User < ActiveRecord::Base
4 class User < ActiveRecord::Base
5
5
6 has_and_belongs_to_many :roles
6 has_and_belongs_to_many :roles
7
7
8 has_many :test_requests, :order => "submitted_at DESC"
8 has_many :test_requests, :order => "submitted_at DESC"
9
9
10 has_many :messages,
10 has_many :messages,
11 :class_name => "Message",
11 :class_name => "Message",
12 :foreign_key => "sender_id",
12 :foreign_key => "sender_id",
13 :order => 'created_at DESC'
13 :order => 'created_at DESC'
14
14
15 has_many :replied_messages,
15 has_many :replied_messages,
16 :class_name => "Message",
16 :class_name => "Message",
17 :foreign_key => "receiver_id",
17 :foreign_key => "receiver_id",
18 :order => 'created_at DESC'
18 :order => 'created_at DESC'
19
19
20 has_many :test_pair_assignments, :dependent => :delete_all
20 has_many :test_pair_assignments, :dependent => :delete_all
21 has_many :submission_statuses
21 has_many :submission_statuses
22
22
23 - has_one :contest_stat, :class_name => "UserContestStat"
23 + has_one :contest_stat, :class_name => "UserContestStat", :dependent => :destroy
24
24
25 belongs_to :site
25 belongs_to :site
26 belongs_to :country
26 belongs_to :country
27
27
28 # For Code Jom
28 # For Code Jom
29 has_one :codejom_status
29 has_one :codejom_status
30
30
31 named_scope :activated_users, :conditions => {:activated => true}
31 named_scope :activated_users, :conditions => {:activated => true}
32
32
33 validates_presence_of :login
33 validates_presence_of :login
34 validates_uniqueness_of :login
34 validates_uniqueness_of :login
35 validates_format_of :login, :with => /^[\_A-Za-z0-9]+$/
35 validates_format_of :login, :with => /^[\_A-Za-z0-9]+$/
36 validates_length_of :login, :within => 3..20
36 validates_length_of :login, :within => 3..20
37
37
38 validates_presence_of :full_name
38 validates_presence_of :full_name
39 validates_length_of :full_name, :minimum => 1
39 validates_length_of :full_name, :minimum => 1
40
40
41 validates_presence_of :member1_full_name
41 validates_presence_of :member1_full_name
42 validates_length_of :member1_full_name, :minimum => 1
42 validates_length_of :member1_full_name, :minimum => 1
43
43
44 validates_presence_of :password, :if => :password_required?
44 validates_presence_of :password, :if => :password_required?
45 validates_length_of :password, :within => 4..20, :if => :password_required?
45 validates_length_of :password, :within => 4..20, :if => :password_required?
46 validates_confirmation_of :password, :if => :password_required?
46 validates_confirmation_of :password, :if => :password_required?
47
47
48 validates_format_of :email,
48 validates_format_of :email,
49 :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i,
49 :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i,
50 :if => :email_validation?
50 :if => :email_validation?
51 validate :uniqueness_of_email_from_activated_users,
51 validate :uniqueness_of_email_from_activated_users,
52 :if => :email_validation?
52 :if => :email_validation?
53 validate :enough_time_interval_between_same_email_registrations,
53 validate :enough_time_interval_between_same_email_registrations,
54 :if => :email_validation?
54 :if => :email_validation?
55
55
56 validate :school_names_for_high_school_users
56 validate :school_names_for_high_school_users
57
57
58 # these are for ytopc
58 # these are for ytopc
59 # disable for now
59 # disable for now
60 #validates_presence_of :province
60 #validates_presence_of :province
61
61
62 attr_accessor :password
62 attr_accessor :password
63
63
64 before_save :encrypt_new_password
64 before_save :encrypt_new_password
65 before_save :assign_default_site
65 before_save :assign_default_site
66
66
67 def self.authenticate(login, password)
67 def self.authenticate(login, password)
68 user = find_by_login(login)
68 user = find_by_login(login)
69 return user if user && user.authenticated?(password)
69 return user if user && user.authenticated?(password)
70 end
70 end
71
71
72 def authenticated?(password)
72 def authenticated?(password)
73 if self.activated
73 if self.activated
74 hashed_password == User.encrypt(password,self.salt)
74 hashed_password == User.encrypt(password,self.salt)
75 else
75 else
76 false
76 false
77 end
77 end
78 end
78 end
79
79
80 def admin?
80 def admin?
81 self.roles.detect {|r| r.name == 'admin' }
81 self.roles.detect {|r| r.name == 'admin' }
82 end
82 end
83
83
84 # These are methods related to test pairs
84 # These are methods related to test pairs
85
85
86 def get_test_pair_assignments_for(problem)
86 def get_test_pair_assignments_for(problem)
87 test_pair_assignments.find_all { |a| a.problem_id == problem.id }
87 test_pair_assignments.find_all { |a| a.problem_id == problem.id }
88 end
88 end
89
89
90 def get_recent_test_pair_assignment_for(problem)
90 def get_recent_test_pair_assignment_for(problem)
91 assignments = get_test_pair_assignments_for problem
91 assignments = get_test_pair_assignments_for problem
92 if assignments.length == 0
92 if assignments.length == 0
93 return nil
93 return nil
94 else
94 else
95 recent = assignments[0]
95 recent = assignments[0]
96 assignments.each do |a|
96 assignments.each do |a|
97 recent = a if a.request_number > recent.request_number
97 recent = a if a.request_number > recent.request_number
98 end
98 end
99 return recent
99 return recent
100 end
100 end
101 end
101 end
102
102
103 def can_request_new_test_pair_for?(problem)
103 def can_request_new_test_pair_for?(problem)
104 recent = get_recent_test_pair_assignment_for problem
104 recent = get_recent_test_pair_assignment_for problem
105 return (recent == nil or recent.submitted or recent.expired?)
105 return (recent == nil or recent.submitted or recent.expired?)
106 end
106 end
107
107
108 def get_new_test_pair_assignment_for(problem)
108 def get_new_test_pair_assignment_for(problem)
109 previous_assignment_numbers =
109 previous_assignment_numbers =
110 get_test_pair_assignments_for(problem).collect {|a| a.test_pair_number }
110 get_test_pair_assignments_for(problem).collect {|a| a.test_pair_number }
111 test_pair = problem.random_test_pair(previous_assignment_numbers)
111 test_pair = problem.random_test_pair(previous_assignment_numbers)
112 if test_pair
112 if test_pair
113 assignment = TestPairAssignment.new(:user => self,
113 assignment = TestPairAssignment.new(:user => self,
114 :problem => problem,
114 :problem => problem,
115 :test_pair => test_pair,
115 :test_pair => test_pair,
116 :test_pair_number => test_pair.number,
116 :test_pair_number => test_pair.number,
117 :request_number =>
117 :request_number =>
118 previous_assignment_numbers.length + 1,
118 previous_assignment_numbers.length + 1,
119 :submitted => false)
119 :submitted => false)
You need to be logged in to leave comments. Login now