From eaa8ca0084e1793faacdde0d77ab37280439ed4c Mon Sep 17 00:00:00 2001 From: martyhines Date: Tue, 20 Aug 2013 22:30:08 -0400 Subject: [PATCH] set default crop creator (rake task, deploy script, seeds) --- config/environments/development.rb | 1 + config/environments/production.rb | 1 + config/environments/staging.rb | 1 + config/environments/test.rb | 1 + db/seeds.rb | 20 ++++++++++++++++++-- lib/tasks/growstuff.rake | 15 +++++++++++++-- script/deploy-tasks.sh | 3 +++ 7 files changed, 38 insertions(+), 4 deletions(-) diff --git a/config/environments/development.rb b/config/environments/development.rb index 211170993..8386b8486 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -55,6 +55,7 @@ Growstuff::Application.configure do config.site_name = "Growstuff (dev)" config.analytics_code = '' config.currency = 'AUD' + config.bot_email = "noreply@growstuff.org" end config.after_initialize do diff --git a/config/environments/production.rb b/config/environments/production.rb index 08feba071..06952e9db 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -86,6 +86,7 @@ Growstuff::Application.configure do eos config.currency = 'AUD' + config.bot_email = "noreply@growstuff.org" end config.after_initialize do diff --git a/config/environments/staging.rb b/config/environments/staging.rb index 24f77f035..75cece50d 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -82,6 +82,7 @@ Growstuff::Application.configure do config.site_name = "Growstuff (staging)" config.analytics_code = '' config.currency = 'AUD' + config.bot_email = "noreply@growstuff.org" end config.after_initialize do diff --git a/config/environments/test.rb b/config/environments/test.rb index 6718e2e84..9d6affbe0 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -44,6 +44,7 @@ Growstuff::Application.configure do config.site_name = "Growstuff (test)" config.analytics_code = '' config.currency = 'AUD' + config.bot_email = "noreply@growstuff.org" end config.after_initialize do diff --git a/db/seeds.rb b/db/seeds.rb index 91ba3823a..85ec17c78 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -12,9 +12,10 @@ require 'csv' def load_data # for all Growstuff sites, including production ones - load_crops load_roles load_basic_account_types + create_cropbot + load_crops # for development environments only if Rails.env.development? @@ -34,7 +35,8 @@ def load_crops system_name,scientific_name,en_wikipedia_url = row @crop = Crop.create( :system_name => system_name, - :en_wikipedia_url => en_wikipedia_url + :en_wikipedia_url => en_wikipedia_url, + :creator_id => @cropbot_user.id ) @crop.scientific_names.create( :scientific_name => scientific_name @@ -102,6 +104,20 @@ def load_admin_users @wrangler_user.save! end +def create_cropbot + @cropbot_user = Member.create( + :login_name => "cropbot", + :email => Growstuff::Application.config.bot_email, + :password => SecureRandom.urlsafe_base64(64), + :tos_agreement => true + ) + @cropbot_user.confirm! + @cropbot_user.roles << @wrangler + @cropbot_user.save! + @cropbot_user.account.account_type = AccountType.find_by_name("Staff") + @cropbot_user.account.save +end + def load_paid_account_types puts "Adding 'paid' and 'seed' account types..." @paid_account = AccountType.create!( diff --git a/lib/tasks/growstuff.rake b/lib/tasks/growstuff.rake index 47a2a0416..949337355 100644 --- a/lib/tasks/growstuff.rake +++ b/lib/tasks/growstuff.rake @@ -128,9 +128,20 @@ namespace :growstuff do Crop.find_each do |c| Crop.reset_counters c.id, :plantings end - end - end + desc "August 2013: set default creator on existing crops" + task :set_default_crop_creator => :environment do + cropbot = Member.find_by_login_name("cropbot") + cropbot.account.account_type = AccountType.find_by_name("Staff") # set this just because it's nice + cropbot.account.save + raise "cropbot not found: create cropbot member on site or run rake db:seed" unless cropbot + Crop.find_each do |crop| + crop.creator = cropbot + crop.save + end + + end + end end diff --git a/script/deploy-tasks.sh b/script/deploy-tasks.sh index 41cd8f50c..c7b85de08 100755 --- a/script/deploy-tasks.sh +++ b/script/deploy-tasks.sh @@ -8,3 +8,6 @@ echo "2013-08-18 - reset crop planting counts" rake growstuff:oneoff:reset_crop_plantings_count + +echo "2013-08-21 - set default crop creator" +rake growstuff:oneoff:set_default_crop_creator