# HG changeset patch # User Nattee Niparnan # Date 2014-09-11 17:55:26 # Node ID b86f327e0d75ce6ddd8345676f77cc9b126c086c # Parent 217b94aa4f7643e38ec786b6a38cd6c3089d3b63 prepare for better hall of fame diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -6,7 +6,12 @@ def admin_authorization return false unless authenticate user = User.find(session[:user_id], :include => ['roles']) - redirect_to :controller => 'main', :action => 'login' unless user.admin? + unless user.admin? + flash[:notice] = 'You are not authorized to view the page you requested' + redirect_to :controller => 'main', :action => 'login' unless user.admin? + return false + end + return true end def authorization_by_roles(allowed_roles) diff --git a/app/controllers/graders_controller.rb b/app/controllers/graders_controller.rb --- a/app/controllers/graders_controller.rb +++ b/app/controllers/graders_controller.rb @@ -1,6 +1,15 @@ class GradersController < ApplicationController - before_filter :admin_authorization + before_filter :admin_authorization, except: [ :submission ] + before_filter(only: [:submission]) { + return false unless authenticate + + if GraderConfiguration["right.user_view_submission"] + return true; + end + + admin_authorization + } verify :method => :post, :only => ['clear_all', 'start_exam', 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 @@ -1,10 +1,10 @@ class ReportController < ApplicationController before_filter :admin_authorization, only: [:login_stat,:submission_stat] - before_filter { |c| + before_filter(only: [:problem_hof]) { |c| return false unless authenticate - if GraderConfiguration["system.hall_of_fame_available"] + if GraderConfiguration["right.user_view_submission"] return true; end @@ -156,7 +156,7 @@ #process user_id @by_lang.each do |lang,prop| prop.each do |k,v| - v[:user] = User.exists?(v[:user_id]) ? User.find(v[:user_id]).login : "(NULL)" + v[:user] = User.exists?(v[:user_id]) ? User.find(v[:user_id]).full_name : "(NULL)" end end @@ -164,19 +164,19 @@ if @by_lang and @by_lang.first @best = @by_lang.first[1] @by_lang.each do |lang,prop| - if @best[:runtime][:value] > prop[:runtime][:value] + if @best[:runtime][:value] >= prop[:runtime][:value] @best[:runtime] = prop[:runtime] @best[:runtime][:lang] = lang end - if @best[:memory][:value] > prop[:memory][:value] + if @best[:memory][:value] >= prop[:memory][:value] @best[:memory] = prop[:memory] @best[:memory][:lang] = lang end - if @best[:length][:value] > prop[:length][:value] + if @best[:length][:value] >= prop[:length][:value] @best[:length] = prop[:length] @best[:length][:lang] = lang end - if @best[:first][:value] > prop[:first][:value] + if @best[:first][:value] >= prop[:first][:value] @best[:first] = prop[:first] @best[:first][:lang] = lang end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -31,7 +31,7 @@ append_to menu_items, "[#{I18n.t 'menu.test'}]", 'test', 'index' end - if GraderConfiguration['system.hall_of_fame_available'] + if GraderConfiguration['right.user_hall_of_fame'] append_to menu_items, "[#{I18n.t 'menu.hall_of_fame'}]", 'report', 'problem_hof' end append_to menu_items, "[#{I18n.t 'menu.help'}]", 'main', 'help' diff --git a/app/views/graders/submission.html.haml b/app/views/graders/submission.html.haml --- a/app/views/graders/submission.html.haml +++ b/app/views/graders/submission.html.haml @@ -5,7 +5,7 @@ %p User: - = "#{@submission.user.login}" + = "(#{@submission.user.login}) #{@submission.user.full_name}" %br/ Problem: - if @submission.problem!=nil 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 @@ -7,10 +7,8 @@ $('#until_datetime').datetimepicker({ showButtonPanel: true, dateFormat: "yy-mm-dd", controlType: "slider"} ); }); - %h1 Login status - =render partial: 'report_menu' =render partial: 'date_range', locals: {param_text: 'Login date range:', title: 'Query login stat in the range' } diff --git a/app/views/report/problem_hof.html.haml b/app/views/report/problem_hof.html.haml --- a/app/views/report/problem_hof.html.haml +++ b/app/views/report/problem_hof.html.haml @@ -1,65 +1,22 @@ + +/- if params[:id] +/ %h1 Tasks Hall of Fame +/ = link_to('[back to All-Time Hall of Fame]', action: 'problem_hof', id: nil ) +/- else +/ %h1 All-Time Hall of Fame + + %h1 Tasks Hall of Fame - .task-menu Tasks %br/ - @problems.each do |prob| = link_to( "[#{prob.name}]", {id: prob.id}) - - - -%h2 Overall - -- if @best - %b Best Runtime: - = " by #{@best[:runtime][:user]} 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]} 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]} with #{@best[:length][:value]} at submission " - = link_to("#" + @best[:length][:sub_id].to_s, controller: 'graders' , action: 'submission', id: @best[:length][:sub_id]) - %br/ - %b First solver: - = " by #{@best[:first][:user]} is the first solver on #{@best[:first][:value]} at submission " - = link_to("#" + @best[:first][:sub_id].to_s, controller: 'graders' , action: 'submission', id: @best[:first][:sub_id]) - %br/ +- unless params[:id] + /=render partial: 'all_time_hof' + Please select a problem. +- else + =render partial: 'task_hof' - %p - This counts only for submission with 100% score
- Right now, java is excluded from memory usage competition. (Because it always uses 2GB memory...) - - %h2 By language - - %table.info - %thead - %tr.info-head - %th Language - %th Best runtime (ms) - %th Best memory (kbytes) - %th Shortest Code (bytes) - %th First solver - %tbody - - @by_lang.each do |lang,value| - %tr{class: cycle('info-even','info-odd')} - %td= lang - %td - = "#{value[:runtime][:user]} (#{(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][: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][: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 - -- else - %h3 No submissions diff --git a/db/seeds.rb b/db/seeds.rb --- a/db/seeds.rb +++ b/db/seeds.rb @@ -54,12 +54,19 @@ }, { - :key => 'system.hall_of_fame_available', + :key => 'right.user_hall_of_fame', :value_type => 'boolean', :default_value => 'false', :description => 'If true, any user can access hall of fame page.' }, + { + :key => 'right.user_view_submission', + :value_type => 'boolean', + :default_value => 'false', + :description => 'If true, any user can view submissions of every one.' + }, + # If Configuration['system.online_registration'] is true, the # system allows online registration, and will use these # information for sending confirmation emails.