Commit 418b9fca1d96f431344e3769b7be0ae41d95dd73
Exists in
master
and in
3 other branches
Merge branch 'sisp_improvements' into 'master'
Sisp improvements Foram adicionados parametros à task de importaçao do sisp para que esta receba o Dominio do novo ambiente e um usuário admin a ser "herdado" do SPB, exemplo: rake sisp:all DOMAIN=dev.sisp.gov.br ADMINUSER=tallysmartins Adicionada uma pequena melhoria na busca do catálogo de software. See merge request !140
Showing
4 changed files
with
77 additions
and
8 deletions
Show diff stats
src/noosfero-spb/software_communities/lib/ext/search_controller.rb
| ... | ... | @@ -89,10 +89,11 @@ class SearchController |
| 89 | 89 | params[:query] ||= "" |
| 90 | 90 | visible_communities = visible_profiles(Community) |
| 91 | 91 | |
| 92 | - filtered_software_list = SoftwareInfo.search_by_query(params[:query]) | |
| 92 | + filtered_software_list = SoftwareInfo.search_by_query(params[:query], environment) | |
| 93 | 93 | |
| 94 | 94 | if params[:only_softwares] |
| 95 | 95 | params[:only_softwares].collect!{ |software_name| software_name.to_slug } |
| 96 | + #FIX-ME: This query is not appropriate | |
| 96 | 97 | filtered_software_list = SoftwareInfo.all.select{ |s| params[:only_softwares].include?(s.identifier) } |
| 97 | 98 | @public_software_selected = false |
| 98 | 99 | end | ... | ... |
src/noosfero-spb/software_communities/lib/software_info.rb
| ... | ... | @@ -13,15 +13,15 @@ class SoftwareInfo < ActiveRecord::Base |
| 13 | 13 | DatabaseDescription |
| 14 | 14 | ] |
| 15 | 15 | |
| 16 | - scope :search_by_query, lambda { |query = ""| | |
| 16 | + scope :search_by_query, lambda { |query = "", env = Environment.default| | |
| 17 | 17 | filtered_query = query.gsub(/[\|\(\)\\\/\s\[\]'"*%&!:]/,' ').split.map{|w| w += ":*"}.join('|') |
| 18 | 18 | search_fields = SoftwareInfo.pg_search_plugin_fields |
| 19 | 19 | |
| 20 | 20 | if query.empty? |
| 21 | - SoftwareInfo.joins(:community).where("profiles.visible = ?", true) | |
| 21 | + SoftwareInfo.joins(:community).where("profiles.visible = ? AND environment_id = ? ", true, env.id) | |
| 22 | 22 | else |
| 23 | 23 | searchable_software_objects = SoftwareInfo.transform_list_in_methods_list(SEARCHABLE_SOFTWARE_CLASSES) |
| 24 | - includes(searchable_software_objects).where("to_tsvector('simple', #{search_fields}) @@ to_tsquery('#{filtered_query}')").where("profiles.visible = ?", true) | |
| 24 | + includes(searchable_software_objects).where("to_tsvector('simple', #{search_fields}) @@ to_tsquery('#{filtered_query}')").where("profiles.visible = ? AND environment_id = ?", true, env.id) | |
| 25 | 25 | end |
| 26 | 26 | } |
| 27 | 27 | ... | ... |
src/noosfero-spb/software_communities/lib/tasks/import_sisp_software.rake
| ... | ... | @@ -3,6 +3,30 @@ |
| 3 | 3 | namespace :sisp do |
| 4 | 4 | desc "Creates SISP env, template, and import data" |
| 5 | 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 | 30 | Rake::Task['sisp:create_env'].invoke |
| 7 | 31 | Rake::Task['noosfero:plugins:enable_all'].invoke |
| 8 | 32 | Rake::Task['sisp:create_template'].invoke |
| ... | ... | @@ -12,14 +36,42 @@ namespace :sisp do |
| 12 | 36 | desc "Creates the SISP Environment" |
| 13 | 37 | task :create_env => :environment do |
| 14 | 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 | 41 | env.domains << domain unless env.domains.include?(domain) |
| 17 | 42 | |
| 18 | 43 | env.theme = "noosfero-spb-theme" |
| 19 | 44 | create_link_blocks env |
| 20 | 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 | 75 | end |
| 24 | 76 | |
| 25 | 77 | def create_link_blocks template |
| ... | ... | @@ -189,8 +241,9 @@ def create_identifier name |
| 189 | 241 | end |
| 190 | 242 | |
| 191 | 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 | 247 | user.save! |
| 195 | 248 | user.activate if !user.activated? |
| 196 | 249 | user | ... | ... |
src/noosfero-spb/software_communities/test/unit/software_info_test.rb
| ... | ... | @@ -41,4 +41,19 @@ class SoftwareInfoValidationTest < ActiveSupport::TestCase |
| 41 | 41 | assert_equal @software_info.license_info.link, another_license_link |
| 42 | 42 | end |
| 43 | 43 | |
| 44 | + should "search softwares on the correct environment when multi environments available" do | |
| 45 | + software_info = create_software_info("soft1") | |
| 46 | + another_software_info = create_software_info("soft2") | |
| 47 | + other_env = Environment.create!(name: "sisp") | |
| 48 | + another_soft_profile = another_software_info.community | |
| 49 | + another_soft_profile.environment_id = other_env.id | |
| 50 | + another_soft_profile.save | |
| 51 | + | |
| 52 | + assert_equal 2, SoftwareInfo.count | |
| 53 | + assert_equal 1, SoftwareInfo.search_by_query("", Environment.default).count | |
| 54 | + assert_equal software_info, SoftwareInfo.search_by_query("", Environment.default).first | |
| 55 | + assert_equal 1, SoftwareInfo.search_by_query("", other_env).count | |
| 56 | + assert_equal true, SoftwareInfo.search_by_query("", other_env).includes?(another_software_info) | |
| 57 | + end | |
| 58 | + | |
| 44 | 59 | end | ... | ... |