Description:
- bootstrap: user admin quick add
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r571:f8d309d2e37e - - 2 files changed: 30 inserted, 29 deleted
@@ -34,126 +34,126 | |||
|
34 | 34 | |
|
35 | 35 | def active |
|
36 | 36 | sessions = ActiveRecord::SessionStore::Session.find(:all, :conditions => ["updated_at >= ?", 60.minutes.ago]) |
|
37 | 37 | @users = [] |
|
38 | 38 | sessions.each do |session| |
|
39 | 39 | if session.data[:user_id] |
|
40 | 40 | @users << User.find(session.data[:user_id]) |
|
41 | 41 | end |
|
42 | 42 | end |
|
43 | 43 | end |
|
44 | 44 | |
|
45 | 45 | def show |
|
46 | 46 | @user = User.find(params[:id]) |
|
47 | 47 | end |
|
48 | 48 | |
|
49 | 49 | def new |
|
50 | 50 | @user = User.new |
|
51 | 51 | end |
|
52 | 52 | |
|
53 | 53 | def create |
|
54 | 54 | @user = User.new(params[:user]) |
|
55 | 55 | @user.activated = true |
|
56 | 56 | if @user.save |
|
57 | 57 | flash[:notice] = 'User was successfully created.' |
|
58 |
- redirect_to :action => ' |
|
|
58 | + redirect_to :action => 'index' | |
|
59 | 59 | else |
|
60 | 60 | render :action => 'new' |
|
61 | 61 | end |
|
62 | 62 | end |
|
63 | 63 | |
|
64 | 64 | def clear_last_ip |
|
65 | 65 | @user = User.find(params[:id]) |
|
66 | 66 | @user.last_ip = nil |
|
67 | 67 | @user.save |
|
68 |
- redirect_to action: ' |
|
|
68 | + redirect_to action: 'index', page: params[:page] | |
|
69 | 69 | end |
|
70 | 70 | |
|
71 | 71 | def create_from_list |
|
72 | 72 | lines = params[:user_list] |
|
73 | 73 | |
|
74 | 74 | note = [] |
|
75 | 75 | |
|
76 | 76 | lines.split("\n").each do |line| |
|
77 | 77 | items = line.chomp.split(',') |
|
78 | 78 | if items.length>=2 |
|
79 | 79 | login = items[0] |
|
80 | 80 | full_name = items[1] |
|
81 | 81 | |
|
82 | 82 | added_random_password = false |
|
83 | 83 | if items.length>=3 |
|
84 | 84 | password = items[2].chomp(" ") |
|
85 | 85 | user_alias = (items.length>=4) ? items[3] : login |
|
86 | 86 | else |
|
87 | 87 | password = random_password |
|
88 | 88 | user_alias = (items.length>=4) ? items[3] : login |
|
89 | 89 | added_random_password = true |
|
90 | 90 | end |
|
91 | 91 | |
|
92 | 92 | user = User.find_by_login(login) |
|
93 | 93 | if (user) |
|
94 | 94 | user.full_name = full_name |
|
95 | 95 | user.password = password |
|
96 | 96 | else |
|
97 | 97 | user = User.new({:login => login, |
|
98 | 98 | :full_name => full_name, |
|
99 | 99 | :password => password, |
|
100 | 100 | :password_confirmation => password, |
|
101 | 101 | :alias => user_alias}) |
|
102 | 102 | end |
|
103 | 103 | user.activated = true |
|
104 | 104 | user.save |
|
105 | 105 | |
|
106 | 106 | if added_random_password |
|
107 | 107 | note << "'#{login}' (+)" |
|
108 | 108 | else |
|
109 | 109 | note << login |
|
110 | 110 | end |
|
111 | 111 | end |
|
112 | 112 | end |
|
113 | 113 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
114 | 114 | ' were successfully created. ' + |
|
115 | 115 | '( (+) - created with random passwords.)' |
|
116 |
- redirect_to :action => ' |
|
|
116 | + redirect_to :action => 'index' | |
|
117 | 117 | end |
|
118 | 118 | |
|
119 | 119 | def edit |
|
120 | 120 | @user = User.find(params[:id]) |
|
121 | 121 | end |
|
122 | 122 | |
|
123 | 123 | def update |
|
124 | 124 | @user = User.find(params[:id]) |
|
125 | 125 | if @user.update_attributes(params[:user]) |
|
126 | 126 | flash[:notice] = 'User was successfully updated.' |
|
127 | 127 | redirect_to :action => 'show', :id => @user |
|
128 | 128 | else |
|
129 | 129 | render :action => 'edit' |
|
130 | 130 | end |
|
131 | 131 | end |
|
132 | 132 | |
|
133 | 133 | def destroy |
|
134 | 134 | User.find(params[:id]).destroy |
|
135 |
- redirect_to :action => ' |
|
|
135 | + redirect_to :action => 'index' | |
|
136 | 136 | end |
|
137 | 137 | |
|
138 | 138 | def user_stat |
|
139 | 139 | if params[:commit] == 'download csv' |
|
140 | 140 | @problems = Problem.all |
|
141 | 141 | else |
|
142 | 142 | @problems = Problem.find_available_problems |
|
143 | 143 | end |
|
144 | 144 | @users = User.includes(:contests, :contest_stat).where(enabled: true) #find(:all, :include => [:contests, :contest_stat]).where(enabled: true) |
|
145 | 145 | @scorearray = Array.new |
|
146 | 146 | @users.each do |u| |
|
147 | 147 | ustat = Array.new |
|
148 | 148 | ustat[0] = u |
|
149 | 149 | @problems.each do |p| |
|
150 | 150 | sub = Submission.find_last_by_user_and_problem(u.id,p.id) |
|
151 | 151 | if (sub!=nil) and (sub.points!=nil) and p and p.full_score |
|
152 | 152 | ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)] |
|
153 | 153 | else |
|
154 | 154 | ustat << [0,false] |
|
155 | 155 | end |
|
156 | 156 | end |
|
157 | 157 | @scorearray << ustat |
|
158 | 158 | end |
|
159 | 159 | if params[:commit] == 'download csv' then |
@@ -178,49 +178,49 | |||
|
178 | 178 | @users.each do |u| |
|
179 | 179 | ustat = Array.new |
|
180 | 180 | ustat[0] = u |
|
181 | 181 | @problems.each do |p| |
|
182 | 182 | max_points = 0 |
|
183 | 183 | Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub| |
|
184 | 184 | max_points = sub.points if sub and sub.points and (sub.points > max_points) |
|
185 | 185 | end |
|
186 | 186 | ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)] |
|
187 | 187 | end |
|
188 | 188 | @scorearray << ustat |
|
189 | 189 | end |
|
190 | 190 | |
|
191 | 191 | if params[:commit] == 'download csv' then |
|
192 | 192 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
193 | 193 | send_data csv, filename: 'max_score.csv' |
|
194 | 194 | else |
|
195 | 195 | render template: 'user_admin/user_stat' |
|
196 | 196 | end |
|
197 | 197 | end |
|
198 | 198 | |
|
199 | 199 | def import |
|
200 | 200 | if params[:file]=='' |
|
201 | 201 | flash[:notice] = 'Error importing no file' |
|
202 |
- redirect_to :action => ' |
|
|
202 | + redirect_to :action => 'index' and return | |
|
203 | 203 | end |
|
204 | 204 | import_from_file(params[:file]) |
|
205 | 205 | end |
|
206 | 206 | |
|
207 | 207 | def random_all_passwords |
|
208 | 208 | users = User.find(:all) |
|
209 | 209 | @prefix = params[:prefix] || '' |
|
210 | 210 | @non_admin_users = User.find_non_admin_with_prefix(@prefix) |
|
211 | 211 | @changed = false |
|
212 | 212 | if request.request_method == 'POST' |
|
213 | 213 | @non_admin_users.each do |user| |
|
214 | 214 | password = random_password |
|
215 | 215 | user.password = password |
|
216 | 216 | user.password_confirmation = password |
|
217 | 217 | user.save |
|
218 | 218 | end |
|
219 | 219 | @changed = true |
|
220 | 220 | end |
|
221 | 221 | end |
|
222 | 222 | |
|
223 | 223 | # contest management |
|
224 | 224 | |
|
225 | 225 | def contests |
|
226 | 226 | @contest, @users = find_contest_and_user_from_contest_id(params[:id]) |
@@ -231,58 +231,58 | |||
|
231 | 231 | contest_id = params[:users_contest_id] |
|
232 | 232 | org_contest, users = find_contest_and_user_from_contest_id(contest_id) |
|
233 | 233 | contest = Contest.find(params[:new_contest][:id]) |
|
234 | 234 | if !contest |
|
235 | 235 | flash[:notice] = 'Error: no contest' |
|
236 | 236 | redirect_to :action => 'contests', :id =>contest_id |
|
237 | 237 | end |
|
238 | 238 | |
|
239 | 239 | note = [] |
|
240 | 240 | users.each do |u| |
|
241 | 241 | u.contests = [contest] |
|
242 | 242 | note << u.login |
|
243 | 243 | end |
|
244 | 244 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
245 | 245 | " were successfully reassigned to #{contest.title}." |
|
246 | 246 | redirect_to :action => 'contests', :id =>contest.id |
|
247 | 247 | end |
|
248 | 248 | |
|
249 | 249 | def add_to_contest |
|
250 | 250 | user = User.find(params[:id]) |
|
251 | 251 | contest = Contest.find(params[:contest_id]) |
|
252 | 252 | if user and contest |
|
253 | 253 | user.contests << contest |
|
254 | 254 | end |
|
255 |
- redirect_to :action => ' |
|
|
255 | + redirect_to :action => 'index' | |
|
256 | 256 | end |
|
257 | 257 | |
|
258 | 258 | def remove_from_contest |
|
259 | 259 | user = User.find(params[:id]) |
|
260 | 260 | contest = Contest.find(params[:contest_id]) |
|
261 | 261 | if user and contest |
|
262 | 262 | user.contests.delete(contest) |
|
263 | 263 | end |
|
264 |
- redirect_to :action => ' |
|
|
264 | + redirect_to :action => 'index' | |
|
265 | 265 | end |
|
266 | 266 | |
|
267 | 267 | def contest_management |
|
268 | 268 | end |
|
269 | 269 | |
|
270 | 270 | def manage_contest |
|
271 | 271 | contest = Contest.find(params[:contest][:id]) |
|
272 | 272 | if !contest |
|
273 | 273 | flash[:notice] = 'You did not choose the contest.' |
|
274 | 274 | redirect_to :action => 'contest_management' and return |
|
275 | 275 | end |
|
276 | 276 | |
|
277 | 277 | operation = params[:operation] |
|
278 | 278 | |
|
279 | 279 | if not ['add','remove','assign'].include? operation |
|
280 | 280 | flash[:notice] = 'You did not choose the operation to perform.' |
|
281 | 281 | redirect_to :action => 'contest_management' and return |
|
282 | 282 | end |
|
283 | 283 | |
|
284 | 284 | lines = params[:login_list] |
|
285 | 285 | if !lines or lines.blank? |
|
286 | 286 | flash[:notice] = 'You entered an empty list.' |
|
287 | 287 | redirect_to :action => 'contest_management' and return |
|
288 | 288 | end |
@@ -1,48 +1,49 | |||
|
1 | 1 | %h1 Listing users |
|
2 | + | |
|
3 | + .panel.panel-primary | |
|
4 | + .panel-title.panel-heading | |
|
5 | + Quick Add | |
|
6 | + .panel-body | |
|
7 | + = form_tag( {method: 'post'}, {class: 'form-inline'}) do | |
|
8 | + .form-group | |
|
9 | + = label_tag 'user_login', 'Login' | |
|
10 | + = text_field 'user', 'login', :size => 10,class: 'form-control' | |
|
11 | + .form-group | |
|
12 | + = label_tag 'user_full_name', 'Full Name' | |
|
13 | + = text_field 'user', 'full_name', :size => 10,class: 'form-control' | |
|
14 | + .form-group | |
|
15 | + = label_tag 'user_password', 'Password' | |
|
16 | + = text_field 'user', 'password', :size => 10,class: 'form-control' | |
|
17 | + .form-group | |
|
18 | + = label_tag 'user_password_confirmation', 'Confirm' | |
|
19 | + = text_field 'user', 'password_confirmation', :size => 10,class: 'form-control' | |
|
20 | + .form-group | |
|
21 | + = label_tag 'user_email', 'email' | |
|
22 | + = text_field 'user', 'email', :size => 10,class: 'form-control' | |
|
23 | + =submit_tag "Create", class: 'btn btn-primary' | |
|
24 | + | |
|
2 | 25 | .submitbox |
|
3 | - %b Quick add | |
|
4 | - = form_tag :action => 'create' do | |
|
5 | - %table{:border => "0"} | |
|
6 | - %tr | |
|
7 | - %td | |
|
8 | - %label{:for => "user_login"} Login | |
|
9 | - %td | |
|
10 | - %label{:for => "user_full_name"} Full name | |
|
11 | - %td | |
|
12 | - %label{:for => "user_password"} Password | |
|
13 | - %td | |
|
14 | - %label{:for => "user_password_confirmation"} Confirm | |
|
15 | - %td | |
|
16 | - %label{:for => "user_email"} Email | |
|
17 | - %tr | |
|
18 | - %td= text_field 'user', 'login', :size => 10 | |
|
19 | - %td= text_field 'user', 'full_name', :size => 30 | |
|
20 | - %td= password_field 'user', 'password', :size => 10 | |
|
21 | - %td= password_field 'user', 'password_confirmation', :size => 10 | |
|
22 | - %td= email_field 'user', 'email', :size => 15 | |
|
23 | - %td= submit_tag "Create" | |
|
24 | - %br/ | |
|
25 | 26 | %b Import from site management |
|
26 | 27 | = form_tag({:action => 'import'}, :multipart => true) do |
|
27 | 28 | File: #{file_field_tag 'file'} #{submit_tag 'Import'} |
|
28 | 29 | %br/ |
|
29 | 30 | %b What else: |
|
30 | 31 | = link_to 'New user', {:action => 'new'}, { class: 'btn btn-default btn-sm'} |
|
31 | 32 | = link_to 'New list of users',{ :action => 'new_list'}, { class: 'btn btn-default btn-sm'} |
|
32 | 33 | = link_to 'View administrators',{ :action => 'admin'}, { class: 'btn btn-default btn-sm'} |
|
33 | 34 | = link_to 'Random passwords',{ :action => 'random_all_passwords'}, { class: 'btn btn-default btn-sm'} |
|
34 | 35 | = link_to 'View active users',{ :action => 'active'}, { class: 'btn btn-default btn-sm'} |
|
35 | 36 | = link_to 'Mass mailing',{ :action => 'mass_mailing'}, { class: 'btn btn-default btn-sm'} |
|
36 | 37 | - if GraderConfiguration.multicontests? |
|
37 | 38 | %br/ |
|
38 | 39 | %b Multi-contest: |
|
39 | 40 | = link_to '[Manage bulk users in contests]', :action => 'contest_management' |
|
40 | 41 | View users in: |
|
41 | 42 | - @contests.each do |contest| |
|
42 | 43 | = link_to "[#{contest.name}]", :action => 'contests', :id => contest.id |
|
43 | 44 | = link_to "[no contest]", :action => 'contests', :id => 'none' |
|
44 | 45 | Total #{@user_count} users | |
|
45 | 46 | - if !@paginated |
|
46 | 47 | Display all users. |
|
47 | 48 | \#{link_to '[show in pages]', :action => 'index', :page => '1'} |
|
48 | 49 | - else |
You need to be logged in to leave comments.
Login now