Description:
add options for bulk manage add user to group (not finished)
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r671:52ce712479a1 - - 2 files changed: 17 inserted, 0 deleted
@@ -207,48 +207,49 | |||
|
207 | 207 | def import |
|
208 | 208 | if params[:file]=='' |
|
209 | 209 | flash[:notice] = 'Error importing no file' |
|
210 | 210 | redirect_to :action => 'index' and return |
|
211 | 211 | end |
|
212 | 212 | import_from_file(params[:file]) |
|
213 | 213 | end |
|
214 | 214 | |
|
215 | 215 | def random_all_passwords |
|
216 | 216 | users = User.all |
|
217 | 217 | @prefix = params[:prefix] || '' |
|
218 | 218 | @non_admin_users = User.find_non_admin_with_prefix(@prefix) |
|
219 | 219 | @changed = false |
|
220 | 220 | if request.request_method == 'POST' |
|
221 | 221 | @non_admin_users.each do |user| |
|
222 | 222 | password = random_password |
|
223 | 223 | user.password = password |
|
224 | 224 | user.password_confirmation = password |
|
225 | 225 | user.save |
|
226 | 226 | end |
|
227 | 227 | @changed = true |
|
228 | 228 | end |
|
229 | 229 | end |
|
230 | 230 | |
|
231 | + | |
|
231 | 232 | # contest management |
|
232 | 233 | |
|
233 | 234 | def contests |
|
234 | 235 | @contest, @users = find_contest_and_user_from_contest_id(params[:id]) |
|
235 | 236 | @contests = Contest.enabled |
|
236 | 237 | end |
|
237 | 238 | |
|
238 | 239 | def assign_from_list |
|
239 | 240 | contest_id = params[:users_contest_id] |
|
240 | 241 | org_contest, users = find_contest_and_user_from_contest_id(contest_id) |
|
241 | 242 | contest = Contest.find(params[:new_contest][:id]) |
|
242 | 243 | if !contest |
|
243 | 244 | flash[:notice] = 'Error: no contest' |
|
244 | 245 | redirect_to :action => 'contests', :id =>contest_id |
|
245 | 246 | end |
|
246 | 247 | |
|
247 | 248 | note = [] |
|
248 | 249 | users.each do |u| |
|
249 | 250 | u.contests = [contest] |
|
250 | 251 | note << u.login |
|
251 | 252 | end |
|
252 | 253 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
253 | 254 | " were successfully reassigned to #{contest.title}." |
|
254 | 255 | redirect_to :action => 'contests', :id =>contest.id |
@@ -402,62 +403,69 | |||
|
402 | 403 | end |
|
403 | 404 | end |
|
404 | 405 | |
|
405 | 406 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
406 | 407 | ' were successfully modified. ' |
|
407 | 408 | redirect_to :action => 'mass_mailing' |
|
408 | 409 | end |
|
409 | 410 | |
|
410 | 411 | #bulk manage |
|
411 | 412 | def bulk_manage |
|
412 | 413 | |
|
413 | 414 | begin |
|
414 | 415 | @users = User.where('login REGEXP ?',params[:regex]) if params[:regex] |
|
415 | 416 | @users.count if @users #i don't know why I have to call count, but if I won't exception is not raised |
|
416 | 417 | rescue Exception |
|
417 | 418 | flash[:error] = 'Regular Expression is malformed' |
|
418 | 419 | @users = nil |
|
419 | 420 | end |
|
420 | 421 | |
|
421 | 422 | if params[:commit] |
|
422 | 423 | @action = {} |
|
423 | 424 | @action[:set_enable] = params[:enabled] |
|
424 | 425 | @action[:enabled] = params[:enable] == "1" |
|
425 | 426 | @action[:gen_password] = params[:gen_password] |
|
427 | + @action[:add_group] = params[:add_group] | |
|
428 | + @action[:group_name] = params[:group_name] | |
|
426 | 429 | end |
|
427 | 430 | |
|
428 | 431 | if params[:commit] == "Perform" |
|
429 | 432 | if @action[:set_enable] |
|
430 | 433 | @users.update_all(enabled: @action[:enabled]) |
|
431 | 434 | end |
|
432 | 435 | if @action[:gen_password] |
|
433 | 436 | @users.each do |u| |
|
434 | 437 | password = random_password |
|
435 | 438 | u.password = password |
|
436 | 439 | u.password_confirmation = password |
|
437 | 440 | u.save |
|
438 | 441 | end |
|
439 | 442 | end |
|
443 | + if @action[:add_group] | |
|
444 | + @uses.each do |u| | |
|
445 | + | |
|
446 | + end | |
|
447 | + end | |
|
440 | 448 | end |
|
441 | 449 | end |
|
442 | 450 | |
|
443 | 451 | protected |
|
444 | 452 | |
|
445 | 453 | def random_password(length=5) |
|
446 | 454 | chars = 'abcdefghijkmnopqrstuvwxyz23456789' |
|
447 | 455 | newpass = "" |
|
448 | 456 | length.times { newpass << chars[rand(chars.size-1)] } |
|
449 | 457 | return newpass |
|
450 | 458 | end |
|
451 | 459 | |
|
452 | 460 | def import_from_file(f) |
|
453 | 461 | data_hash = YAML.load(f) |
|
454 | 462 | @import_log = "" |
|
455 | 463 | |
|
456 | 464 | country_data = data_hash[:countries] |
|
457 | 465 | site_data = data_hash[:sites] |
|
458 | 466 | user_data = data_hash[:users] |
|
459 | 467 | |
|
460 | 468 | # import country |
|
461 | 469 | countries = {} |
|
462 | 470 | country_data.each_pair do |id,country| |
|
463 | 471 | c = Country.find_by_name(country[:name]) |
@@ -25,48 +25,57 | |||
|
25 | 25 | matches every user whose login ends with "21" |
|
26 | 26 | .col-md-6 |
|
27 | 27 | .panel.panel-primary |
|
28 | 28 | .panel-title.panel-heading |
|
29 | 29 | Action |
|
30 | 30 | .panel-body |
|
31 | 31 | .row.form-group |
|
32 | 32 | .col-md-6 |
|
33 | 33 | %label.checkbox-inline |
|
34 | 34 | = check_box_tag "enabled", true, params[:enabled] |
|
35 | 35 | Change "Enabled" to |
|
36 | 36 | .col-md-3 |
|
37 | 37 | %label.radio-inline |
|
38 | 38 | = radio_button_tag "enable", 1, params[:enable] == '1', id: 'enable-yes' |
|
39 | 39 | Yes |
|
40 | 40 | .col-md-3 |
|
41 | 41 | %label.radio-inline |
|
42 | 42 | = radio_button_tag "enable", 0, params[:enable] == '0', id: 'enable-no' |
|
43 | 43 | No |
|
44 | 44 | .row.form-group |
|
45 | 45 | .col-md-6 |
|
46 | 46 | %label.checkbox-inline |
|
47 | 47 | = check_box_tag "gen_password", true, params[:gen_password] |
|
48 | 48 | Generate new random password |
|
49 | + .row.form-group | |
|
50 | + .col-md-4 | |
|
51 | + %label.checkbox-inline | |
|
52 | + = check_box_tag "add_group", true, params[:add_group] | |
|
53 | + Add users to group | |
|
54 | + %label.col-md-3.control-label.text-right Group name | |
|
55 | + .col-md-5 | |
|
56 | + = text_field_tag "group_name", params[:group_name], id: 'group_name',class: 'form-control select2' | |
|
57 | + | |
|
49 | 58 | |
|
50 | 59 | .row |
|
51 | 60 | .col-md-12 |
|
52 | 61 | = submit_tag "Preview Result", class: 'btn btn-default' |
|
53 | 62 | - if @users |
|
54 | 63 | .row |
|
55 | 64 | .col-md-4 |
|
56 | 65 | - if @action |
|
57 | 66 | %h2 Confirmation |
|
58 | 67 | - if @action[:set_enable] |
|
59 | 68 | .alert.alert-info The following users will be set #{(@action[:enabled] ? 'enable' : 'disable')}. |
|
60 | 69 | - if @action[:gen_password] |
|
61 | 70 | .alert.alert-info The password of the following users will be randomly generated. |
|
62 | 71 | .row |
|
63 | 72 | .col-md-4 |
|
64 | 73 | = submit_tag "Perform", class: 'btn btn-primary' |
|
65 | 74 | .row |
|
66 | 75 | .col-md-12 |
|
67 | 76 | The pattern matches #{@users.count} following users. |
|
68 | 77 | %br |
|
69 | 78 | - @users.each do |user| |
|
70 | 79 | = user.login |
|
71 | 80 | = ' ' |
|
72 | 81 | = user.full_name |
You need to be logged in to leave comments.
Login now