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