From 7729b1630f4a7b69c39ddb56d6a3285453706311 Mon Sep 17 00:00:00 2001 From: Ronaldo Pontes Date: Mon, 19 Aug 2013 19:46:52 -0300 Subject: [PATCH] Organized seeds and added rake config:show and config:put tasks --- .gitignore | 2 + db/seeds.rb | 31 ++++++++++ db/seeds/{my-seeds.rb => add-users.rb} | 9 +-- db/seeds/my-seeds-local.example.rb | 85 ++++++++++++++++++++++++++ lib/tasks/config.rake | 57 +++++++++++++++++ lib/tasks/users.rake | 76 ++++++++++++++++++++++- 6 files changed, 251 insertions(+), 9 deletions(-) mode change 100644 => 100755 db/seeds.rb rename db/seeds/{my-seeds.rb => add-users.rb} (67%) create mode 100755 db/seeds/my-seeds-local.example.rb create mode 100755 lib/tasks/config.rake mode change 100644 => 100755 lib/tasks/users.rake diff --git a/.gitignore b/.gitignore index 2f578de2..db675f4d 100755 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ db/*.sqlite3 log/*.log tmp/**/* config/database.yml +db/seeds/my-seeds-local.rb +db/seeds/my-seeds-heroku.rb db/development_structure.sql # Vim *.swp diff --git a/db/seeds.rb b/db/seeds.rb old mode 100644 new mode 100755 index 2e4d0120..784bfee0 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,5 +1,7 @@ # coding: utf-8 +puts 'Seeding the database...' + [ { pt: 'Arte', en: 'Art' }, { pt: 'Artes plásticas', en: 'Visual Arts' }, @@ -90,3 +92,32 @@ OauthProvider.find_or_create_by_name!( secret: 'your_facebook_app_secret', path: 'facebook' ) + + +puts +puts '=============================================' +puts ' Showing all Authentication Providers' +puts '---------------------------------------------' + +OauthProvider.all.each do |conf| + a = conf.attributes + puts " name #{a['name']}" + puts " key: #{a['key']}" + puts " secret: #{a['secret']}" + puts " path: #{a['path']}" + puts +end + + +puts +puts '=============================================' +puts ' Showing all entries in Configuration Table...' +puts '---------------------------------------------' + +Configuration.all.each do |conf| + a = conf.attributes + puts " #{a['name']}: #{a['value']}" +end + +puts '---------------------------------------------' +puts 'Done!' diff --git a/db/seeds/my-seeds.rb b/db/seeds/add-users.rb similarity index 67% rename from db/seeds/my-seeds.rb rename to db/seeds/add-users.rb index 8a1fa55a..90ddaf09 100755 --- a/db/seeds/my-seeds.rb +++ b/db/seeds/add-users.rb @@ -1,11 +1,4 @@ -## Optional Seed file -## to be used during development - -puts "Adding Uservoice.com settings..." - - Configuration.find_or_create_by_name('uservoice_subdomain').update_attribute('value', 'dummy_domain.uservoice.com') - Configuration.find_or_create_by_name('uservoice_sso_key').update_attribute('value', 'dummy_uservoice_sso_key') - +## Add sample users puts "Adding Admin user..." diff --git a/db/seeds/my-seeds-local.example.rb b/db/seeds/my-seeds-local.example.rb new file mode 100755 index 00000000..773fa845 --- /dev/null +++ b/db/seeds/my-seeds-local.example.rb @@ -0,0 +1,85 @@ +## Update this configuration seed and then run +## rake db:seed:my-seeds + +puts "Adding OauthProvider settings..." + + puts " Facebook..." + + ## catarse-local-dev Facebook App + facebook = OauthProvider.find_or_initialize_by_name 'facebook' + facebook.update_attributes( + key: '556758001037275', + secret: '5b3a847321b426f9dabd011359a21400', + path: 'facebook' + ) + + + #OauthProvider.create :name => 'Twitter', :key => 'myconsumerkey', :secret => 'myconsumersecret', :strategy => 'Twitter', :path => 'twitter' + #OauthProvider.create :name => 'LinkedIn', :key => 'myconsumerkey', :secret => 'myconsumersecret', :strategy => 'LinkedIn', :path => 'linked_in' + +### +## Uservoice.com seetings +## at YOURDOMAIN.uservoice.com/admin/settings#/channels +## Sendgrid Heroku Plugin Settings +puts "Creating Configuration entries..." +{ + + catarse_fee: '0.13', + company_name: 'Catarse', + + host: 'YOUR_HOST', + base_domain: 'YOUR_DOMAIN', + base_url: "YOUR_BASE_URL", + + facebook_url: "http://facebook.com/MY-FACEBOOK-PAGE", + facebook_app_id: '556758001037275', + uservoice_subdomain: 'MY-USER-VOICE.uservoice.com', + uservoice_sso_key: 'MY-USER-VOICE-KEY', + uservoice_secret_gadget: 'MY-USER-VOICE-SECRET', + sendgrid_user_name: 'MY-HEROKU-SENDGRID-APP@heroku.com', + sendgrid: 'MY-HEROKU-SENDGRID-KEY', + mailchimp_url: "YOUR_MAIL_CHIMP_URL", + + blog_url: "YOUR_BLOG_URL", + twitter_username: "YOUR_TWITTER", + email_contact: 'EMAIL_ACCOUNT', + email_payments: 'EMAIL_ACCOUNT', + email_projects: 'EMAIL_ACCOUNT', + email_system: 'EMAIL_ACCOUNT', + email_no_reply: 'EMAIL_ACCOUNT', + support_forum: 'YOUR_SUPPORT_URL', + +}.each do |name, value| + conf = Configuration.find_or_initialize_by_name name + conf.update_attributes({ + value: value + }) +end + +puts +puts '=============================================' +puts ' Showing all Authentication Providers' +puts '---------------------------------------------' + +OauthProvider.all.each do |conf| + a = conf.attributes + puts " name #{a['name']}" + puts " key: #{a['key']}" + puts " secret: #{a['secret']}" + puts " path: #{a['path']}" + puts +end + + +puts +puts '=============================================' +puts ' Showing all entries in Configuration Table...' +puts '---------------------------------------------' + +Configuration.all.each do |conf| + a = conf.attributes + puts " #{a['name']}: #{a['value']}" +end + +puts '---------------------------------------------' +puts 'Done!' diff --git a/lib/tasks/config.rake b/lib/tasks/config.rake new file mode 100755 index 00000000..8496b419 --- /dev/null +++ b/lib/tasks/config.rake @@ -0,0 +1,57 @@ +#### +# Task to manage the application configuration table +## +namespace :config do + ### + # Shows all entries in the configuration table + # usage: rake config:show + ## + desc "Shows all entries in the configuration table\n usage: rake config:show" + task :show => :environment do + + puts + puts '=============================================' + puts ' Showing all Authentication Providers' + puts '---------------------------------------------' + + OauthProvider.all.each do |conf| + a = conf.attributes + puts " name #{a['name']}" + puts " key: #{a['key']}" + puts " secret: #{a['secret']}" + puts " path: #{a['path']}" + puts + end + + + puts + puts '=============================================' + puts ' Showing all entries in Configuration Table...' + puts '---------------------------------------------' + + Configuration.all.each do |conf| + a = conf.attributes + puts " #{a['name']}: #{a['value']}" + end + + puts '---------------------------------------------' + puts 'Done!' + end + + ### + # Adds an entry to the configuration table + # usage: rake config:put[config_name,config_value] + ## + desc "Adds an entry to the configuration table\n usage: rake config:put" + task :put, [:name, :value] => :environment do |t, args| + puts + puts "Adding #{args[:name]}=#{args[:value]} to configuration table..." + conf = Configuration.find_or_initialize_by_name args[:name] + conf.update_attributes( + value: args[:value], + ) + puts 'Done!' + puts + end + +end diff --git a/lib/tasks/users.rake b/lib/tasks/users.rake old mode 100644 new mode 100755 index 68d01126..0594c49d --- a/lib/tasks/users.rake +++ b/lib/tasks/users.rake @@ -1,4 +1,12 @@ -namespace :user do +#### +# Task to manage the application users +## +namespace :users do + + ### + # Syncs users with newsletter + # usage: rake users:sync_with_mailee + ## desc 'This task will sync the users with newsletter = true with Mailee.' task :sync_with_mailee => :environment do print "Synchronizing contacts..." @@ -7,4 +15,70 @@ namespace :user do end puts "OK!" end + + + ### + # Shows all entries in the configuration table + # usage: rake users:show + ## + desc "Shows all entries in the configuration table" + task :show => :environment do + + puts + puts '=============================================' + puts ' Application Users' + puts '---------------------------------------------' + + User.all.each do |conf| + a = conf.attributes + print "\nname: #{a['name']}" + print "\n nickname: #{a['nickname']}" + print "\n email: #{a['email']}" + print "\n admin: #{a['admin']}" + puts + end + + puts '---------------------------------------------' + puts 'Done!' + end + + ### + # Sets user as administrator + # usage: rake users:admin[email] + ## + desc "Sets user as administrator" + task :admin, [:email] => :environment do |t, args| + puts + puts "Setting #{args[:email]} as administrator..." + u = User.find_by_email(args[:email]) + unless u + puts "ERROR: User doesn't exist!" + next + end + + u.update_attribute :admin, true + puts "#{u.name}: #{u.email} is now an administrator!" + puts 'Done!' + puts + end + + + ### + # Sets first user as administrator + # usage: rake users:adminfirst + ## + desc "Sets first user as administrator" + task :adminfirst => :environment do + puts + unless User.count > 0 + puts "ERROR: User doesn't exist!" + next + end + + u = User.first + u.update_attribute :admin, true + puts "#{u.name}: #{u.email} is now an administrator!" + puts 'Done!' + puts + end end