Description:
add user profile page listing all submission, permission is by 'right.user_view_submission' add link from users to their profile page
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r431:7654a9f33bc8 - - 6 files changed: 92 inserted, 14 deleted

@@ -0,0 +1,40
1 + - content_for :header do
2 + = javascript_include_tag 'new'
3 +
4 + %script{:type=>"text/javascript"}
5 + $(function () {
6 + $('#submission_table').tablesorter({widgets: ['zebra','filter']});
7 + });
8 +
9 + %h1= @user.full_name + ' Profile'
10 +
11 + %h2 Basic info
12 + <b>Login:</b> #{@user.login} <br/>
13 + <b>Full name:</b> #{@user.full_name} <br />
14 +
15 +
16 + %h2 Problem Stat
17 +
18 + %h2 Submissions
19 +
20 + %table.tablesorter-cafe#submission_table
21 + %thead
22 + %tr
23 + %th ID
24 + %th Problem code
25 + %th Problem name
26 + %th Language
27 + %th Result
28 + %th Score
29 + %tbody
30 + - @submission.each do |s|
31 + %tr
32 + %td= link_to "#{s.id}", controller: "graders", action: "submission", id: s.id
33 + %td= s.problem.name
34 + %td= s.problem.full_name
35 + %td= s.language.pretty_name
36 + %td{style: 'font-family: Droid Sans Mono,Consolas, monospace, mono'}= s.grader_comment
37 + %td= s.points/s.problem.full_score * 100
38 +
39 +
40 +
@@ -27,7 +27,8
27 end
27 end
28
28
29 User.all.each do |user|
29 User.all.each do |user|
30 - @logins << { login: user.login,
30 + @logins << { id: user.id,
31 + login: user.login,
31 full_name: user.full_name,
32 full_name: user.full_name,
32 count: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?",
33 count: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?",
33 user.id,@since_time,@until_time)
34 user.id,@since_time,@until_time)
@@ -14,6 +14,7
14 :register,
14 :register,
15 :forget,
15 :forget,
16 :retrieve_password]
16 :retrieve_password]
17 + before_filter :authenticate, :profile_authorization, only: [:profile]
17
18
18 verify :method => :post, :only => [:chg_passwd],
19 verify :method => :post, :only => [:chg_passwd],
19 :redirect_to => { :action => :index }
20 :redirect_to => { :action => :index }
@@ -108,6 +109,11
108 redirect_to :action => 'forget'
109 redirect_to :action => 'forget'
109 end
110 end
110
111
112 + def profile
113 + @user = User.find(params[:id])
114 + @submission = Submission.where(user_id: params[:id]).all
115 + end
116 +
111 protected
117 protected
112
118
113 def verify_online_registration
119 def verify_online_registration
@@ -152,5 +158,19
152
158
153 send_mail(user.email, mail_subject, mail_body)
159 send_mail(user.email, mail_subject, mail_body)
154 end
160 end
161 +
162 + # allow viewing of regular user profile only when options allow so
163 + # only admins can view admins profile
164 + def profile_authorization
165 + #if view admins' profile, allow only admin
166 + return false unless(params[:id])
167 + user = User.find(params[:id])
168 + return false unless user
169 + return admin_authorization if user.admin?
170 + return true if GraderConfiguration["right.user_view_submission"]
171 +
172 + #finally, we allow only admin
173 + admin_authorization
174 + end
155
175
156 end
176 end
@@ -7,22 +7,34
7
7
8 - if @best
8 - if @best
9 %b Best Runtime:
9 %b Best Runtime:
10 - by <span class="hof_user">#{@best[:runtime][:user]}</span> using <span class="hof_language">#{@best[:runtime][:lang]}</span> with <span class="hof_value">#{@best[:runtime][:value] * 1000} milliseconds</span> at submission
10 + by #{link_to @best[:runtime][:user], controller:'users', action:'profile', id:@best[:memory][:user_id]}
11 + using <span class="hof_language">#{@best[:runtime][:lang]}</span>
12 + with <span class="hof_value">#{@best[:runtime][:value] * 1000} milliseconds</span>
13 + at submission
11 = link_to("#" + @best[:runtime][:sub_id].to_s, controller: 'graders', action: 'submission', id:@best[:runtime][:sub_id])
14 = link_to("#" + @best[:runtime][:sub_id].to_s, controller: 'graders', action: 'submission', id:@best[:runtime][:sub_id])
12 %br/
15 %br/
13
16
14 %b Best Memory Usage:
17 %b Best Memory Usage:
15 - by <span class="hof_user">#{@best[:memory][:user]}</span> using <span class="hof_language">#{@best[:memory][:lang]}</span> with <span class="hof_value">#{@best[:memory][:value]} kbytes </span> at submission
18 + by #{link_to @best[:memory][:user], controller:'users', action:'profile', id:@best[:memory][:user_id]}
19 + using <span class="hof_language">#{@best[:memory][:lang]}</span>
20 + with <span class="hof_value">#{@best[:memory][:value]} kbytes </span>
21 + at submission
16 = link_to("#" + @best[:memory][:sub_id].to_s, controller: 'graders' , action: 'submission', id:@best[:memory][:sub_id])
22 = link_to("#" + @best[:memory][:sub_id].to_s, controller: 'graders' , action: 'submission', id:@best[:memory][:sub_id])
17 %br/
23 %br/
18
24
19 - %b Shortest Code:
25 + %b Shortest Code:
20 - by <span class="hof_user">#{@best[:length][:user]}</span> using <span class="hof_language">#{@best[:length][:lang]}</span> with <span class="hof_value">#{@best[:length][:value]} bytes</span> at submission
26 + by #{link_to @best[:length][:user], controller:'users', action:'profile', id:@best[:length][:user_id]}
27 + using <span class="hof_language">#{@best[:length][:lang]}</span>
28 + with <span class="hof_value">#{@best[:length][:value]} bytes</span>
29 + at submission
21 = link_to("#" + @best[:length][:sub_id].to_s, controller: 'graders' , action: 'submission', id: @best[:length][:sub_id])
30 = link_to("#" + @best[:length][:sub_id].to_s, controller: 'graders' , action: 'submission', id: @best[:length][:sub_id])
22 %br/
31 %br/
23
32
24 - %b First solver:
33 + %b First solver:
25 - <span class="hof_user">#{@best[:first][:user]}</span> is the first solver using <span class="hof_language">#{@best[:first][:lang]}</span> on <span class="hof_value">#{@best[:first][:value]}</span> at submission
34 + #{link_to @best[:first][:user], controller:'users', action:'profile', id:@best[:first][:user_id]} is the first solver
35 + using <span class="hof_language">#{@best[:first][:lang]}</span>
36 + on <span class="hof_value">#{@best[:first][:value]}</span>
37 + at submission
26 = link_to("#" + @best[:first][:sub_id].to_s, controller: 'graders' , action: 'submission', id: @best[:first][:sub_id])
38 = link_to("#" + @best[:first][:sub_id].to_s, controller: 'graders' , action: 'submission', id: @best[:first][:sub_id])
27 %br/
39 %br/
28
40
@@ -46,17 +58,22
46 %tr{class: cycle('info-even','info-odd')}
58 %tr{class: cycle('info-even','info-odd')}
47 %td= lang
59 %td= lang
48 %td
60 %td
49 - = "#{value[:runtime][:user]} (#{(value[:runtime][:value] * 1000).to_i} @"
61 + = link_to value[:runtime][:user], controller: 'users', action: 'profile', id: value[:runtime][:user_id]
62 + = "(#{(value[:runtime][:value] * 1000).to_i} @"
50 = "#{link_to("#" + value[:runtime][:sub_id].to_s, controller: 'graders' , action: 'submission', id: value[:runtime][:sub_id])} )".html_safe
63 = "#{link_to("#" + value[:runtime][:sub_id].to_s, controller: 'graders' , action: 'submission', id: value[:runtime][:sub_id])} )".html_safe
51 %td
64 %td
52 - = "#{value[:memory][:user]} (#{value[:memory][:value]} @"
65 + = link_to value[:memory][:user], controller: 'users', action: 'profile', id: value[:memory][:user_id]
66 + = "(#{value[:memory][:value]} @"
53 = "#{link_to("#" + value[:memory][:sub_id].to_s, controller: 'graders' , action: 'submission', id: value[:memory][:sub_id])} )".html_safe
67 = "#{link_to("#" + value[:memory][:sub_id].to_s, controller: 'graders' , action: 'submission', id: value[:memory][:sub_id])} )".html_safe
54 %td
68 %td
55 - = "#{value[:length][:user]} (#{value[:length][:value]} @"
69 + = link_to value[:length][:user], controller: 'users', action: 'profile', id: value[:length][:user_id]
70 + = "(#{value[:length][:value]} @"
56 = "#{link_to("#" + value[:length][:sub_id].to_s, controller: 'graders' , action: 'submission', id: value[:length][:sub_id])} )".html_safe
71 = "#{link_to("#" + value[:length][:sub_id].to_s, controller: 'graders' , action: 'submission', id: value[:length][:sub_id])} )".html_safe
57 %td
72 %td
58 - = "#{value[:first][:user]} (#{value[:first][:value]} @"
73 + - if value[:first][:user] != '(NULL)' #TODO: i know... this is wrong...
59 - = "#{link_to("#" + value[:first][:sub_id].to_s, controller: 'graders' , action: 'submission', id: value[:first][:sub_id])} )".html_safe
74 + = link_to value[:first][:user], controller: 'users', action: 'profile', id: value[:first][:user_id]
75 + = "(#{value[:first][:value]} @"
76 + = "#{link_to("#" + value[:first][:sub_id].to_s, controller: 'graders' , action: 'submission', id: value[:first][:sub_id])} )".html_safe
60
77
61 - else
78 - else
62 %h3 No submissions
79 %h3 No submissions
@@ -25,7 +25,7
25 %tbody
25 %tbody
26 - @logins.each do |l|
26 - @logins.each do |l|
27 %tr{class: cycle('info-even','info-odd')}
27 %tr{class: cycle('info-even','info-odd')}
28 - %td= l[:login]
28 + %td= link_to l[:login], controller: 'users', action: 'profile', id: l[:id]
29 %td= l[:full_name]
29 %td= l[:full_name]
30 %td= l[:count]
30 %td= l[:count]
31 %td= l[:min] ? l[:min].in_time_zone.strftime('%Y-%m-%d %H:%M') : ''
31 %td= l[:min] ? l[:min].in_time_zone.strftime('%Y-%m-%d %H:%M') : ''
@@ -41,7 +41,7
41 - total,num_passed = 0,0
41 - total,num_passed = 0,0
42 - sc.each_index do |i|
42 - sc.each_index do |i|
43 - if i == 0
43 - if i == 0
44 - %td= sc[i].login
44 + %td= link_to sc[i].login, controller: 'users', action: 'profile', id: sc[i]
45 %td= sc[i].full_name
45 %td= sc[i].full_name
46 %td= sc[i].activated
46 %td= sc[i].activated
47 %td= sc[i].try(:contest_stat).try(:started_at)!=nil ? 'yes' : 'no'
47 %td= sc[i].try(:contest_stat).try(:started_at)!=nil ? 'yes' : 'no'
You need to be logged in to leave comments. Login now