Show More
Commit Description:
[web] added mode + access control, when sites started/finished...
Commit Description:
[web] added mode + access control, when sites started/finished git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@250 6386c4cd-e34a-4fa8-8920-d93eb39b512e
File last commit:
Show/Diff file:
Action:
app/models/configuration.rb | 70 lines | 1.3 KiB | text/x-ruby | RubyLexer |
#
# This class also contains various login of the system.
#
class Configuration < ActiveRecord::Base
SYSTEM_MODE_CONF_KEY = 'system.mode'
@@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
#
# 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
((user.site.started==false) or (user.site.finished?))
end
return true
end
def self.show_tasks_to?(user)
mode = get(SYSTEM_MODE_CONF_KEY)
if (mode=='contest')
return false if (user.site!=nil) and (user.site.started==false)
end
return true
end
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