Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'krick/master' into integration

  • Loading branch information...
commit e277e3206e9693a3ff30f25c83841167c20c7d43 2 parents 1ec55ea + e470fa5
@bborn bborn authored
Showing with 72 additions and 11 deletions.
  1. +55 −0 db/sample/users.rb
  2. +17 −11 tasks/community_engine_tasks.rake
View
55 db/sample/users.rb
@@ -0,0 +1,55 @@
+# see last line where we create an admin if there is none, asking for email and password
+
+def prompt_for_admin_password
+ password = ask('Password [communityengine]: ', String) do |q|
+ q.echo = false
+ q.validate = /^(|.{5,40})$/
+ q.responses[:not_valid] = "Invalid password. Must be at least 5 characters long."
+ q.whitespace = :strip
+ end
+ password = "communityengine" if password.blank?
+ password
+end
+
+def prompt_for_admin_login
+ login = ask('Login [admin]: ', String) do |q|
+ q.echo = true
+ q.whitespace = :strip
+ end
+ login = "admin" if login.blank?
+ login
+end
+
+def create_admin_user
+ if ENV['AUTO_ACCEPT']
+ password = "communityengine"
+ login = "admin"
+ else
+ require 'highline/import'
+ puts "Create the admin user (press enter for defaults)."
+ login = prompt_for_admin_login
+ password = prompt_for_admin_password
+ end
+ attributes = {
+ :password => password,
+ :password_confirmation => password,
+ :email => 'admin@example.com',
+ :login => login,
+ :birthday => 30.years.ago
+ }
+
+
+ if User.find_by_login(login)
+ puts "\nWARNING: There is already a user with the login: #{login}, so no account changes were made. If you wish to create an additional admin user, please run 'rake community_engine:create_admin' again with a different login.\n\n"
+ else
+ admin = User.create(attributes)
+ # create an admin role and and assign the admin user to that role
+ admin.role = Role[:admin]
+ admin.activate
+ puts "\nINFO: User with admin priviliges was created.\n" if admin.save!
+ end
+end
+
+load File.join(RAILS_ROOT, 'vendor', 'plugins', 'community_engine', 'app', 'models', 'user.rb')
+
+create_admin_user
View
28 tasks/community_engine_tasks.rake
@@ -21,6 +21,12 @@ namespace :community_engine do
#nothing
end
+ desc "Create user with admin role."
+ task :create_admin do
+ Rake::Task['environment'].invoke
+ require File.join(RAILS_ROOT, 'vendor', 'plugins', 'community_engine', 'db', 'sample', 'users.rb')
+ end
+
desc 'Assign admin role to user. Usage: rake community_engine:make_admin email=admin@foo.com'
task :make_admin => :environment do
email = ENV["email"]
@@ -33,7 +39,7 @@ namespace :community_engine do
puts "There is no user with the e-mail '#{email}'."
end
end
-
+
desc 'Test the community_engine plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
@@ -63,13 +69,13 @@ namespace :community_engine do
reg_exp = []
for show_type in show_only
reg_exp << case show_type
- when 'm', 'models' : 'app\/models'
- when 'c', 'controllers' : 'app\/controllers'
- when 'h', 'helpers' : 'app\/helpers'
- when 'l', 'lib' : 'lib'
- else
- show_type
- end
+ when 'm', 'models' : 'app\/models'
+ when 'c', 'controllers' : 'app\/controllers'
+ when 'h', 'helpers' : 'app\/helpers'
+ when 'l', 'lib' : 'lib'
+ else
+ show_type
+ end
end
reg_exp.map!{ |m| "(#{m})" }
params << " --exclude \"^(?!#{reg_exp.join('|')})\""
@@ -110,12 +116,12 @@ namespace :community_engine do
namespace :db do
namespace :migrate do
-
+
desc 'For CE coming from version < 1.0.1 that stored plugin migration info in the normal Rails schema_migrations table. Move that info back into the plugin_schema_migrations table.'
task :upgrade_desert_plugin_migrations => :environment do
plugin_migration_table = Desert::PluginMigrations::Migrator.schema_migrations_table_name
schema_migration_table = ActiveRecord::Migrator.schema_migrations_table_name
-
+
unless ActiveRecord::Base.connection.table_exists?(plugin_migration_table)
ActiveRecord::Migration.create_table(plugin_migration_table, :id => false) do |schema_migrations_table|
schema_migrations_table.column :version, :string, :null => false
@@ -156,4 +162,4 @@ namespace :community_engine do
end
end
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.