Description:
fig bugs in login report
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r859:d7fa5bf1aeba - - 2 files changed: 7 inserted, 6 deleted
@@ -27,98 +27,96 | |||||
|
27 |
|
27 | ||
|
28 | def nav_announcement |
|
28 | def nav_announcement |
|
29 | @nav_announcement = Announcement.where(on_nav_bar: true) |
|
29 | @nav_announcement = Announcement.where(on_nav_bar: true) |
|
30 | end |
|
30 | end |
|
31 |
|
31 | ||
|
32 | def admin_authorization |
|
32 | def admin_authorization |
|
33 | return false unless check_valid_login |
|
33 | return false unless check_valid_login |
|
34 | user = User.includes(:roles).find(session[:user_id]) |
|
34 | user = User.includes(:roles).find(session[:user_id]) |
|
35 | unless user.admin? |
|
35 | unless user.admin? |
|
36 | unauthorized_redirect |
|
36 | unauthorized_redirect |
|
37 | return false |
|
37 | return false |
|
38 | end |
|
38 | end |
|
39 | return true |
|
39 | return true |
|
40 | end |
|
40 | end |
|
41 |
|
41 | ||
|
42 | #admin always count as every roles |
|
42 | #admin always count as every roles |
|
43 | def role_authorization(roles) |
|
43 | def role_authorization(roles) |
|
44 | return false unless check_valid_login |
|
44 | return false unless check_valid_login |
|
45 | user = User.find(session[:user_id]) |
|
45 | user = User.find(session[:user_id]) |
|
46 | return true if user.admin? |
|
46 | return true if user.admin? |
|
47 | roles.each do |r| |
|
47 | roles.each do |r| |
|
48 | return true if user.has_role?(r) |
|
48 | return true if user.has_role?(r) |
|
49 | end |
|
49 | end |
|
50 | unauthorized_redirect |
|
50 | unauthorized_redirect |
|
51 | end |
|
51 | end |
|
52 |
|
52 | ||
|
53 | def authorization_by_roles(allowed_roles) |
|
53 | def authorization_by_roles(allowed_roles) |
|
54 | return false unless check_valid_login |
|
54 | return false unless check_valid_login |
|
55 | unless @current_user.roles.detect { |role| allowed_roles.member?(role.name) } |
|
55 | unless @current_user.roles.detect { |role| allowed_roles.member?(role.name) } |
|
56 | unauthorized_redirect |
|
56 | unauthorized_redirect |
|
57 | return false |
|
57 | return false |
|
58 | end |
|
58 | end |
|
59 | end |
|
59 | end |
|
60 |
|
60 | ||
|
61 | def testcase_authorization |
|
61 | def testcase_authorization |
|
62 | #admin always has privileged |
|
62 | #admin always has privileged |
|
63 | if @current_user.admin? |
|
63 | if @current_user.admin? |
|
64 | return true |
|
64 | return true |
|
65 | end |
|
65 | end |
|
66 |
|
66 | ||
|
67 | unauthorized_redirect unless GraderConfiguration["right.view_testcase"] |
|
67 | unauthorized_redirect unless GraderConfiguration["right.view_testcase"] |
|
68 | end |
|
68 | end |
|
69 |
|
69 | ||
|
70 | def unique_visitor_id |
|
70 | def unique_visitor_id |
|
71 | unless cookies.encrypted[:uuid] |
|
71 | unless cookies.encrypted[:uuid] |
|
72 | value = SecureRandom.uuid |
|
72 | value = SecureRandom.uuid |
|
73 | cookies.encrypted[:uuid] = { value: value, expires: 20.year } |
|
73 | cookies.encrypted[:uuid] = { value: value, expires: 20.year } |
|
74 | end |
|
74 | end |
|
75 | - puts "encrypt " + cookies.encrypted[:uuid] |
|
||
|
76 | - puts cookies[:uuid] |
|
||
|
77 | end |
|
75 | end |
|
78 |
|
76 | ||
|
79 | protected |
|
77 | protected |
|
80 |
|
78 | ||
|
81 | #redirect to root (and also force logout) |
|
79 | #redirect to root (and also force logout) |
|
82 | #if the user is not logged_in or the system is in "ADMIN ONLY" mode |
|
80 | #if the user is not logged_in or the system is in "ADMIN ONLY" mode |
|
83 | def check_valid_login |
|
81 | def check_valid_login |
|
84 | #check if logged in |
|
82 | #check if logged in |
|
85 | unless session[:user_id] |
|
83 | unless session[:user_id] |
|
86 | if GraderConfiguration[SINGLE_USER_MODE_CONF_KEY] |
|
84 | if GraderConfiguration[SINGLE_USER_MODE_CONF_KEY] |
|
87 | unauthorized_redirect('You need to login but you cannot log in at this time') |
|
85 | unauthorized_redirect('You need to login but you cannot log in at this time') |
|
88 | else |
|
86 | else |
|
89 | unauthorized_redirect('You need to login') |
|
87 | unauthorized_redirect('You need to login') |
|
90 | end |
|
88 | end |
|
91 | return false |
|
89 | return false |
|
92 | end |
|
90 | end |
|
93 |
|
91 | ||
|
94 | # check if run in single user mode |
|
92 | # check if run in single user mode |
|
95 | if GraderConfiguration[SINGLE_USER_MODE_CONF_KEY] |
|
93 | if GraderConfiguration[SINGLE_USER_MODE_CONF_KEY] |
|
96 | if @current_user==nil || (!@current_user.admin?) |
|
94 | if @current_user==nil || (!@current_user.admin?) |
|
97 | unauthorized_redirect('You cannot log in at this time') |
|
95 | unauthorized_redirect('You cannot log in at this time') |
|
98 | return false |
|
96 | return false |
|
99 | end |
|
97 | end |
|
100 | end |
|
98 | end |
|
101 |
|
99 | ||
|
102 | # check if the user is enabled |
|
100 | # check if the user is enabled |
|
103 | unless @current_user.enabled? || @current_user.admin? |
|
101 | unless @current_user.enabled? || @current_user.admin? |
|
104 | unauthorized_redirect 'Your account is disabled' |
|
102 | unauthorized_redirect 'Your account is disabled' |
|
105 | return false |
|
103 | return false |
|
106 | end |
|
104 | end |
|
107 |
|
105 | ||
|
108 | # check if user ip is allowed |
|
106 | # check if user ip is allowed |
|
109 | unless @current_user.admin? || GraderConfiguration[WHITELIST_IGNORE_CONF_KEY] |
|
107 | unless @current_user.admin? || GraderConfiguration[WHITELIST_IGNORE_CONF_KEY] |
|
110 | unless is_request_ip_allowed? |
|
108 | unless is_request_ip_allowed? |
|
111 | unauthorized_redirect 'Your IP is not allowed to login at this time.' |
|
109 | unauthorized_redirect 'Your IP is not allowed to login at this time.' |
|
112 | return false |
|
110 | return false |
|
113 | end |
|
111 | end |
|
114 | end |
|
112 | end |
|
115 |
|
113 | ||
|
116 | if GraderConfiguration.multicontests? |
|
114 | if GraderConfiguration.multicontests? |
|
117 | return true if @current_user.admin? |
|
115 | return true if @current_user.admin? |
|
118 | begin |
|
116 | begin |
|
119 | if @current_user.contest_stat(true).forced_logout |
|
117 | if @current_user.contest_stat(true).forced_logout |
|
120 | flash[:notice] = 'You have been automatically logged out.' |
|
118 | flash[:notice] = 'You have been automatically logged out.' |
|
121 | redirect_to :controller => 'main', :action => 'index' |
|
119 | redirect_to :controller => 'main', :action => 'index' |
|
122 | end |
|
120 | end |
|
123 | rescue |
|
121 | rescue |
|
124 | end |
|
122 | end |
@@ -74,140 +74,143 | |||||
|
74 | else |
|
74 | else |
|
75 | #render template: 'user_admin/user_stat' |
|
75 | #render template: 'user_admin/user_stat' |
|
76 | render 'max_score' |
|
76 | render 'max_score' |
|
77 | end |
|
77 | end |
|
78 |
|
78 | ||
|
79 | end |
|
79 | end |
|
80 |
|
80 | ||
|
81 | def score |
|
81 | def score |
|
82 | if params[:commit] == 'download csv' |
|
82 | if params[:commit] == 'download csv' |
|
83 | @problems = Problem.all |
|
83 | @problems = Problem.all |
|
84 | else |
|
84 | else |
|
85 | @problems = Problem.available_problems |
|
85 | @problems = Problem.available_problems |
|
86 | end |
|
86 | end |
|
87 | @users = User.includes(:contests, :contest_stat).where(enabled: true) |
|
87 | @users = User.includes(:contests, :contest_stat).where(enabled: true) |
|
88 | @scorearray = Array.new |
|
88 | @scorearray = Array.new |
|
89 | @users.each do |u| |
|
89 | @users.each do |u| |
|
90 | ustat = Array.new |
|
90 | ustat = Array.new |
|
91 | ustat[0] = u |
|
91 | ustat[0] = u |
|
92 | @problems.each do |p| |
|
92 | @problems.each do |p| |
|
93 | sub = Submission.find_last_by_user_and_problem(u.id,p.id) |
|
93 | sub = Submission.find_last_by_user_and_problem(u.id,p.id) |
|
94 | if (sub!=nil) and (sub.points!=nil) and p and p.full_score |
|
94 | if (sub!=nil) and (sub.points!=nil) and p and p.full_score |
|
95 | ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)] |
|
95 | ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)] |
|
96 | else |
|
96 | else |
|
97 | ustat << [0,false] |
|
97 | ustat << [0,false] |
|
98 | end |
|
98 | end |
|
99 | end |
|
99 | end |
|
100 | @scorearray << ustat |
|
100 | @scorearray << ustat |
|
101 | end |
|
101 | end |
|
102 | if params[:commit] == 'download csv' then |
|
102 | if params[:commit] == 'download csv' then |
|
103 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
103 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
104 | send_data csv, filename: 'last_score.csv' |
|
104 | send_data csv, filename: 'last_score.csv' |
|
105 | else |
|
105 | else |
|
106 | render template: 'user_admin/user_stat' |
|
106 | render template: 'user_admin/user_stat' |
|
107 | end |
|
107 | end |
|
108 |
|
108 | ||
|
109 | end |
|
109 | end |
|
110 |
|
110 | ||
|
111 | def login |
|
111 | def login |
|
112 | end |
|
112 | end |
|
113 |
|
113 | ||
|
114 | def login_summary_query |
|
114 | def login_summary_query |
|
115 | @users = Array.new |
|
115 | @users = Array.new |
|
116 |
|
116 | ||
|
117 | date_and_time = '%Y-%m-%d %H:%M' |
|
117 | date_and_time = '%Y-%m-%d %H:%M' |
|
118 | begin |
|
118 | begin |
|
119 | md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
119 | md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
120 | @since_time = Time.zone.local(md[1].to_i,md[2].to_i,md[3].to_i,md[4].to_i,md[5].to_i) |
|
120 | @since_time = Time.zone.local(md[1].to_i,md[2].to_i,md[3].to_i,md[4].to_i,md[5].to_i) |
|
121 | rescue |
|
121 | rescue |
|
122 |
- @since_time = |
|
122 | + @since_time = Time.zone.now |
|
123 | end |
|
123 | end |
|
|
124 | + puts @since_time | ||
|
124 | begin |
|
125 | begin |
|
125 | md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
126 | md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
126 | @until_time = Time.zone.local(md[1].to_i,md[2].to_i,md[3].to_i,md[4].to_i,md[5].to_i) |
|
127 | @until_time = Time.zone.local(md[1].to_i,md[2].to_i,md[3].to_i,md[4].to_i,md[5].to_i) |
|
127 | rescue |
|
128 | rescue |
|
128 | @until_time = DateTime.new(3000,1,1) |
|
129 | @until_time = DateTime.new(3000,1,1) |
|
129 | end |
|
130 | end |
|
130 |
|
131 | ||
|
131 | record = User |
|
132 | record = User |
|
132 | .left_outer_joins(:logins).group('users.id') |
|
133 | .left_outer_joins(:logins).group('users.id') |
|
133 | .where("logins.created_at >= ? AND logins.created_at <= ?",@since_time, @until_time) |
|
134 | .where("logins.created_at >= ? AND logins.created_at <= ?",@since_time, @until_time) |
|
134 | case params[:users] |
|
135 | case params[:users] |
|
135 | when 'enabled' |
|
136 | when 'enabled' |
|
136 | record = record.where(enabled: true) |
|
137 | record = record.where(enabled: true) |
|
137 | when 'group' |
|
138 | when 'group' |
|
138 | record = record.joins(:groups).where(groups: {id: params[:groups]}) if params[:groups] |
|
139 | record = record.joins(:groups).where(groups: {id: params[:groups]}) if params[:groups] |
|
139 | end |
|
140 | end |
|
140 |
|
141 | ||
|
141 | record = record.pluck("users.id,users.login,users.full_name,count(logins.created_at),min(logins.created_at),max(logins.created_at)") |
|
142 | record = record.pluck("users.id,users.login,users.full_name,count(logins.created_at),min(logins.created_at),max(logins.created_at)") |
|
142 | record.each do |user| |
|
143 | record.each do |user| |
|
143 | x = Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
144 | x = Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
144 | user[0],@since_time,@until_time) |
|
145 | user[0],@since_time,@until_time) |
|
145 | .pluck(:ip_address).uniq |
|
146 | .pluck(:ip_address).uniq |
|
|
147 | + puts user[4] | ||
|
|
148 | + puts user[5] | ||
|
146 | @users << { id: user[0], |
|
149 | @users << { id: user[0], |
|
147 | login: user[1], |
|
150 | login: user[1], |
|
148 | full_name: user[2], |
|
151 | full_name: user[2], |
|
149 | count: user[3], |
|
152 | count: user[3], |
|
150 | - min: user[4], |
|
153 | + min: user[4].in_time_zone, |
|
151 | - max: user[5], |
|
154 | + max: user[5].in_time_zone, |
|
152 | ip: x |
|
155 | ip: x |
|
153 | } |
|
156 | } |
|
154 | end |
|
157 | end |
|
155 | end |
|
158 | end |
|
156 |
|
159 | ||
|
157 | def login_detail_query |
|
160 | def login_detail_query |
|
158 | @logins = Array.new |
|
161 | @logins = Array.new |
|
159 |
|
162 | ||
|
160 | date_and_time = '%Y-%m-%d %H:%M' |
|
163 | date_and_time = '%Y-%m-%d %H:%M' |
|
161 | begin |
|
164 | begin |
|
162 | md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
165 | md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
163 | @since_time = Time.zone.local(md[1].to_i,md[2].to_i,md[3].to_i,md[4].to_i,md[5].to_i) |
|
166 | @since_time = Time.zone.local(md[1].to_i,md[2].to_i,md[3].to_i,md[4].to_i,md[5].to_i) |
|
164 | rescue |
|
167 | rescue |
|
165 |
- @since_time = |
|
168 | + @since_time = Time.zone.now |
|
166 | end |
|
169 | end |
|
167 | begin |
|
170 | begin |
|
168 | md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
171 | md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
169 | @until_time = Time.zone.local(md[1].to_i,md[2].to_i,md[3].to_i,md[4].to_i,md[5].to_i) |
|
172 | @until_time = Time.zone.local(md[1].to_i,md[2].to_i,md[3].to_i,md[4].to_i,md[5].to_i) |
|
170 | rescue |
|
173 | rescue |
|
171 | @until_time = DateTime.new(3000,1,1) |
|
174 | @until_time = DateTime.new(3000,1,1) |
|
172 | end |
|
175 | end |
|
173 |
|
176 | ||
|
174 | @logins = Login.includes(:user).where("logins.created_at >= ? AND logins.created_at <= ?",@since_time, @until_time) |
|
177 | @logins = Login.includes(:user).where("logins.created_at >= ? AND logins.created_at <= ?",@since_time, @until_time) |
|
175 | case params[:users] |
|
178 | case params[:users] |
|
176 | when 'enabled' |
|
179 | when 'enabled' |
|
177 | @logins = @logins.where(users: {enabled: true}) |
|
180 | @logins = @logins.where(users: {enabled: true}) |
|
178 | when 'group' |
|
181 | when 'group' |
|
179 | @logins = @logins.joins(user: :groups).where(user: {groups: {id: params[:groups]}}) if params[:groups] |
|
182 | @logins = @logins.joins(user: :groups).where(user: {groups: {id: params[:groups]}}) if params[:groups] |
|
180 | end |
|
183 | end |
|
181 | end |
|
184 | end |
|
182 |
|
185 | ||
|
183 | def submission |
|
186 | def submission |
|
184 | end |
|
187 | end |
|
185 |
|
188 | ||
|
186 | def submission_query |
|
189 | def submission_query |
|
187 | @submissions = Submission |
|
190 | @submissions = Submission |
|
188 | .includes(:problem).includes(:user).includes(:language) |
|
191 | .includes(:problem).includes(:user).includes(:language) |
|
189 |
|
192 | ||
|
190 | case params[:users] |
|
193 | case params[:users] |
|
191 | when 'enabled' |
|
194 | when 'enabled' |
|
192 | @submissions = @submissions.where(users: {enabled: true}) |
|
195 | @submissions = @submissions.where(users: {enabled: true}) |
|
193 | when 'group' |
|
196 | when 'group' |
|
194 | @submissions = @submissions.joins(user: :groups).where(user: {groups: {id: params[:groups]}}) if params[:groups] |
|
197 | @submissions = @submissions.joins(user: :groups).where(user: {groups: {id: params[:groups]}}) if params[:groups] |
|
195 | end |
|
198 | end |
|
196 |
|
199 | ||
|
197 | case params[:problems] |
|
200 | case params[:problems] |
|
198 | when 'enabled' |
|
201 | when 'enabled' |
|
199 | @submissions = @submissions.where(problems: {available: true}) |
|
202 | @submissions = @submissions.where(problems: {available: true}) |
|
200 | when 'selected' |
|
203 | when 'selected' |
|
201 | @submissions = @submissions.where(problem_id: params[:problem_id]) |
|
204 | @submissions = @submissions.where(problem_id: params[:problem_id]) |
|
202 | end |
|
205 | end |
|
203 |
|
206 | ||
|
204 | #set default |
|
207 | #set default |
|
205 | params[:since_datetime] = Date.today.to_s if params[:since_datetime].blank? |
|
208 | params[:since_datetime] = Date.today.to_s if params[:since_datetime].blank? |
|
206 |
|
209 | ||
|
207 | @submissions, @recordsTotal, @recordsFiltered = process_query_record( @submissions, |
|
210 | @submissions, @recordsTotal, @recordsFiltered = process_query_record( @submissions, |
|
208 | global_search: ['user.login','user.full_name','problem.name','problem.full_name','points'], |
|
211 | global_search: ['user.login','user.full_name','problem.name','problem.full_name','points'], |
|
209 | date_filter: 'submitted_at', |
|
212 | date_filter: 'submitted_at', |
|
210 | date_param_since: 'since_datetime', |
|
213 | date_param_since: 'since_datetime', |
|
211 | date_param_until: 'until_datetime', |
|
214 | date_param_until: 'until_datetime', |
|
212 | hard_limit: 100_000 |
|
215 | hard_limit: 100_000 |
|
213 | ) |
|
216 | ) |
You need to be logged in to leave comments.
Login now