Show More
Commit Description:
[web] fix nil problem in various place, some styling...
Commit Description:
[web] fix nil problem in various place, some styling git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@259 6386c4cd-e34a-4fa8-8920-d93eb39b512e
File last commit:
Show/Diff file:
Action:
app/models/configuration.rb | 78 lines | 1.6 KiB | text/x-ruby | RubyLexer |
jittat
[web] added mode + access control, when sites started/finished...
r122 #
# This class also contains various login of the system.
#
jittat
[web] added configurations...
r76 class Configuration < ActiveRecord::Base
jittat
[web] added mode + access control, when sites started/finished...
r122 SYSTEM_MODE_CONF_KEY = 'system.mode'
jittat
[web] added configurations...
r76 @@configurations = nil
def self.get(key)
if @@configurations == nil
self.read_config
end
return @@configurations[key]
end
def self.[](key)
self.get(key)
end
def self.reload
self.read_config
end
def self.clear
@@configurations = nil
end
jittat
[web] added mode + access control, when sites started/finished...
r122 #
# View decision
#
def self.show_submitbox_to?(user)
mode = get(SYSTEM_MODE_CONF_KEY)
return false if mode=='analysis'
if (mode=='contest')
return false if (user.site!=nil) and
jittat
[web] fix nil problem in various place, some styling...
r129 ((user.site.started!=true) or (user.site.finished?))
jittat
[web] added mode + access control, when sites started/finished...
r122 end
return true
end
def self.show_tasks_to?(user)
mode = get(SYSTEM_MODE_CONF_KEY)
if (mode=='contest')
jittat
[web] fix nil problem in various place, some styling...
r129 return false if (user.site!=nil) and (user.site.started!=true)
jittat
[web] added mode + access control, when sites started/finished...
r122 end
return true
end
jittat
[web] test request stops at 30 min before end, auto refresh grader process status...
r128
def self.allow_test_request(user)
mode = get(SYSTEM_MODE_CONF_KEY)
if (mode=='contest')
jittat
[web] fix nil problem in various place, some styling...
r129 return false if (user.site!=nil) and ((user.site.started!=true) or (user.site.time_left < 30.minutes))
jittat
[web] test request stops at 30 min before end, auto refresh grader process status...
r128 end
return false if mode=='analysis'
return true
end
jittat
[web] added mode + access control, when sites started/finished...
r122
jittat
[web] added configurations...
r76 protected
def self.read_config
@@configurations = {}
Configuration.find(:all).each do |conf|
key = conf.key
val = conf.value
case conf.value_type
when 'string'
@@configurations[key] = val
when 'integer'
@@configurations[key] = val.to_i
when 'boolean'
@@configurations[key] = (val=='true')
end
end
end
end