Description:
merge
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r843:2e56e1493802 - - 5 files changed: 39 inserted, 85 deleted
@@ -0,0 +1,5 | |||||
|
|
1 | + class AddIndexToTaskStatus < ActiveRecord::Migration[5.2] | ||
|
|
2 | + def change | ||
|
|
3 | + add_index :tasks, :status | ||
|
|
4 | + end | ||
|
|
5 | + end |
@@ -39,7 +39,7 | |||||
|
39 | redirect_to :action => 'index' |
|
39 | redirect_to :action => 'index' |
|
40 | else |
|
40 | else |
|
41 | render :action => 'new' |
|
41 | render :action => 'new' |
|
42 |
- end |
|
42 | + end |
|
43 | end |
|
43 | end |
|
44 |
|
44 | ||
|
45 | def clear_last_ip |
|
45 | def clear_last_ip |
@@ -52,92 +52,23 | |||||
|
52 | def create_from_list |
|
52 | def create_from_list |
|
53 | lines = params[:user_list] |
|
53 | lines = params[:user_list] |
|
54 |
|
54 | ||
|
55 | - note = [] |
|
||
|
56 | - error_note = [] |
|
||
|
57 | - error_msg = nil |
|
||
|
58 | - ok_user = [] |
|
||
|
59 | - |
|
||
|
60 | - lines.split("\n").each do |line| |
|
||
|
61 | - #split with large limit, this will cause consecutive ',' to be result in a blank |
|
||
|
62 | - items = line.chomp.split(',',1000) |
|
||
|
63 | - if items.length>=2 |
|
||
|
64 | - login = items[0] |
|
||
|
65 | - full_name = items[1] |
|
||
|
66 | - remark ='' |
|
||
|
67 | - user_alias = '' |
|
||
|
68 | - |
|
||
|
69 | - added_random_password = false |
|
||
|
70 | - added_password = false |
|
||
|
71 | - if items.length >= 3 |
|
||
|
72 | - if items[2].chomp(" ").length > 0 |
|
||
|
73 | - password = items[2].chomp(" ") |
|
||
|
74 | - added_password = true |
|
||
|
75 | - end |
|
||
|
76 | - else |
|
||
|
77 | - password = random_password |
|
||
|
78 | - added_random_password=true; |
|
||
|
79 | - end |
|
||
|
80 | - |
|
||
|
81 | - if items.length>= 4 and items[3].chomp(" ").length > 0; |
|
||
|
82 | - user_alias = items[3].chomp(" ") |
|
||
|
83 | - else |
|
||
|
84 | - user_alias = login |
|
||
|
85 | - end |
|
||
|
86 | - |
|
||
|
87 |
|
55 | ||
|
88 | - has_remark = false |
|
56 | + res = User.create_from_list(lines) |
|
89 | - if items.length>=5 |
|
57 | + error_logins = res[:error_logins] |
|
90 | - remark = items[4].strip; |
|
58 | + error_msg = res[:first_error] |
|
91 | - has_remark = true |
|
59 | + ok_user = res[:created_users] |
|
92 | - end |
|
||
|
93 |
|
60 | ||
|
94 | - user = User.find_by_login(login) |
|
||
|
95 | - if (user) |
|
||
|
96 | - user.full_name = full_name |
|
||
|
97 | - user.remark = remark if has_remark |
|
||
|
98 | - user.password = password if added_password || added_random_password |
|
||
|
99 | - else |
|
||
|
100 | - #create a random password if none are given |
|
||
|
101 | - password = random_password unless password |
|
||
|
102 | - user = User.new({:login => login, |
|
||
|
103 | - :full_name => full_name, |
|
||
|
104 | - :password => password, |
|
||
|
105 | - :password_confirmation => password, |
|
||
|
106 | - :alias => user_alias, |
|
||
|
107 | - :remark => remark}) |
|
||
|
108 | - end |
|
||
|
109 | - user.activated = true |
|
||
|
110 | - |
|
||
|
111 | - if user.save |
|
||
|
112 | - if added_random_password |
|
||
|
113 | - note << "'#{login}' (+)" |
|
||
|
114 | - else |
|
||
|
115 | - note << login |
|
||
|
116 | - end |
|
||
|
117 | - ok_user << user |
|
||
|
118 | - else |
|
||
|
119 | - error_note << "'#{login}'" |
|
||
|
120 | - error_msg = user.errors.full_messages.to_sentence unless error_msg |
|
||
|
121 | - end |
|
||
|
122 | - |
|
||
|
123 | - end |
|
||
|
124 | - end |
|
||
|
125 |
|
61 | ||
|
126 | #add to group |
|
62 | #add to group |
|
127 | if params[:add_to_group] |
|
63 | if params[:add_to_group] |
|
128 |
- group = Group. |
|
64 | + group = Group.find_by(id: params[:group_id])&.add_users_skip_existing(ok_user) |
|
129 | - if group |
|
||
|
130 | - group.users << ok_user |
|
||
|
131 | - end |
|
||
|
132 | end |
|
65 | end |
|
133 |
|
66 | ||
|
134 | # show flash |
|
67 | # show flash |
|
135 | - if note.size > 0 |
|
68 | + if ok_user.count > 0 |
|
136 | - flash[:success] = 'User(s) ' + note.join(', ') + |
|
69 | + flash[:success] = "#{ok_user.count} user(s) was created or updated successfully" |
|
137 | - ' were successfully created. ' + |
|
||
|
138 | - '( (+) - created with random passwords.)' |
|
||
|
139 | end |
|
70 | end |
|
140 |
- if error_ |
|
71 | + if error_logins.size > 0 |
|
141 | flash[:error] = "Following user(s) failed to be created: " + error_note.join(', ') + ". The error of the first failed one are: " + error_msg; |
|
72 | flash[:error] = "Following user(s) failed to be created: " + error_note.join(', ') + ". The error of the first failed one are: " + error_msg; |
|
142 | end |
|
73 | end |
|
143 | redirect_to :action => 'index' |
|
74 | redirect_to :action => 'index' |
@@ -401,7 +332,7 | |||||
|
401 | flash[:notice] = 'You entered an empty mail subject.' |
|
332 | flash[:notice] = 'You entered an empty mail subject.' |
|
402 | redirect_to :action => 'mass_mailing' and return |
|
333 | redirect_to :action => 'mass_mailing' and return |
|
403 | end |
|
334 | end |
|
404 | - |
|
335 | + |
|
405 | mail_body = params[:email_body] |
|
336 | mail_body = params[:email_body] |
|
406 | if !mail_body or mail_body.blank? |
|
337 | if !mail_body or mail_body.blank? |
|
407 | flash[:notice] = 'You entered an empty mail body.' |
|
338 | flash[:notice] = 'You entered an empty mail body.' |
@@ -417,7 +348,7 | |||||
|
417 | note << user.login |
|
348 | note << user.login |
|
418 | end |
|
349 | end |
|
419 | end |
|
350 | end |
|
420 | - |
|
351 | + |
|
421 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
352 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
422 | ' were successfully modified. ' |
|
353 | ' were successfully modified. ' |
|
423 | redirect_to :action => 'mass_mailing' |
|
354 | redirect_to :action => 'mass_mailing' |
@@ -426,9 +357,14 | |||||
|
426 | #bulk manage |
|
357 | #bulk manage |
|
427 | def bulk_manage |
|
358 | def bulk_manage |
|
428 |
|
359 | ||
|
429 |
- begin |
|
360 | + begin |
|
430 | - @users = User.where('(login REGEXP ?) OR (remark REGEXP ?)',params[:regex],params[:regex]) if params[:regex] |
|
361 | + if params[:filter_group] |
|
431 | - @users.count if @users #i don't know why I have to call count, but if I won't exception is not raised |
|
362 | + @users = Group.find_by(id: params[:filter_group_id]).users |
|
|
363 | + else | ||
|
|
364 | + @users = User.all | ||
|
|
365 | + end | ||
|
|
366 | + @users = @users.where('(login REGEXP ?) OR (remark REGEXP ?)',params[:regex],params[:regex]) unless params[:regex].blank? | ||
|
|
367 | + @users.count if @users #test the sql | ||
|
432 | rescue Exception |
|
368 | rescue Exception |
|
433 | flash[:error] = 'Regular Expression is malformed' |
|
369 | flash[:error] = 'Regular Expression is malformed' |
|
434 | @users = nil |
|
370 | @users = nil |
@@ -8,6 +8,13 | |||||
|
8 | #has_and_belongs_to_many :problems |
|
8 | #has_and_belongs_to_many :problems |
|
9 | #has_and_belongs_to_many :users |
|
9 | #has_and_belongs_to_many :users |
|
10 |
|
10 | ||
|
|
11 | + def add_users_skip_existing(users_list) | ||
|
|
12 | + new_list = [] | ||
|
|
13 | + users_list.uniq.each do |u| | ||
|
|
14 | + new_list << u unless users.include? u | ||
|
|
15 | + end | ||
|
|
16 | + users << new_list | ||
|
|
17 | + end | ||
|
11 |
|
18 | ||
|
12 | end |
|
19 | end |
|
13 |
|
20 |
@@ -27,7 +27,7 | |||||
|
27 | =form_tag add_user_group_path(@group), class: 'form-inline' do |
|
27 | =form_tag add_user_group_path(@group), class: 'form-inline' do |
|
28 | .form-group |
|
28 | .form-group |
|
29 | =label_tag :user_id, "User" |
|
29 | =label_tag :user_id, "User" |
|
30 |
- =select_tag :user_id, options_from_collection_for_select(User.all,'id',' |
|
30 | + =select_tag :user_id, options_from_collection_for_select(User.all,'id','login_with_name'), class: 'select2', style: 'width: 25em'; |
|
31 | =submit_tag "Add",class: 'btn btn-primary' |
|
31 | =submit_tag "Add",class: 'btn btn-primary' |
|
32 |
|
32 | ||
|
33 |
|
33 | ||
@@ -59,7 +59,7 | |||||
|
59 | =form_tag add_problem_group_path(@group), class: 'form-inline' do |
|
59 | =form_tag add_problem_group_path(@group), class: 'form-inline' do |
|
60 | .form-group |
|
60 | .form-group |
|
61 | =label_tag :problem_id, "Problem" |
|
61 | =label_tag :problem_id, "Problem" |
|
62 |
- =select_tag :problem_id, options_from_collection_for_select(Problem.all,'id',' |
|
62 | + =select_tag :problem_id, options_from_collection_for_select(Problem.all,'id','long_name'), class: 'select2', style: 'width: 25em'; |
|
63 | =submit_tag "Add",class: 'btn btn-primary' |
|
63 | =submit_tag "Add",class: 'btn btn-primary' |
|
64 |
|
64 | ||
|
65 |
|
65 |
@@ -23,6 +23,12 | |||||
|
23 | %li |
|
23 | %li |
|
24 | %code 21$ |
|
24 | %code 21$ |
|
25 | matches every user whose login ends with "21" |
|
25 | matches every user whose login ends with "21" |
|
|
26 | + .form-group | ||
|
|
27 | + .div.checkbox | ||
|
|
28 | + %label | ||
|
|
29 | + = check_box_tag :filter_group, 1, params[:filter_group] == '1' | ||
|
|
30 | + Apply to this group only | ||
|
|
31 | + = select_tag "filter_group_id", options_from_collection_for_select( Group.all, 'id','name',params[:filter_group_id]), id: 'group_name',class: 'select2' | ||
|
26 | .col-md-6 |
|
32 | .col-md-6 |
|
27 | .panel.panel-primary |
|
33 | .panel.panel-primary |
|
28 | .panel-title.panel-heading |
|
34 | .panel-title.panel-heading |
You need to be logged in to leave comments.
Login now