set default crop creator (rake task, deploy script, seeds)

This commit is contained in:
martyhines
2013-08-20 22:30:08 -04:00
parent 098595721b
commit eaa8ca0084
7 changed files with 38 additions and 4 deletions

View File

@@ -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

View File

@@ -86,6 +86,7 @@ Growstuff::Application.configure do
<noscript><p><img alt="Clicky" width="1" height="1" src="//in.getclicky.com/100594260ns.gif" /></p></noscript>
eos
config.currency = 'AUD'
config.bot_email = "noreply@growstuff.org"
end
config.after_initialize do

View File

@@ -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

View File

@@ -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

View File

@@ -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!(

View File

@@ -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

View File

@@ -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