Description:
report only enabled user
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r550:6d57d5eff450 - - 1 file changed: 1 inserted, 1 deleted

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