Description:
remove junk from ealier merge
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r484:a0c51d75908c - - 1 file changed: 0 inserted, 28 deleted

@@ -60,220 +60,192
60 else
60 else
61 render :action => 'new'
61 render :action => 'new'
62 end
62 end
63 end
63 end
64
64
65 def create_from_list
65 def create_from_list
66 lines = params[:user_list]
66 lines = params[:user_list]
67
67
68 note = []
68 note = []
69
69
70 lines.split("\n").each do |line|
70 lines.split("\n").each do |line|
71 items = line.chomp.split(',')
71 items = line.chomp.split(',')
72 if items.length>=2
72 if items.length>=2
73 login = items[0]
73 login = items[0]
74 full_name = items[1]
74 full_name = items[1]
75
75
76 added_random_password = false
76 added_random_password = false
77 if items.length>=3
77 if items.length>=3
78 password = items[2].chomp(" ")
78 password = items[2].chomp(" ")
79 user_alias = (items.length>=4) ? items[3] : login
79 user_alias = (items.length>=4) ? items[3] : login
80 else
80 else
81 password = random_password
81 password = random_password
82 user_alias = (items.length>=4) ? items[3] : login
82 user_alias = (items.length>=4) ? items[3] : login
83 added_random_password = true
83 added_random_password = true
84 end
84 end
85
85
86 user = User.find_by_login(login)
86 user = User.find_by_login(login)
87 if (user)
87 if (user)
88 user.full_name = full_name
88 user.full_name = full_name
89 user.password = password
89 user.password = password
90 else
90 else
91 user = User.new({:login => login,
91 user = User.new({:login => login,
92 :full_name => full_name,
92 :full_name => full_name,
93 :password => password,
93 :password => password,
94 :password_confirmation => password,
94 :password_confirmation => password,
95 :alias => user_alias})
95 :alias => user_alias})
96 end
96 end
97 user.activated = true
97 user.activated = true
98 user.save
98 user.save
99
99
100 if added_random_password
100 if added_random_password
101 note << "'#{login}' (+)"
101 note << "'#{login}' (+)"
102 else
102 else
103 note << login
103 note << login
104 end
104 end
105 end
105 end
106 end
106 end
107 flash[:notice] = 'User(s) ' + note.join(', ') +
107 flash[:notice] = 'User(s) ' + note.join(', ') +
108 ' were successfully created. ' +
108 ' were successfully created. ' +
109 '( (+) - created with random passwords.)'
109 '( (+) - created with random passwords.)'
110 redirect_to :action => 'list'
110 redirect_to :action => 'list'
111 end
111 end
112
112
113 def edit
113 def edit
114 @user = User.find(params[:id])
114 @user = User.find(params[:id])
115 end
115 end
116
116
117 def update
117 def update
118 @user = User.find(params[:id])
118 @user = User.find(params[:id])
119 if @user.update_attributes(params[:user])
119 if @user.update_attributes(params[:user])
120 flash[:notice] = 'User was successfully updated.'
120 flash[:notice] = 'User was successfully updated.'
121 redirect_to :action => 'show', :id => @user
121 redirect_to :action => 'show', :id => @user
122 else
122 else
123 render :action => 'edit'
123 render :action => 'edit'
124 end
124 end
125 end
125 end
126
126
127 def destroy
127 def destroy
128 User.find(params[:id]).destroy
128 User.find(params[:id]).destroy
129 redirect_to :action => 'list'
129 redirect_to :action => 'list'
130 end
130 end
131
131
132 def user_stat
132 def user_stat
133 if params[:commit] == 'download csv'
133 if params[:commit] == 'download csv'
134 @problems = Problem.all
134 @problems = Problem.all
135 else
135 else
136 @problems = Problem.find_available_problems
136 @problems = Problem.find_available_problems
137 end
137 end
138 @users = User.find(:all, :include => [:contests, :contest_stat])
138 @users = User.find(:all, :include => [:contests, :contest_stat])
139 @scorearray = Array.new
139 @scorearray = Array.new
140 @users.each do |u|
140 @users.each do |u|
141 ustat = Array.new
141 ustat = Array.new
142 ustat[0] = u
142 ustat[0] = u
143 @problems.each do |p|
143 @problems.each do |p|
144 sub = Submission.find_last_by_user_and_problem(u.id,p.id)
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)
146 ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)]
146 ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)]
147 else
147 else
148 ustat << [0,false]
148 ustat << [0,false]
149 end
149 end
150 end
150 end
151 @scorearray << ustat
151 @scorearray << ustat
152 end
152 end
153 end
153 end
154
154
155 def user_stat_max
155 def user_stat_max
156 - @problems = Problem.find_available_problems
157 - @users = User.find(:all, :include => [:contests, :contest_stat])
158 - @scorearray = Array.new
159 - #set up range from param
160 - since_id = params.fetch(:since_id, 0).to_i
161 - until_id = params.fetch(:until_id, 0).to_i
162 - @users.each do |u|
163 - ustat = Array.new
164 - ustat[0] = u
165 - @problems.each do |p|
166 - max_points = 0
167 - Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub|
168 - max_points = sub.points if sub and sub.points and (sub.points > max_points)
169 - end
170 - ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)]
171 - end
172 - @scorearray << ustat
173 - end
174 -
175 - if params[:commit] == 'download csv' then
176 - csv = gen_csv_from_scorearray(@scorearray,@problems)
177 - send_data csv, filename: 'last_score.csv'
178 - else
179 - render template: 'user_admin/user_stat'
180 - end
181 - end
182 -
183 - def user_stat_max
184 if params[:commit] == 'download csv'
156 if params[:commit] == 'download csv'
185 @problems = Problem.all
157 @problems = Problem.all
186 else
158 else
187 @problems = Problem.find_available_problems
159 @problems = Problem.find_available_problems
188 end
160 end
189 @users = User.find(:all, :include => [:contests, :contest_stat])
161 @users = User.find(:all, :include => [:contests, :contest_stat])
190 @scorearray = Array.new
162 @scorearray = Array.new
191 #set up range from param
163 #set up range from param
192 since_id = params.fetch(:since_id, 0).to_i
164 since_id = params.fetch(:since_id, 0).to_i
193 until_id = params.fetch(:until_id, 0).to_i
165 until_id = params.fetch(:until_id, 0).to_i
194 @users.each do |u|
166 @users.each do |u|
195 ustat = Array.new
167 ustat = Array.new
196 ustat[0] = u
168 ustat[0] = u
197 @problems.each do |p|
169 @problems.each do |p|
198 max_points = 0
170 max_points = 0
199 Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub|
171 Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub|
200 max_points = sub.points if sub and sub.points and (sub.points > max_points)
172 max_points = sub.points if sub and sub.points and (sub.points > max_points)
201 end
173 end
202 ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)]
174 ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)]
203 end
175 end
204 @scorearray << ustat
176 @scorearray << ustat
205 end
177 end
206
178
207 if params[:commit] == 'download csv' then
179 if params[:commit] == 'download csv' then
208 csv = gen_csv_from_scorearray(@scorearray,@problems)
180 csv = gen_csv_from_scorearray(@scorearray,@problems)
209 send_data csv, filename: 'max_score.csv'
181 send_data csv, filename: 'max_score.csv'
210 else
182 else
211 render template: 'user_admin/user_stat'
183 render template: 'user_admin/user_stat'
212 end
184 end
213 end
185 end
214
186
215 def import
187 def import
216 if params[:file]==''
188 if params[:file]==''
217 flash[:notice] = 'Error importing no file'
189 flash[:notice] = 'Error importing no file'
218 redirect_to :action => 'list' and return
190 redirect_to :action => 'list' and return
219 end
191 end
220 import_from_file(params[:file])
192 import_from_file(params[:file])
221 end
193 end
222
194
223 def random_all_passwords
195 def random_all_passwords
224 users = User.find(:all)
196 users = User.find(:all)
225 @prefix = params[:prefix] || ''
197 @prefix = params[:prefix] || ''
226 @non_admin_users = User.find_non_admin_with_prefix(@prefix)
198 @non_admin_users = User.find_non_admin_with_prefix(@prefix)
227 @changed = false
199 @changed = false
228 if request.request_method == 'POST'
200 if request.request_method == 'POST'
229 @non_admin_users.each do |user|
201 @non_admin_users.each do |user|
230 password = random_password
202 password = random_password
231 user.password = password
203 user.password = password
232 user.password_confirmation = password
204 user.password_confirmation = password
233 user.save
205 user.save
234 end
206 end
235 @changed = true
207 @changed = true
236 end
208 end
237 end
209 end
238
210
239 # contest management
211 # contest management
240
212
241 def contests
213 def contests
242 @contest, @users = find_contest_and_user_from_contest_id(params[:id])
214 @contest, @users = find_contest_and_user_from_contest_id(params[:id])
243 @contests = Contest.enabled
215 @contests = Contest.enabled
244 end
216 end
245
217
246 def assign_from_list
218 def assign_from_list
247 contest_id = params[:users_contest_id]
219 contest_id = params[:users_contest_id]
248 org_contest, users = find_contest_and_user_from_contest_id(contest_id)
220 org_contest, users = find_contest_and_user_from_contest_id(contest_id)
249 contest = Contest.find(params[:new_contest][:id])
221 contest = Contest.find(params[:new_contest][:id])
250 if !contest
222 if !contest
251 flash[:notice] = 'Error: no contest'
223 flash[:notice] = 'Error: no contest'
252 redirect_to :action => 'contests', :id =>contest_id
224 redirect_to :action => 'contests', :id =>contest_id
253 end
225 end
254
226
255 note = []
227 note = []
256 users.each do |u|
228 users.each do |u|
257 u.contests = [contest]
229 u.contests = [contest]
258 note << u.login
230 note << u.login
259 end
231 end
260 flash[:notice] = 'User(s) ' + note.join(', ') +
232 flash[:notice] = 'User(s) ' + note.join(', ') +
261 " were successfully reassigned to #{contest.title}."
233 " were successfully reassigned to #{contest.title}."
262 redirect_to :action => 'contests', :id =>contest.id
234 redirect_to :action => 'contests', :id =>contest.id
263 end
235 end
264
236
265 def add_to_contest
237 def add_to_contest
266 user = User.find(params[:id])
238 user = User.find(params[:id])
267 contest = Contest.find(params[:contest_id])
239 contest = Contest.find(params[:contest_id])
268 if user and contest
240 if user and contest
269 user.contests << contest
241 user.contests << contest
270 end
242 end
271 redirect_to :action => 'list'
243 redirect_to :action => 'list'
272 end
244 end
273
245
274 def remove_from_contest
246 def remove_from_contest
275 user = User.find(params[:id])
247 user = User.find(params[:id])
276 contest = Contest.find(params[:contest_id])
248 contest = Contest.find(params[:contest_id])
277 if user and contest
249 if user and contest
278 user.contests.delete(contest)
250 user.contests.delete(contest)
279 end
251 end
You need to be logged in to leave comments. Login now