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 @@ -1,7 +1,7 @@ class ApplicationController < ActionController::Base protect_from_forgery - before_filter :current_user + before_filter :current_user SINGLE_USER_MODE_CONF_KEY = 'system.single_user_mode' MULTIPLE_IP_LOGIN_CONF_KEY = 'right.multiple_ip_login' @@ -20,7 +20,7 @@ def admin_authorization return false unless authenticate - user = User.find(session[:user_id], :include => ['roles']) + user = User.includes(:roles).find(session[:user_id]) unless user.admin? unauthorized_redirect return false @@ -37,6 +37,18 @@ end end + def testcase_authorization + #admin always has privileged + puts "haha" + if @current_user.admin? + return true + end + + puts "hehe" + puts GraderConfiguration["right.view_testcase"] + unauthorized_redirect unless GraderConfiguration["right.view_testcase"] + end + protected def authenticate @@ -101,10 +113,10 @@ return false unless authenticate user = User.find(session[:user_id]) unless user.roles.detect { |role| - role.rights.detect{ |right| - right.controller == self.class.controller_name and - (right.action == 'all' or right.action == action_name) - } + role.rights.detect{ |right| + right.controller == self.class.controller_name and + (right.action == 'all' or right.action == action_name) + } } flash[:notice] = 'You are not authorized to view the page you requested' #request.env['HTTP_REFERER'] ? (redirect_to :back) : (redirect_to :controller => 'login')