Commit 6129c293c04e8f670161f9223f493ee45bb40b39
1 parent
c8e26bfb
Exists in
master
and in
35 other branches
Added parameters to sisp task
-Added variables DOMAIN and ADMINUSER to sisp:all task for custom configurations Signed-off-by: Tallys Martins <tallysmartins@yahoo.com.br>
Showing
1 changed file
with
57 additions
and
4 deletions
Show diff stats
src/noosfero-spb/software_communities/lib/tasks/import_sisp_software.rake
@@ -3,6 +3,30 @@ | @@ -3,6 +3,30 @@ | ||
3 | namespace :sisp do | 3 | namespace :sisp do |
4 | desc "Creates SISP env, template, and import data" | 4 | desc "Creates SISP env, template, and import data" |
5 | task :all => :environment do | 5 | task :all => :environment do |
6 | + unless ENV["DOMAIN"].present? | ||
7 | + puts "You didn't choose any domain. The default domain is 'novo.sisp.gov.br'" | ||
8 | + puts "You can run rake sisp:all DOMAIN=domain.url" | ||
9 | + puts "Continue and create SISP Environment with default domain? (y/N)" | ||
10 | + response = $stdin.gets.strip | ||
11 | + | ||
12 | + unless ['y', 'yes'].include?(response.downcase) | ||
13 | + puts "*** ABORTED." | ||
14 | + exit 1 | ||
15 | + end | ||
16 | + end | ||
17 | + | ||
18 | + unless ENV["ADMINUSER"].present? | ||
19 | + puts "You didn't enter any user to be selected from the default Environment" | ||
20 | + puts "You can run rake sisp:all ADMINUSER=jose" | ||
21 | + puts "Continue and create SISP Environment without an admin user? (y/N)" | ||
22 | + response = $stdin.gets.strip | ||
23 | + | ||
24 | + unless ['y', 'yes'].include?(response.downcase) | ||
25 | + puts "*** ABORTED." | ||
26 | + exit 1 | ||
27 | + end | ||
28 | + end | ||
29 | + | ||
6 | Rake::Task['sisp:create_env'].invoke | 30 | Rake::Task['sisp:create_env'].invoke |
7 | Rake::Task['noosfero:plugins:enable_all'].invoke | 31 | Rake::Task['noosfero:plugins:enable_all'].invoke |
8 | Rake::Task['sisp:create_template'].invoke | 32 | Rake::Task['sisp:create_template'].invoke |
@@ -12,14 +36,42 @@ namespace :sisp do | @@ -12,14 +36,42 @@ namespace :sisp do | ||
12 | desc "Creates the SISP Environment" | 36 | desc "Creates the SISP Environment" |
13 | task :create_env => :environment do | 37 | task :create_env => :environment do |
14 | env = Environment.find_or_create_by_name("SISP") | 38 | env = Environment.find_or_create_by_name("SISP") |
15 | - domain = Domain.find_or_create_by_name("novo.sisp.gov.br") | 39 | + domain_name = ENV["DOMAIN"] || "novo.sisp.gov.br" |
40 | + domain = Domain.find_or_create_by_name(domain_name) | ||
16 | env.domains << domain unless env.domains.include?(domain) | 41 | env.domains << domain unless env.domains.include?(domain) |
17 | 42 | ||
18 | env.theme = "noosfero-spb-theme" | 43 | env.theme = "noosfero-spb-theme" |
19 | create_link_blocks env | 44 | create_link_blocks env |
20 | env.save | 45 | env.save |
21 | 46 | ||
22 | - puts "SISP Environment created" | 47 | + user = Environment.default.users.find_by_login(ENV["ADMINUSER"]) |
48 | + if user.present? | ||
49 | + password = SecureRandom.base64 | ||
50 | + sisp_user = env.users.find_by_login(user.login) | ||
51 | + | ||
52 | + unless sisp_user.present? | ||
53 | + sisp_user = User.new(:login => user.login, :email => user.email, :password => password, :password_confirmation => password, :environment => env) | ||
54 | + end | ||
55 | + | ||
56 | + sisp_user.save | ||
57 | + sisp_user.activate | ||
58 | + env.add_admin sisp_user.person | ||
59 | + puts "SISP admin user created with success!" | ||
60 | + puts "Type the password for this user" | ||
61 | + $stdin.echo = false | ||
62 | + sisp_user.password = $stdin.gets.strip | ||
63 | + puts "Type the password confirmation" | ||
64 | + sisp_user.password_confirmation = $stdin.gets.strip | ||
65 | + | ||
66 | + puts "Password not changed! Enter rails console and make it manually" unless sisp_user.save | ||
67 | + $stdin.echo = true | ||
68 | + else | ||
69 | + puts "\nWARNING!!!!!!***********************************************" | ||
70 | + puts "No user found with the given login '#{ENV['ADMINUSER']}'.... skipping" | ||
71 | + puts "You can run this task again passing a valid user login with the following command:" | ||
72 | + puts "rake sisp:create_env ADMINUSER=userlogin" | ||
73 | + end | ||
74 | + puts "\n\nSISP Environment created" | ||
23 | end | 75 | end |
24 | 76 | ||
25 | def create_link_blocks template | 77 | def create_link_blocks template |
@@ -189,8 +241,9 @@ def create_identifier name | @@ -189,8 +241,9 @@ def create_identifier name | ||
189 | end | 241 | end |
190 | 242 | ||
191 | def create_sisp_user #TODO change user info | 243 | def create_sisp_user #TODO change user info |
192 | - user = $env.users.find_by_login('sisp-admin') | ||
193 | - user ||= User.new(:login => 'sisp-admin', :email => 'sisp_user@changeme.com', :password => 'sisp1234', :password_confirmation => 'sisp1234', :environment => $env) | 244 | + user = $env.users.find_by_login('sisp_admin') |
245 | + password = SecureRandom.base64 | ||
246 | + user ||= User.new(:login => 'sisp_admin', :email => 'sisp_user@changeme.com', :password => password, :password_confirmation => password, :environment => $env) | ||
194 | user.save! | 247 | user.save! |
195 | user.activate if !user.activated? | 248 | user.activate if !user.activated? |
196 | user | 249 | user |