Description:
logs out users after contests changed
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r294:069c049fbc3a - - 22 files changed: 191 inserted, 192 deleted
@@ -0,0 +1,87 | |||
|
1 | + require 'spec_helper' | |
|
2 | + require 'config_spec_helper' | |
|
3 | + require 'delorean' | |
|
4 | + | |
|
5 | + describe "ContestManagements" do | |
|
6 | + include ConfigSpecHelperMethods | |
|
7 | + | |
|
8 | + fixtures :users | |
|
9 | + fixtures :problems | |
|
10 | + fixtures :contests | |
|
11 | + fixtures :roles | |
|
12 | + | |
|
13 | + before(:each) do | |
|
14 | + @admin_user = users(:mary) | |
|
15 | + @contest_b = contests(:contest_b) | |
|
16 | + @james = users(:james) | |
|
17 | + @jack = users(:jack) | |
|
18 | + | |
|
19 | + set_contest_time_limit('3:00') | |
|
20 | + set_indv_contest_mode | |
|
21 | + end | |
|
22 | + | |
|
23 | + it "should reset users' timer when their contests change" do | |
|
24 | + james_session = open_session | |
|
25 | + james_session.extend(MainSessionMethods) | |
|
26 | + | |
|
27 | + james_login_and_get_main_list(james_session) | |
|
28 | + james_session.response.should_not have_text(/OVER/) | |
|
29 | + | |
|
30 | + Delorean.time_travel_to(190.minutes.since) do | |
|
31 | + james_session.get_main_list | |
|
32 | + james_session.response.should have_text(/OVER/) | |
|
33 | + | |
|
34 | + james_session.get '/' # logout | |
|
35 | + james_session.get '/main/list' # clearly log out | |
|
36 | + james_session.response.should_not render_template 'main/list' | |
|
37 | + | |
|
38 | + admin_change_users_contest_to("james", @contest_b, true) | |
|
39 | + | |
|
40 | + james_login_and_get_main_list(james_session) | |
|
41 | + james_session.response.should_not have_text(/OVER/) | |
|
42 | + end | |
|
43 | + end | |
|
44 | + | |
|
45 | + private | |
|
46 | + | |
|
47 | + module MainSessionMethods | |
|
48 | + def login(login_name, password) | |
|
49 | + post '/login/login', :login => login_name, :password => password | |
|
50 | + assert_redirected_to '/main/list' | |
|
51 | + end | |
|
52 | + | |
|
53 | + def get_main_list | |
|
54 | + get '/main/list' | |
|
55 | + assert_template 'main/list' | |
|
56 | + end | |
|
57 | + end | |
|
58 | + | |
|
59 | + module ContestManagementSessionMethods | |
|
60 | + def change_users_contest_to(user_login_list, contest, reset_timer=false) | |
|
61 | + post_data = { | |
|
62 | + :contest => {:id => contest.id}, | |
|
63 | + :operation => 'assign', | |
|
64 | + :login_list => user_login_list | |
|
65 | + } | |
|
66 | + post_data[:reset_timer] = true if reset_timer | |
|
67 | + post '/user_admin/manage_contest', post_data | |
|
68 | + end | |
|
69 | + end | |
|
70 | + | |
|
71 | + def admin_change_users_contest_to(user_list, contest, reset_timer) | |
|
72 | + admin_session = open_session | |
|
73 | + admin_session.extend(MainSessionMethods) | |
|
74 | + admin_session.extend(ContestManagementSessionMethods) | |
|
75 | + | |
|
76 | + admin_session.login('mary','goodbye') | |
|
77 | + admin_session.get '/main/list' | |
|
78 | + admin_session.change_users_contest_to(user_list, contest, reset_timer) | |
|
79 | + end | |
|
80 | + | |
|
81 | + def james_login_and_get_main_list(session) | |
|
82 | + session.login('james', 'morning') | |
|
83 | + session.get_main_list | |
|
84 | + end | |
|
85 | + | |
|
86 | + end | |
|
87 | + |
@@ -196,24 +196,31 | |||
|
196 | 196 | end |
|
197 | 197 | |
|
198 | 198 | note = [] |
|
199 | + user_ids = {} | |
|
199 | 200 | lines.split("\n").each do |line| |
|
200 | - puts line | |
|
201 | 201 | user = User.find_by_login(line.chomp) |
|
202 | - puts user | |
|
203 | 202 | if user |
|
204 | 203 | if operation=='add' |
|
205 |
- user.contests |
|
|
204 | + if ! user.contests.include? contest | |
|
205 | + user.contests << contest | |
|
206 | + end | |
|
206 | 207 | elsif operation=='remove' |
|
207 | 208 | user.contests.delete(contest) |
|
208 | 209 | else |
|
209 | 210 | user.contests = [contest] |
|
210 | 211 | end |
|
211 | - | |
|
212 | + | |
|
212 | 213 | user.contest_stat.destroy if params[:reset_timer] |
|
213 | 214 | |
|
214 | 215 | note << user.login |
|
216 | + user_ids[user.id] = true | |
|
215 | 217 | end |
|
216 | 218 | end |
|
219 | + | |
|
220 | + if params[:reset_timer] | |
|
221 | + logout_users(user_ids) | |
|
222 | + end | |
|
223 | + | |
|
217 | 224 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
218 | 225 | ' were successfully modified. ' |
|
219 | 226 | redirect_to :action => 'contest_management' |
@@ -324,4 +331,13 | |||
|
324 | 331 | |
|
325 | 332 | end |
|
326 | 333 | |
|
334 | + def logout_users(user_ids) | |
|
335 | + sessions = ActiveRecord::SessionStore::Session.find(:all, :conditions => ["updated_at >= ?", 60.minutes.ago]) | |
|
336 | + sessions.each do |session| | |
|
337 | + if user_ids.has_key? session.data[:user_id] | |
|
338 | + session.destroy | |
|
339 | + end | |
|
340 | + end | |
|
341 | + end | |
|
342 | + | |
|
327 | 343 | end |
@@ -7,6 +7,8 | |||
|
7 | 7 | |
|
8 | 8 | SYSTEM_MODE_CONF_KEY = 'system.mode' |
|
9 | 9 | TEST_REQUEST_EARLY_TIMEOUT_KEY = 'contest.test_request.early_timeout' |
|
10 | + MULTICONTESTS_KEY = 'system.multicontests' | |
|
11 | + CONTEST_TIME_LIMIT_KEY = 'contest.time_limit' | |
|
10 | 12 | |
|
11 | 13 | cattr_accessor :cache |
|
12 | 14 | cattr_accessor :config_cache |
@@ -107,8 +109,7 | |||
|
107 | 109 | end |
|
108 | 110 | |
|
109 | 111 | def self.multicontests? |
|
110 | - g = get('system.multicontests') | |
|
111 | - return get('system.multicontests') == true | |
|
112 | + return get(MULTICONTESTS_KEY) == true | |
|
112 | 113 | end |
|
113 | 114 | |
|
114 | 115 | def self.time_limit_mode? |
@@ -121,7 +122,7 | |||
|
121 | 122 | end |
|
122 | 123 | |
|
123 | 124 | def self.contest_time_limit |
|
124 |
- contest_time_str = Configuration[ |
|
|
125 | + contest_time_str = Configuration[CONTEST_TIME_LIMIT_KEY] | |
|
125 | 126 | |
|
126 | 127 | if not defined? Configuration.contest_time_str |
|
127 | 128 | Configuration.contest_time_str = nil |
@@ -154,10 +154,7 | |||
|
154 | 154 | return false if site==nil |
|
155 | 155 | return site.finished? |
|
156 | 156 | elsif Configuration.indv_contest_mode? |
|
157 | - time_limit = Configuration.contest_time_limit | |
|
158 | - | |
|
159 | - return false if contest_stat==nil | |
|
160 | - | |
|
157 | + return false if self.contest_stat(true)==nil | |
|
161 | 158 | return contest_time_left == 0 |
|
162 | 159 | else |
|
163 | 160 | return false |
@@ -29,7 +29,7 | |||
|
29 | 29 | :key => 'contest.time_limit', |
|
30 | 30 | :value_type => 'string', |
|
31 | 31 | :default_value => 'unlimited', |
|
32 | - :description => 'Time limit in format hh:mm, or "unlimited" for contests with no time limits.' | |
|
32 | + :description => 'Time limit in format hh:mm, or "unlimited" for contests with no time limits. This config is CACHED. Restart the server before the change can take effect.' | |
|
33 | 33 | }, |
|
34 | 34 | |
|
35 | 35 | { |
@@ -10,11 +10,29 | |||
|
10 | 10 | end |
|
11 | 11 | |
|
12 | 12 | def enable_multicontest |
|
13 | - find_or_create_and_set_config('system.multicontests','boolean','true') | |
|
13 | + find_or_create_and_set_config(Configuration::MULTICONTESTS_KEY, | |
|
14 | + 'boolean','true') | |
|
14 | 15 | end |
|
15 | 16 | |
|
16 | 17 | def disable_multicontest |
|
17 | - find_or_create_and_set_config('system.multicontests','boolean','false') | |
|
18 | + find_or_create_and_set_config(Configuration::MULTICONTESTS_KEY, | |
|
19 | + 'boolean','false') | |
|
20 | + end | |
|
21 | + | |
|
22 | + def set_indv_contest_mode | |
|
23 | + find_or_create_and_set_config(Configuration::SYSTEM_MODE_CONF_KEY, | |
|
24 | + 'string','indv-contest') | |
|
18 | 25 | end |
|
19 | 26 | |
|
27 | + def set_standard_mode | |
|
28 | + find_or_create_and_set_config(Configuration::SYSTEM_MODE_CONF_KEY, | |
|
29 | + 'string','standard') | |
|
30 | + end | |
|
31 | + | |
|
32 | + def set_contest_time_limit(limit) | |
|
33 | + find_or_create_and_set_config(Configuration::CONTEST_TIME_LIMIT_KEY, | |
|
34 | + 'string',limit) | |
|
35 | + # clear old value | |
|
36 | + Configuration.contest_time_str = nil | |
|
37 | + end | |
|
20 | 38 | end |
@@ -1,3 +1,5 | |||
|
1 | + require 'delorean' | |
|
2 | + | |
|
1 | 3 | require File.dirname(__FILE__) + '/../spec_helper' |
|
2 | 4 | require File.dirname(__FILE__) + '/../config_spec_helper' |
|
3 | 5 | |
@@ -142,3 +144,50 | |||
|
142 | 144 | end |
|
143 | 145 | |
|
144 | 146 | |
|
147 | + describe MainController, "during individual contest mode" do | |
|
148 | + | |
|
149 | + integrate_views | |
|
150 | + | |
|
151 | + include ConfigSpecHelperMethods | |
|
152 | + | |
|
153 | + fixtures :users | |
|
154 | + fixtures :problems | |
|
155 | + fixtures :contests | |
|
156 | + | |
|
157 | + before(:each) do | |
|
158 | + set_contest_time_limit('3:00') # 3 hours | |
|
159 | + set_indv_contest_mode | |
|
160 | + end | |
|
161 | + | |
|
162 | + it "should allow newly login user to see problem list" do | |
|
163 | + john = users(:john) | |
|
164 | + get "list", {}, {:user_id => john.id} | |
|
165 | + | |
|
166 | + response.should render_template 'main/list' | |
|
167 | + response.should have_text(/add/) | |
|
168 | + response.should have_text(/easy_problem/) | |
|
169 | + response.should have_text(/hard_problem/) | |
|
170 | + end | |
|
171 | + | |
|
172 | + it "should not show 'contest over' sign before the contest ends" do | |
|
173 | + john = users(:john) | |
|
174 | + get "list", {}, {:user_id => john.id} | |
|
175 | + | |
|
176 | + Delorean.time_travel_to(179.minutes.since) do | |
|
177 | + get "list", {}, {:user_id => john.id} | |
|
178 | + response.should_not have_text(/OVER/) | |
|
179 | + end | |
|
180 | + end | |
|
181 | + | |
|
182 | + it "should show 'contest over' sign after the contest ends" do | |
|
183 | + john = users(:john) | |
|
184 | + get "list", {}, {:user_id => john.id} | |
|
185 | + | |
|
186 | + Delorean.time_travel_to(181.minutes.since) do | |
|
187 | + get "list", {}, {:user_id => john.id} | |
|
188 | + response.should have_text(/OVER/) | |
|
189 | + end | |
|
190 | + end | |
|
191 | + | |
|
192 | + end | |
|
193 | + |
@@ -1,3 +1,4 | |||
|
1 | 1 | # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html |
|
2 | 2 | admin: |
|
3 | + name: admin | |
|
3 | 4 | rights: graders_right, user_admin_right, problems_right No newline at end of file |
@@ -1,11 +1,11 | |||
|
1 | 1 | # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html |
|
2 | 2 | |
|
3 | - one: | |
|
4 | - name: MyString | |
|
3 | + first_site: | |
|
4 | + name: First site | |
|
5 | 5 | started: false |
|
6 | 6 | start_time: 2008-04-09 14:08:28 |
|
7 | 7 | |
|
8 | - two: | |
|
9 | - name: MyString | |
|
8 | + second_site: | |
|
9 | + name: Second site | |
|
10 | 10 | started: false |
|
11 | 11 | start_time: 2008-04-09 14:08:28 |
@@ -11,6 +11,7 | |||
|
11 | 11 | full_name: john |
|
12 | 12 | hashed_password: <%= User.encrypt("hello",salt) %> |
|
13 | 13 | salt: <%= salt %> |
|
14 | + activated: true | |
|
14 | 15 | |
|
15 | 16 | mary: |
|
16 | 17 | login: mary |
@@ -18,6 +19,7 | |||
|
18 | 19 | hashed_password: <%= User.encrypt("goodbye",salt) %> |
|
19 | 20 | salt: <%= salt %> |
|
20 | 21 | roles: admin |
|
22 | + activated: true | |
|
21 | 23 | |
|
22 | 24 | james: |
|
23 | 25 | login: james |
@@ -25,6 +27,7 | |||
|
25 | 27 | hashed_password: <%= User.encrypt("morning",salt) %> |
|
26 | 28 | salt: <%= salt %> |
|
27 | 29 | contests: contest_a |
|
30 | + activated: true | |
|
28 | 31 | |
|
29 | 32 | jack: |
|
30 | 33 | login: jack |
@@ -32,3 +35,4 | |||
|
32 | 35 | hashed_password: <%= User.encrypt("morning",salt) %> |
|
33 | 36 | salt: <%= salt %> |
|
34 | 37 | contests: contest_a, contest_b |
|
38 | + activated: true |
deleted file |
deleted file |
deleted file |
deleted file |
deleted file |
deleted file |
deleted file |
deleted file |
deleted file |
deleted file |
deleted file |
deleted file |
You need to be logged in to leave comments.
Login now