Description:
confusing merge
Commit status:
[Not Reviewed]
References:
merge default
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r483:7cf62e1e74ba - - 1 file changed: 0 inserted, 1 deleted

@@ -1,197 +1,196
1 require 'csv'
1 require 'csv'
2
2
3 class UserAdminController < ApplicationController
3 class UserAdminController < ApplicationController
4
4
5 -
6 include MailHelperMethods
5 include MailHelperMethods
7
6
8 before_filter :admin_authorization
7 before_filter :admin_authorization
9
8
10 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
9 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
11 verify :method => :post, :only => [ :destroy,
10 verify :method => :post, :only => [ :destroy,
12 :create, :create_from_list,
11 :create, :create_from_list,
13 :update,
12 :update,
14 :manage_contest,
13 :manage_contest,
15 :bulk_mail
14 :bulk_mail
16 ],
15 ],
17 :redirect_to => { :action => :list }
16 :redirect_to => { :action => :list }
18
17
19 def index
18 def index
20 list
19 list
21 render :action => 'list'
20 render :action => 'list'
22 end
21 end
23
22
24 def list
23 def list
25 @user_count = User.count
24 @user_count = User.count
26 if params[:page] == 'all'
25 if params[:page] == 'all'
27 @users = User.all
26 @users = User.all
28 @paginated = false
27 @paginated = false
29 else
28 else
30 @users = User.paginate :page => params[:page]
29 @users = User.paginate :page => params[:page]
31 @paginated = true
30 @paginated = true
32 end
31 end
33 @hidden_columns = ['hashed_password', 'salt', 'created_at', 'updated_at']
32 @hidden_columns = ['hashed_password', 'salt', 'created_at', 'updated_at']
34 @contests = Contest.enabled
33 @contests = Contest.enabled
35 end
34 end
36
35
37 def active
36 def active
38 sessions = ActiveRecord::SessionStore::Session.find(:all, :conditions => ["updated_at >= ?", 60.minutes.ago])
37 sessions = ActiveRecord::SessionStore::Session.find(:all, :conditions => ["updated_at >= ?", 60.minutes.ago])
39 @users = []
38 @users = []
40 sessions.each do |session|
39 sessions.each do |session|
41 if session.data[:user_id]
40 if session.data[:user_id]
42 @users << User.find(session.data[:user_id])
41 @users << User.find(session.data[:user_id])
43 end
42 end
44 end
43 end
45 end
44 end
46
45
47 def show
46 def show
48 @user = User.find(params[:id])
47 @user = User.find(params[:id])
49 end
48 end
50
49
51 def new
50 def new
52 @user = User.new
51 @user = User.new
53 end
52 end
54
53
55 def create
54 def create
56 @user = User.new(params[:user])
55 @user = User.new(params[:user])
57 @user.activated = true
56 @user.activated = true
58 if @user.save
57 if @user.save
59 flash[:notice] = 'User was successfully created.'
58 flash[:notice] = 'User was successfully created.'
60 redirect_to :action => 'list'
59 redirect_to :action => 'list'
61 else
60 else
62 render :action => 'new'
61 render :action => 'new'
63 end
62 end
64 end
63 end
65
64
66 def create_from_list
65 def create_from_list
67 lines = params[:user_list]
66 lines = params[:user_list]
68
67
69 note = []
68 note = []
70
69
71 lines.split("\n").each do |line|
70 lines.split("\n").each do |line|
72 items = line.chomp.split(',')
71 items = line.chomp.split(',')
73 if items.length>=2
72 if items.length>=2
74 login = items[0]
73 login = items[0]
75 full_name = items[1]
74 full_name = items[1]
76
75
77 added_random_password = false
76 added_random_password = false
78 if items.length>=3
77 if items.length>=3
79 password = items[2].chomp(" ")
78 password = items[2].chomp(" ")
80 user_alias = (items.length>=4) ? items[3] : login
79 user_alias = (items.length>=4) ? items[3] : login
81 else
80 else
82 password = random_password
81 password = random_password
83 user_alias = (items.length>=4) ? items[3] : login
82 user_alias = (items.length>=4) ? items[3] : login
84 added_random_password = true
83 added_random_password = true
85 end
84 end
86
85
87 user = User.find_by_login(login)
86 user = User.find_by_login(login)
88 if (user)
87 if (user)
89 user.full_name = full_name
88 user.full_name = full_name
90 user.password = password
89 user.password = password
91 else
90 else
92 user = User.new({:login => login,
91 user = User.new({:login => login,
93 :full_name => full_name,
92 :full_name => full_name,
94 :password => password,
93 :password => password,
95 :password_confirmation => password,
94 :password_confirmation => password,
96 :alias => user_alias})
95 :alias => user_alias})
97 end
96 end
98 user.activated = true
97 user.activated = true
99 user.save
98 user.save
100
99
101 if added_random_password
100 if added_random_password
102 note << "'#{login}' (+)"
101 note << "'#{login}' (+)"
103 else
102 else
104 note << login
103 note << login
105 end
104 end
106 end
105 end
107 end
106 end
108 flash[:notice] = 'User(s) ' + note.join(', ') +
107 flash[:notice] = 'User(s) ' + note.join(', ') +
109 ' were successfully created. ' +
108 ' were successfully created. ' +
110 '( (+) - created with random passwords.)'
109 '( (+) - created with random passwords.)'
111 redirect_to :action => 'list'
110 redirect_to :action => 'list'
112 end
111 end
113
112
114 def edit
113 def edit
115 @user = User.find(params[:id])
114 @user = User.find(params[:id])
116 end
115 end
117
116
118 def update
117 def update
119 @user = User.find(params[:id])
118 @user = User.find(params[:id])
120 if @user.update_attributes(params[:user])
119 if @user.update_attributes(params[:user])
121 flash[:notice] = 'User was successfully updated.'
120 flash[:notice] = 'User was successfully updated.'
122 redirect_to :action => 'show', :id => @user
121 redirect_to :action => 'show', :id => @user
123 else
122 else
124 render :action => 'edit'
123 render :action => 'edit'
125 end
124 end
126 end
125 end
127
126
128 def destroy
127 def destroy
129 User.find(params[:id]).destroy
128 User.find(params[:id]).destroy
130 redirect_to :action => 'list'
129 redirect_to :action => 'list'
131 end
130 end
132
131
133 def user_stat
132 def user_stat
134 if params[:commit] == 'download csv'
133 if params[:commit] == 'download csv'
135 @problems = Problem.all
134 @problems = Problem.all
136 else
135 else
137 @problems = Problem.find_available_problems
136 @problems = Problem.find_available_problems
138 end
137 end
139 @users = User.find(:all, :include => [:contests, :contest_stat])
138 @users = User.find(:all, :include => [:contests, :contest_stat])
140 @scorearray = Array.new
139 @scorearray = Array.new
141 @users.each do |u|
140 @users.each do |u|
142 ustat = Array.new
141 ustat = Array.new
143 ustat[0] = u
142 ustat[0] = u
144 @problems.each do |p|
143 @problems.each do |p|
145 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)
146 if (sub!=nil) and (sub.points!=nil)
145 if (sub!=nil) and (sub.points!=nil)
147 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)]
148 else
147 else
149 ustat << [0,false]
148 ustat << [0,false]
150 end
149 end
151 end
150 end
152 @scorearray << ustat
151 @scorearray << ustat
153 end
152 end
154 end
153 end
155
154
156 def user_stat_max
155 def user_stat_max
157 @problems = Problem.find_available_problems
156 @problems = Problem.find_available_problems
158 @users = User.find(:all, :include => [:contests, :contest_stat])
157 @users = User.find(:all, :include => [:contests, :contest_stat])
159 @scorearray = Array.new
158 @scorearray = Array.new
160 #set up range from param
159 #set up range from param
161 since_id = params.fetch(:since_id, 0).to_i
160 since_id = params.fetch(:since_id, 0).to_i
162 until_id = params.fetch(:until_id, 0).to_i
161 until_id = params.fetch(:until_id, 0).to_i
163 @users.each do |u|
162 @users.each do |u|
164 ustat = Array.new
163 ustat = Array.new
165 ustat[0] = u
164 ustat[0] = u
166 @problems.each do |p|
165 @problems.each do |p|
167 max_points = 0
166 max_points = 0
168 Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub|
167 Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub|
169 max_points = sub.points if sub and sub.points and (sub.points > max_points)
168 max_points = sub.points if sub and sub.points and (sub.points > max_points)
170 end
169 end
171 ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)]
170 ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)]
172 end
171 end
173 @scorearray << ustat
172 @scorearray << ustat
174 end
173 end
175
174
176 if params[:commit] == 'download csv' then
175 if params[:commit] == 'download csv' then
177 csv = gen_csv_from_scorearray(@scorearray,@problems)
176 csv = gen_csv_from_scorearray(@scorearray,@problems)
178 send_data csv, filename: 'last_score.csv'
177 send_data csv, filename: 'last_score.csv'
179 else
178 else
180 render template: 'user_admin/user_stat'
179 render template: 'user_admin/user_stat'
181 end
180 end
182 end
181 end
183
182
184 def user_stat_max
183 def user_stat_max
185 if params[:commit] == 'download csv'
184 if params[:commit] == 'download csv'
186 @problems = Problem.all
185 @problems = Problem.all
187 else
186 else
188 @problems = Problem.find_available_problems
187 @problems = Problem.find_available_problems
189 end
188 end
190 @users = User.find(:all, :include => [:contests, :contest_stat])
189 @users = User.find(:all, :include => [:contests, :contest_stat])
191 @scorearray = Array.new
190 @scorearray = Array.new
192 #set up range from param
191 #set up range from param
193 since_id = params.fetch(:since_id, 0).to_i
192 since_id = params.fetch(:since_id, 0).to_i
194 until_id = params.fetch(:until_id, 0).to_i
193 until_id = params.fetch(:until_id, 0).to_i
195 @users.each do |u|
194 @users.each do |u|
196 ustat = Array.new
195 ustat = Array.new
197 ustat[0] = u
196 ustat[0] = u
You need to be logged in to leave comments. Login now