diff --git a/app/controllers/report_controller.rb b/app/controllers/report_controller.rb --- a/app/controllers/report_controller.rb +++ b/app/controllers/report_controller.rb @@ -27,7 +27,8 @@ end User.all.each do |user| - @logins << { login: user.login, + @logins << { id: user.id, + login: user.login, full_name: user.full_name, count: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", user.id,@since_time,@until_time) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -14,6 +14,7 @@ :register, :forget, :retrieve_password] + before_filter :authenticate, :profile_authorization, only: [:profile] verify :method => :post, :only => [:chg_passwd], :redirect_to => { :action => :index } @@ -108,6 +109,11 @@ redirect_to :action => 'forget' end + def profile + @user = User.find(params[:id]) + @submission = Submission.where(user_id: params[:id]).all + end + protected def verify_online_registration @@ -152,5 +158,19 @@ send_mail(user.email, mail_subject, mail_body) end + + # allow viewing of regular user profile only when options allow so + # only admins can view admins profile + def profile_authorization + #if view admins' profile, allow only admin + return false unless(params[:id]) + user = User.find(params[:id]) + return false unless user + return admin_authorization if user.admin? + return true if GraderConfiguration["right.user_view_submission"] + + #finally, we allow only admin + admin_authorization + end end diff --git a/app/views/report/_task_hof.html.haml b/app/views/report/_task_hof.html.haml --- a/app/views/report/_task_hof.html.haml +++ b/app/views/report/_task_hof.html.haml @@ -7,22 +7,34 @@ - if @best %b Best Runtime: - by #{@best[:runtime][:user]} using #{@best[:runtime][:lang]} with #{@best[:runtime][:value] * 1000} milliseconds at submission + by #{link_to @best[:runtime][:user], controller:'users', action:'profile', id:@best[:memory][:user_id]} + using #{@best[:runtime][:lang]} + with #{@best[:runtime][:value] * 1000} milliseconds + at submission = link_to("#" + @best[:runtime][:sub_id].to_s, controller: 'graders', action: 'submission', id:@best[:runtime][:sub_id]) %br/ %b Best Memory Usage: - by #{@best[:memory][:user]} using #{@best[:memory][:lang]} with #{@best[:memory][:value]} kbytes at submission + by #{link_to @best[:memory][:user], controller:'users', action:'profile', id:@best[:memory][:user_id]} + using #{@best[:memory][:lang]} + with #{@best[:memory][:value]} kbytes + at submission = link_to("#" + @best[:memory][:sub_id].to_s, controller: 'graders' , action: 'submission', id:@best[:memory][:sub_id]) %br/ - %b Shortest Code: - by #{@best[:length][:user]} using #{@best[:length][:lang]} with #{@best[:length][:value]} bytes at submission + %b Shortest Code: + by #{link_to @best[:length][:user], controller:'users', action:'profile', id:@best[:length][:user_id]} + using #{@best[:length][:lang]} + with #{@best[:length][:value]} bytes + at submission = link_to("#" + @best[:length][:sub_id].to_s, controller: 'graders' , action: 'submission', id: @best[:length][:sub_id]) %br/ - %b First solver: - #{@best[:first][:user]} is the first solver using #{@best[:first][:lang]} on #{@best[:first][:value]} at submission + %b First solver: + #{link_to @best[:first][:user], controller:'users', action:'profile', id:@best[:first][:user_id]} is the first solver + using #{@best[:first][:lang]} + on #{@best[:first][:value]} + at submission = link_to("#" + @best[:first][:sub_id].to_s, controller: 'graders' , action: 'submission', id: @best[:first][:sub_id]) %br/ @@ -46,17 +58,22 @@ %tr{class: cycle('info-even','info-odd')} %td= lang %td - = "#{value[:runtime][:user]} (#{(value[:runtime][:value] * 1000).to_i} @" + = link_to value[:runtime][:user], controller: 'users', action: 'profile', id: value[:runtime][:user_id] + = "(#{(value[:runtime][:value] * 1000).to_i} @" = "#{link_to("#" + value[:runtime][:sub_id].to_s, controller: 'graders' , action: 'submission', id: value[:runtime][:sub_id])} )".html_safe %td - = "#{value[:memory][:user]} (#{value[:memory][:value]} @" + = link_to value[:memory][:user], controller: 'users', action: 'profile', id: value[:memory][:user_id] + = "(#{value[:memory][:value]} @" = "#{link_to("#" + value[:memory][:sub_id].to_s, controller: 'graders' , action: 'submission', id: value[:memory][:sub_id])} )".html_safe %td - = "#{value[:length][:user]} (#{value[:length][:value]} @" + = link_to value[:length][:user], controller: 'users', action: 'profile', id: value[:length][:user_id] + = "(#{value[:length][:value]} @" = "#{link_to("#" + value[:length][:sub_id].to_s, controller: 'graders' , action: 'submission', id: value[:length][:sub_id])} )".html_safe %td - = "#{value[:first][:user]} (#{value[:first][:value]} @" - = "#{link_to("#" + value[:first][:sub_id].to_s, controller: 'graders' , action: 'submission', id: value[:first][:sub_id])} )".html_safe + - if value[:first][:user] != '(NULL)' #TODO: i know... this is wrong... + = link_to value[:first][:user], controller: 'users', action: 'profile', id: value[:first][:user_id] + = "(#{value[:first][:value]} @" + = "#{link_to("#" + value[:first][:sub_id].to_s, controller: 'graders' , action: 'submission', id: value[:first][:sub_id])} )".html_safe - else %h3 No submissions diff --git a/app/views/report/login_stat.html.haml b/app/views/report/login_stat.html.haml --- a/app/views/report/login_stat.html.haml +++ b/app/views/report/login_stat.html.haml @@ -25,7 +25,7 @@ %tbody - @logins.each do |l| %tr{class: cycle('info-even','info-odd')} - %td= l[:login] + %td= link_to l[:login], controller: 'users', action: 'profile', id: l[:id] %td= l[:full_name] %td= l[:count] %td= l[:min] ? l[:min].in_time_zone.strftime('%Y-%m-%d %H:%M') : '' diff --git a/app/views/user_admin/user_stat.html.haml b/app/views/user_admin/user_stat.html.haml --- a/app/views/user_admin/user_stat.html.haml +++ b/app/views/user_admin/user_stat.html.haml @@ -41,7 +41,7 @@ - total,num_passed = 0,0 - sc.each_index do |i| - if i == 0 - %td= sc[i].login + %td= link_to sc[i].login, controller: 'users', action: 'profile', id: sc[i] %td= sc[i].full_name %td= sc[i].activated %td= sc[i].try(:contest_stat).try(:started_at)!=nil ? 'yes' : 'no' diff --git a/app/views/users/profile.html.haml b/app/views/users/profile.html.haml new file mode 100644 --- /dev/null +++ b/app/views/users/profile.html.haml @@ -0,0 +1,40 @@ +- content_for :header do + = javascript_include_tag 'new' + +%script{:type=>"text/javascript"} + $(function () { + $('#submission_table').tablesorter({widgets: ['zebra','filter']}); + }); + +%h1= @user.full_name + ' Profile' + +%h2 Basic info +Login: #{@user.login}
+Full name: #{@user.full_name}
+ + +%h2 Problem Stat + +%h2 Submissions + +%table.tablesorter-cafe#submission_table + %thead + %tr + %th ID + %th Problem code + %th Problem name + %th Language + %th Result + %th Score + %tbody + - @submission.each do |s| + %tr + %td= link_to "#{s.id}", controller: "graders", action: "submission", id: s.id + %td= s.problem.name + %td= s.problem.full_name + %td= s.language.pretty_name + %td{style: 'font-family: Droid Sans Mono,Consolas, monospace, mono'}= s.grader_comment + %td= s.points/s.problem.full_score * 100 + + +