Description:
add more error message to user list upgrade. Fix #9
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r785:2cf37c58fc60 - - 2 files changed: 21 inserted, 15 deleted
@@ -52,95 +52,99 | |||||
|
52 | def clear_last_ip |
|
52 | def clear_last_ip |
|
53 | @user = User.find(params[:id]) |
|
53 | @user = User.find(params[:id]) |
|
54 | @user.last_ip = nil |
|
54 | @user.last_ip = nil |
|
55 | @user.save |
|
55 | @user.save |
|
56 | redirect_to action: 'index', page: params[:page] |
|
56 | redirect_to action: 'index', page: params[:page] |
|
57 | end |
|
57 | end |
|
58 |
|
58 | ||
|
59 | def create_from_list |
|
59 | def create_from_list |
|
60 | lines = params[:user_list] |
|
60 | lines = params[:user_list] |
|
61 |
|
61 | ||
|
62 | note = [] |
|
62 | note = [] |
|
63 | error_note = [] |
|
63 | error_note = [] |
|
|
64 | + error_msg = nil | ||
|
64 | ok_user = [] |
|
65 | ok_user = [] |
|
65 |
|
66 | ||
|
66 | lines.split("\n").each do |line| |
|
67 | lines.split("\n").each do |line| |
|
67 | items = line.chomp.split(',') |
|
68 | items = line.chomp.split(',') |
|
68 | if items.length>=2 |
|
69 | if items.length>=2 |
|
69 | login = items[0] |
|
70 | login = items[0] |
|
70 | full_name = items[1] |
|
71 | full_name = items[1] |
|
71 | remark ='' |
|
72 | remark ='' |
|
72 | user_alias = '' |
|
73 | user_alias = '' |
|
73 |
|
74 | ||
|
74 | added_random_password = false |
|
75 | added_random_password = false |
|
75 | if items.length >= 3 and items[2].chomp(" ").length > 0; |
|
76 | if items.length >= 3 and items[2].chomp(" ").length > 0; |
|
76 | password = items[2].chomp(" ") |
|
77 | password = items[2].chomp(" ") |
|
77 | else |
|
78 | else |
|
78 | password = random_password |
|
79 | password = random_password |
|
79 | - add_random_password=true; |
|
80 | + added_random_password=true; |
|
80 | end |
|
81 | end |
|
81 |
|
82 | ||
|
82 | if items.length>= 4 and items[3].chomp(" ").length > 0; |
|
83 | if items.length>= 4 and items[3].chomp(" ").length > 0; |
|
83 | user_alias = items[3].chomp(" ") |
|
84 | user_alias = items[3].chomp(" ") |
|
84 | else |
|
85 | else |
|
85 | user_alias = login |
|
86 | user_alias = login |
|
86 | end |
|
87 | end |
|
87 |
|
88 | ||
|
88 | if items.length>=5 |
|
89 | if items.length>=5 |
|
89 | remark = items[4].strip; |
|
90 | remark = items[4].strip; |
|
90 | end |
|
91 | end |
|
91 |
|
92 | ||
|
92 | user = User.find_by_login(login) |
|
93 | user = User.find_by_login(login) |
|
93 | if (user) |
|
94 | if (user) |
|
94 | user.full_name = full_name |
|
95 | user.full_name = full_name |
|
95 | user.password = password |
|
96 | user.password = password |
|
96 | user.remark = remark |
|
97 | user.remark = remark |
|
97 | else |
|
98 | else |
|
98 | user = User.new({:login => login, |
|
99 | user = User.new({:login => login, |
|
99 |
- |
|
100 | + :full_name => full_name, |
|
100 |
- |
|
101 | + :password => password, |
|
101 |
- |
|
102 | + :password_confirmation => password, |
|
102 |
- |
|
103 | + :alias => user_alias, |
|
103 |
- |
|
104 | + :remark => remark}) |
|
104 | end |
|
105 | end |
|
105 | user.activated = true |
|
106 | user.activated = true |
|
106 |
|
107 | ||
|
107 | if user.save |
|
108 | if user.save |
|
108 | if added_random_password |
|
109 | if added_random_password |
|
109 | note << "'#{login}' (+)" |
|
110 | note << "'#{login}' (+)" |
|
110 | else |
|
111 | else |
|
111 | note << login |
|
112 | note << login |
|
112 | end |
|
113 | end |
|
113 | ok_user << user |
|
114 | ok_user << user |
|
114 | else |
|
115 | else |
|
115 | - error_note << "#{login}" |
|
116 | + error_note << "'#{login}'" |
|
|
117 | + error_msg = user.errors.full_messages.to_sentence unless error_msg | ||
|
116 | end |
|
118 | end |
|
117 |
|
119 | ||
|
118 | end |
|
120 | end |
|
119 | end |
|
121 | end |
|
120 |
|
122 | ||
|
121 | #add to group |
|
123 | #add to group |
|
122 | if params[:add_to_group] |
|
124 | if params[:add_to_group] |
|
123 | group = Group.where(id: params[:group_id]).first |
|
125 | group = Group.where(id: params[:group_id]).first |
|
124 | if group |
|
126 | if group |
|
125 | group.users << ok_user |
|
127 | group.users << ok_user |
|
126 | end |
|
128 | end |
|
127 | end |
|
129 | end |
|
128 |
|
130 | ||
|
129 | # show flash |
|
131 | # show flash |
|
130 | - flash[:success] = 'User(s) ' + note.join(', ') + |
|
132 | + if note.size > 0 |
|
131 | - ' were successfully created. ' + |
|
133 | + flash[:success] = 'User(s) ' + note.join(', ') + |
|
132 | - '( (+) - created with random passwords.)' |
|
134 | + ' were successfully created. ' + |
|
|
135 | + '( (+) - created with random passwords.)' | ||
|
|
136 | + end | ||
|
133 | if error_note.size > 0 |
|
137 | if error_note.size > 0 |
|
134 | - flash[:error] = "Following user(s) failed to be created: " + error_note.join(', ') |
|
138 | + flash[:error] = "Following user(s) failed to be created: " + error_note.join(', ') + ". The error of the first failed one are: " + error_msg; |
|
135 | end |
|
139 | end |
|
136 | redirect_to :action => 'index' |
|
140 | redirect_to :action => 'index' |
|
137 | end |
|
141 | end |
|
138 |
|
142 | ||
|
139 | def edit |
|
143 | def edit |
|
140 | @user = User.find(params[:id]) |
|
144 | @user = User.find(params[:id]) |
|
141 | end |
|
145 | end |
|
142 |
|
146 | ||
|
143 | def update |
|
147 | def update |
|
144 | @user = User.find(params[:id]) |
|
148 | @user = User.find(params[:id]) |
|
145 | if @user.update_attributes(user_params) |
|
149 | if @user.update_attributes(user_params) |
|
146 | flash[:notice] = 'User was successfully updated.' |
|
150 | flash[:notice] = 'User was successfully updated.' |
@@ -12,29 +12,31 | |||||
|
12 | .col-md-12 |
|
12 | .col-md-12 |
|
13 | %h1 Group details |
|
13 | %h1 Group details |
|
14 | .row |
|
14 | .row |
|
15 | .col-md-6 |
|
15 | .col-md-6 |
|
16 | .panel.panel-default |
|
16 | .panel.panel-default |
|
17 | .panel-heading |
|
17 | .panel-heading |
|
18 | .panel-title Users in this group |
|
18 | .panel-title Users in this group |
|
19 | .panel-body |
|
19 | .panel-body |
|
20 | %ul |
|
20 | %ul |
|
21 | %li |
|
21 | %li |
|
22 | If you want to add several users to a group, it may be easier to just re-import those users in |
|
22 | If you want to add several users to a group, it may be easier to just re-import those users in |
|
23 | = link_to 'New list of users', new_list_user_admin_index_path |
|
23 | = link_to 'New list of users', new_list_user_admin_index_path |
|
24 | - page |
|
24 | + page. You can also use |
|
|
25 | + = link_to 'Bulk Manage User', bulk_manage_user_admin_index_path | ||
|
|
26 | + page. | ||
|
25 | =form_tag add_user_group_path(@group), class: 'form-inline' do |
|
27 | =form_tag add_user_group_path(@group), class: 'form-inline' do |
|
26 | .form-group |
|
28 | .form-group |
|
27 | =label_tag :user_id, "User" |
|
29 | =label_tag :user_id, "User" |
|
28 | - =select_tag :user_id, options_from_collection_for_select(User.all,'id','full_name'), class: 'select2' |
|
30 | + =select_tag :user_id, options_from_collection_for_select(User.all,'id','full_name'), class: 'select2', style: 'width: 10em'; |
|
29 | =submit_tag "Add",class: 'btn btn-primary' |
|
31 | =submit_tag "Add",class: 'btn btn-primary' |
|
30 |
|
32 | ||
|
31 |
|
33 | ||
|
32 | %table.table.table-hover |
|
34 | %table.table.table-hover |
|
33 | %thead |
|
35 | %thead |
|
34 | %tr |
|
36 | %tr |
|
35 | %th Login |
|
37 | %th Login |
|
36 | %th Full name |
|
38 | %th Full name |
|
37 | %th Remark |
|
39 | %th Remark |
|
38 | %th= link_to 'Remove All', remove_all_user_group_path(@group), method: :delete, :data => { :confirm => "Remove ALL USERS from group?" }, class: 'btn btn-danger btn-sm' |
|
40 | %th= link_to 'Remove All', remove_all_user_group_path(@group), method: :delete, :data => { :confirm => "Remove ALL USERS from group?" }, class: 'btn btn-danger btn-sm' |
|
39 |
|
41 | ||
|
40 | %tbody |
|
42 | %tbody |
@@ -43,30 +45,30 | |||||
|
43 | %td= user.login |
|
45 | %td= user.login |
|
44 | %td= user.full_name |
|
46 | %td= user.full_name |
|
45 | %td= user.remark |
|
47 | %td= user.remark |
|
46 | %td= link_to 'Remove', remove_user_group_path(@group,user), :method => :delete, :data => { :confirm => "Remove #{user.full_name}?" }, class: 'btn btn-danger btn-sm' |
|
48 | %td= link_to 'Remove', remove_user_group_path(@group,user), :method => :delete, :data => { :confirm => "Remove #{user.full_name}?" }, class: 'btn btn-danger btn-sm' |
|
47 | .col-md-6 |
|
49 | .col-md-6 |
|
48 | .panel.panel-default |
|
50 | .panel.panel-default |
|
49 | .panel-heading |
|
51 | .panel-heading |
|
50 | .panel-title Problems |
|
52 | .panel-title Problems |
|
51 | .panel-body |
|
53 | .panel-body |
|
52 | %ul |
|
54 | %ul |
|
53 | %li |
|
55 | %li |
|
54 | If you want to add several problem to a group, it may be easier to bulk manage them in the |
|
56 | If you want to add several problem to a group, it may be easier to bulk manage them in the |
|
55 | - = link_to 'Bulk Manage', manage_problems_path |
|
57 | + = link_to 'Bulk Manage Problems', manage_problems_path |
|
56 | page |
|
58 | page |
|
57 | =form_tag add_problem_group_path(@group), class: 'form-inline' do |
|
59 | =form_tag add_problem_group_path(@group), class: 'form-inline' do |
|
58 | .form-group |
|
60 | .form-group |
|
59 | =label_tag :problem_id, "Problem" |
|
61 | =label_tag :problem_id, "Problem" |
|
60 | - =select_tag :problem_id, options_from_collection_for_select(Problem.all,'id','full_name'), class: 'select2' |
|
62 | + =select_tag :problem_id, options_from_collection_for_select(Problem.all,'id','full_name'), class: 'select2', style: 'width: 10em'; |
|
61 | =submit_tag "Add",class: 'btn btn-primary' |
|
63 | =submit_tag "Add",class: 'btn btn-primary' |
|
62 |
|
64 | ||
|
63 |
|
65 | ||
|
64 | %table.table.table-hover |
|
66 | %table.table.table-hover |
|
65 | %thead |
|
67 | %thead |
|
66 | %tr |
|
68 | %tr |
|
67 | %th name |
|
69 | %th name |
|
68 | %th Full name |
|
70 | %th Full name |
|
69 | %th Full score |
|
71 | %th Full score |
|
70 | %th= link_to 'Remove All', remove_all_problem_group_path(@group), method: :delete, :data => { :confirm => "Remove ALL PROBLEMS from group?" }, class: 'btn btn-danger btn-sm' |
|
72 | %th= link_to 'Remove All', remove_all_problem_group_path(@group), method: :delete, :data => { :confirm => "Remove ALL PROBLEMS from group?" }, class: 'btn btn-danger btn-sm' |
|
71 |
|
73 | ||
|
72 | %tbody |
|
74 | %tbody |
You need to be logged in to leave comments.
Login now