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