Description:
fix bugs when user creation error
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r812:e2597379728c - - 1 file changed: 1 inserted, 1 deleted
@@ -24,97 +24,97 | |||||
|
24 | end |
|
24 | end |
|
25 |
|
25 | ||
|
26 | def show |
|
26 | def show |
|
27 | @user = User.find(params[:id]) |
|
27 | @user = User.find(params[:id]) |
|
28 | end |
|
28 | end |
|
29 |
|
29 | ||
|
30 | def new |
|
30 | def new |
|
31 | @user = User.new |
|
31 | @user = User.new |
|
32 | end |
|
32 | end |
|
33 |
|
33 | ||
|
34 | def create |
|
34 | def create |
|
35 | @user = User.new(user_params) |
|
35 | @user = User.new(user_params) |
|
36 | @user.activated = true |
|
36 | @user.activated = true |
|
37 | if @user.save |
|
37 | if @user.save |
|
38 | flash[:notice] = 'User was successfully created.' |
|
38 | flash[:notice] = 'User was successfully created.' |
|
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 |
|
46 | @user = User.find(params[:id]) |
|
46 | @user = User.find(params[:id]) |
|
47 | @user.last_ip = nil |
|
47 | @user.last_ip = nil |
|
48 | @user.save |
|
48 | @user.save |
|
49 | redirect_to action: 'index', page: params[:page] |
|
49 | redirect_to action: 'index', page: params[:page] |
|
50 | end |
|
50 | end |
|
51 |
|
51 | ||
|
52 | def create_from_list |
|
52 | def create_from_list |
|
53 | lines = params[:user_list] |
|
53 | lines = params[:user_list] |
|
54 |
|
54 | ||
|
55 |
|
55 | ||
|
56 | res = User.create_from_list(lines) |
|
56 | res = User.create_from_list(lines) |
|
57 | error_logins = res[:error_logins] |
|
57 | error_logins = res[:error_logins] |
|
58 | error_msg = res[:first_error] |
|
58 | error_msg = res[:first_error] |
|
59 | ok_user = res[:created_users] |
|
59 | ok_user = res[:created_users] |
|
60 |
|
60 | ||
|
61 |
|
61 | ||
|
62 | #add to group |
|
62 | #add to group |
|
63 | if params[:add_to_group] |
|
63 | if params[:add_to_group] |
|
64 | group = Group.find_by(id: params[:group_id])&.add_users_skip_existing(ok_user) |
|
64 | group = Group.find_by(id: params[:group_id])&.add_users_skip_existing(ok_user) |
|
65 | end |
|
65 | end |
|
66 |
|
66 | ||
|
67 | # show flash |
|
67 | # show flash |
|
68 | if ok_user.count > 0 |
|
68 | if ok_user.count > 0 |
|
69 | flash[:success] = "#{ok_user.count} user(s) was created or updated successfully" |
|
69 | flash[:success] = "#{ok_user.count} user(s) was created or updated successfully" |
|
70 | end |
|
70 | end |
|
71 | if error_logins.size > 0 |
|
71 | if error_logins.size > 0 |
|
72 |
- flash[:error] = "Following user(s) failed to be created: " + error_ |
|
72 | + flash[:error] = "Following user(s) failed to be created: " + error_logins.join(', ') + ". The error of the first failed one are: " + error_msg; |
|
73 | end |
|
73 | end |
|
74 | redirect_to :action => 'index' |
|
74 | redirect_to :action => 'index' |
|
75 | end |
|
75 | end |
|
76 |
|
76 | ||
|
77 | def edit |
|
77 | def edit |
|
78 | @user = User.find(params[:id]) |
|
78 | @user = User.find(params[:id]) |
|
79 | end |
|
79 | end |
|
80 |
|
80 | ||
|
81 | def update |
|
81 | def update |
|
82 | @user = User.find(params[:id]) |
|
82 | @user = User.find(params[:id]) |
|
83 | if @user.update_attributes(user_params) |
|
83 | if @user.update_attributes(user_params) |
|
84 | flash[:notice] = 'User was successfully updated.' |
|
84 | flash[:notice] = 'User was successfully updated.' |
|
85 | redirect_to :action => 'show', :id => @user |
|
85 | redirect_to :action => 'show', :id => @user |
|
86 | else |
|
86 | else |
|
87 | render :action => 'edit' |
|
87 | render :action => 'edit' |
|
88 | end |
|
88 | end |
|
89 | end |
|
89 | end |
|
90 |
|
90 | ||
|
91 | def destroy |
|
91 | def destroy |
|
92 | User.find(params[:id]).destroy |
|
92 | User.find(params[:id]).destroy |
|
93 | redirect_to :action => 'index' |
|
93 | redirect_to :action => 'index' |
|
94 | end |
|
94 | end |
|
95 |
|
95 | ||
|
96 | def user_stat |
|
96 | def user_stat |
|
97 | if params[:commit] == 'download csv' |
|
97 | if params[:commit] == 'download csv' |
|
98 | @problems = Problem.all |
|
98 | @problems = Problem.all |
|
99 | else |
|
99 | else |
|
100 | @problems = Problem.available_problems |
|
100 | @problems = Problem.available_problems |
|
101 | end |
|
101 | end |
|
102 | @users = User.includes(:contests, :contest_stat).where(enabled: true) |
|
102 | @users = User.includes(:contests, :contest_stat).where(enabled: true) |
|
103 | @scorearray = Array.new |
|
103 | @scorearray = Array.new |
|
104 | @users.each do |u| |
|
104 | @users.each do |u| |
|
105 | ustat = Array.new |
|
105 | ustat = Array.new |
|
106 | ustat[0] = u |
|
106 | ustat[0] = u |
|
107 | @problems.each do |p| |
|
107 | @problems.each do |p| |
|
108 | sub = Submission.find_last_by_user_and_problem(u.id,p.id) |
|
108 | sub = Submission.find_last_by_user_and_problem(u.id,p.id) |
|
109 | if (sub!=nil) and (sub.points!=nil) and p and p.full_score |
|
109 | if (sub!=nil) and (sub.points!=nil) and p and p.full_score |
|
110 | ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)] |
|
110 | ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)] |
|
111 | else |
|
111 | else |
|
112 | ustat << [0,false] |
|
112 | ustat << [0,false] |
|
113 | end |
|
113 | end |
|
114 | end |
|
114 | end |
|
115 | @scorearray << ustat |
|
115 | @scorearray << ustat |
|
116 | end |
|
116 | end |
|
117 | if params[:commit] == 'download csv' then |
|
117 | if params[:commit] == 'download csv' then |
|
118 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
118 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
119 | send_data csv, filename: 'last_score.csv' |
|
119 | send_data csv, filename: 'last_score.csv' |
|
120 | else |
|
120 | else |
You need to be logged in to leave comments.
Login now