# HG changeset patch # User Jittat Fakcharoenphol # Date 2010-05-10 16:47:12 # Node ID c400f7405eeec6cb74b9d3d6583962e1886709d6 # Parent 2cdefa1ab6f28c949b8e13a32abb0daf99f101a3 added default contest diff --git a/app/controllers/user_admin_controller.rb b/app/controllers/user_admin_controller.rb --- a/app/controllers/user_admin_controller.rb +++ b/app/controllers/user_admin_controller.rb @@ -54,7 +54,7 @@ redirect_to :action => 'list' else render :action => 'new' - end + end end def create_from_list diff --git a/app/models/user.rb b/app/models/user.rb --- a/app/models/user.rb +++ b/app/models/user.rb @@ -53,6 +53,7 @@ before_save :encrypt_new_password before_save :assign_default_site + before_save :assign_default_contest # this is for will_paginate cattr_reader :per_page @@ -273,6 +274,19 @@ end end + def assign_default_contest + # have to catch error when migrating (because self.site is not available). + begin + if self.contests.length == 0 + default_contest = Contest.find_by_name(Configuration['contest.default_contest_name']) + if default_contest + self.contests = [default_contest] + end + end + rescue + end + end + def password_required? self.hashed_password.blank? || !self.password.blank? end diff --git a/db/seeds.rb b/db/seeds.rb --- a/db/seeds.rb +++ b/db/seeds.rb @@ -107,7 +107,15 @@ :key => 'contest.confirm_indv_contest_start', :value_type => 'boolean', :default_value => 'false' + }, + + { + :key => 'contest.default_contest_name', + :value_type => 'string', + :default_value => 'none', + :description => "New user will be assigned to this contest automatically, if it exists. Set to 'none' if there is no default contest." } + ]