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
r858:21c0ea2ca2c0 - - 2 files changed: 7 inserted, 6 deleted
@@ -51,50 +51,48 | |||
|
51 | 51 | end |
|
52 | 52 | |
|
53 | 53 | def authorization_by_roles(allowed_roles) |
|
54 | 54 | return false unless check_valid_login |
|
55 | 55 | unless @current_user.roles.detect { |role| allowed_roles.member?(role.name) } |
|
56 | 56 | unauthorized_redirect |
|
57 | 57 | return false |
|
58 | 58 | end |
|
59 | 59 | end |
|
60 | 60 | |
|
61 | 61 | def testcase_authorization |
|
62 | 62 | #admin always has privileged |
|
63 | 63 | if @current_user.admin? |
|
64 | 64 | return true |
|
65 | 65 | end |
|
66 | 66 | |
|
67 | 67 | unauthorized_redirect unless GraderConfiguration["right.view_testcase"] |
|
68 | 68 | end |
|
69 | 69 | |
|
70 | 70 | def unique_visitor_id |
|
71 | 71 | unless cookies.encrypted[:uuid] |
|
72 | 72 | value = SecureRandom.uuid |
|
73 | 73 | cookies.encrypted[:uuid] = { value: value, expires: 20.year } |
|
74 | 74 | end |
|
75 | - puts "encrypt " + cookies.encrypted[:uuid] | |
|
76 | - puts cookies[:uuid] | |
|
77 | 75 | end |
|
78 | 76 | |
|
79 | 77 | protected |
|
80 | 78 | |
|
81 | 79 | #redirect to root (and also force logout) |
|
82 | 80 | #if the user is not logged_in or the system is in "ADMIN ONLY" mode |
|
83 | 81 | def check_valid_login |
|
84 | 82 | #check if logged in |
|
85 | 83 | unless session[:user_id] |
|
86 | 84 | if GraderConfiguration[SINGLE_USER_MODE_CONF_KEY] |
|
87 | 85 | unauthorized_redirect('You need to login but you cannot log in at this time') |
|
88 | 86 | else |
|
89 | 87 | unauthorized_redirect('You need to login') |
|
90 | 88 | end |
|
91 | 89 | return false |
|
92 | 90 | end |
|
93 | 91 | |
|
94 | 92 | # check if run in single user mode |
|
95 | 93 | if GraderConfiguration[SINGLE_USER_MODE_CONF_KEY] |
|
96 | 94 | if @current_user==nil || (!@current_user.admin?) |
|
97 | 95 | unauthorized_redirect('You cannot log in at this time') |
|
98 | 96 | return false |
|
99 | 97 | end |
|
100 | 98 | end |
@@ -98,92 +98,95 | |||
|
98 | 98 | end |
|
99 | 99 | end |
|
100 | 100 | @scorearray << ustat |
|
101 | 101 | end |
|
102 | 102 | if params[:commit] == 'download csv' then |
|
103 | 103 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
104 | 104 | send_data csv, filename: 'last_score.csv' |
|
105 | 105 | else |
|
106 | 106 | render template: 'user_admin/user_stat' |
|
107 | 107 | end |
|
108 | 108 | |
|
109 | 109 | end |
|
110 | 110 | |
|
111 | 111 | def login |
|
112 | 112 | end |
|
113 | 113 | |
|
114 | 114 | def login_summary_query |
|
115 | 115 | @users = Array.new |
|
116 | 116 | |
|
117 | 117 | date_and_time = '%Y-%m-%d %H:%M' |
|
118 | 118 | begin |
|
119 | 119 | md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
120 | 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 | 121 | rescue |
|
122 |
- @since_time = |
|
|
122 | + @since_time = Time.zone.now | |
|
123 | 123 | end |
|
124 | + puts @since_time | |
|
124 | 125 | begin |
|
125 | 126 | md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
126 | 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 | 128 | rescue |
|
128 | 129 | @until_time = DateTime.new(3000,1,1) |
|
129 | 130 | end |
|
130 | 131 | |
|
131 | 132 | record = User |
|
132 | 133 | .left_outer_joins(:logins).group('users.id') |
|
133 | 134 | .where("logins.created_at >= ? AND logins.created_at <= ?",@since_time, @until_time) |
|
134 | 135 | case params[:users] |
|
135 | 136 | when 'enabled' |
|
136 | 137 | record = record.where(enabled: true) |
|
137 | 138 | when 'group' |
|
138 | 139 | record = record.joins(:groups).where(groups: {id: params[:groups]}) if params[:groups] |
|
139 | 140 | end |
|
140 | 141 | |
|
141 | 142 | record = record.pluck("users.id,users.login,users.full_name,count(logins.created_at),min(logins.created_at),max(logins.created_at)") |
|
142 | 143 | record.each do |user| |
|
143 | 144 | x = Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
144 | 145 | user[0],@since_time,@until_time) |
|
145 | 146 | .pluck(:ip_address).uniq |
|
147 | + puts user[4] | |
|
148 | + puts user[5] | |
|
146 | 149 | @users << { id: user[0], |
|
147 | 150 | login: user[1], |
|
148 | 151 | full_name: user[2], |
|
149 | 152 | count: user[3], |
|
150 | - min: user[4], | |
|
151 | - max: user[5], | |
|
153 | + min: user[4].in_time_zone, | |
|
154 | + max: user[5].in_time_zone, | |
|
152 | 155 | ip: x |
|
153 | 156 | } |
|
154 | 157 | end |
|
155 | 158 | end |
|
156 | 159 | |
|
157 | 160 | def login_detail_query |
|
158 | 161 | @logins = Array.new |
|
159 | 162 | |
|
160 | 163 | date_and_time = '%Y-%m-%d %H:%M' |
|
161 | 164 | begin |
|
162 | 165 | md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
163 | 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 | 167 | rescue |
|
165 |
- @since_time = |
|
|
168 | + @since_time = Time.zone.now | |
|
166 | 169 | end |
|
167 | 170 | begin |
|
168 | 171 | md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
169 | 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 | 173 | rescue |
|
171 | 174 | @until_time = DateTime.new(3000,1,1) |
|
172 | 175 | end |
|
173 | 176 | |
|
174 | 177 | @logins = Login.includes(:user).where("logins.created_at >= ? AND logins.created_at <= ?",@since_time, @until_time) |
|
175 | 178 | case params[:users] |
|
176 | 179 | when 'enabled' |
|
177 | 180 | @logins = @logins.where(users: {enabled: true}) |
|
178 | 181 | when 'group' |
|
179 | 182 | @logins = @logins.joins(user: :groups).where(user: {groups: {id: params[:groups]}}) if params[:groups] |
|
180 | 183 | end |
|
181 | 184 | end |
|
182 | 185 | |
|
183 | 186 | def submission |
|
184 | 187 | end |
|
185 | 188 | |
|
186 | 189 | def submission_query |
|
187 | 190 | @submissions = Submission |
|
188 | 191 | .includes(:problem).includes(:user).includes(:language) |
|
189 | 192 |
You need to be logged in to leave comments.
Login now