Commit 571380271dedf25106f78aa4d0198704cbc9e2f9

Authored by Parley
1 parent f4b16954
Exists in master and in 79 other branches add_sisp_to_chef, add_super_archives_plugin, api_for_colab, automates_core_packing, backup_not_prod, changes_in_buttons_on_content_panel, colab_automated_login, colab_spb_plugin_recipe, colab_widgets_settings, design_validation, dev_env_minimal, disable_email_dev, fix_breadcrumbs_position, fix_categories_software_link, fix_edit_institution, fix_edit_software_with_another_license, fix_get_license_info, fix_gitlab_assets_permission, fix_list_style_inside_article, fix_list_style_on_folder_elements, fix_members_pagination, fix_merge_request_url, fix_models_translations, fix_no_license, fix_software_api, fix_software_block_migration, fix_software_communities_translations, fix_software_communities_unit_test, fix_style_create_institution_admin_panel, fix_superarchives_imports, fix_sym_links_noosfero, focus_search_field_theme, gov-user-refactoring, gov-user-refactoring-rails4, header_fix, institution_modal_on_rating, kalibro-conf-refactoring, kalibro-processor-package, lxc_settings, margin_fix, mezuro_cookbook, prezento, refactor_download_block, refactor_software_communities, refactor_software_for_sisp, register_page, release-process, release-process-v2, remove-unused-images, remove_broken_theme, remove_secondary_email_from_user, remove_sisp_buttons, removing_super_archives_email, review_message, scope2method, signals_user_noosfero, sisp_catalog_header, sisp_colab_config, sisp_dev, sisp_dev_master, sisp_simple_version, software_as_organization, software_catalog_style_fix, software_communities_html_refactor, software_infos_api, spb_minimal_env, spb_to_rails4, spec_refactor, stable-4.1, stable-4.2, stable-4.x, temp_soft_comm_refactoring, theme_header, theme_javascript_refactory, thread_dropdown, thread_page, update_search_by_categories, update_software_api, update_softwares_boxes

Implement task to create templates of people

Signed-off-by: Parley Martins <parley@outlook.com>
Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com>
Showing 1 changed file with 57 additions and 10 deletions   Show diff stats
lib/tasks/templates.rake
1 1 namespace :templates do
2 2 namespace :create do
3   -
  3 +
4 4 desc "Create new templates of software, intitution, person and community"
5 5 task :all => :environment do
6 6 Rake::Task["templates:create:institution"].invoke
... ... @@ -18,12 +18,53 @@ namespace :templates do
18 18 end
19 19 end
20 20  
21   -
22 21 desc "Create new templates of people"
23 22 task :people => :environment do
24 23 Environment.all.each do |env|
25 24 if env.plugin_enabled?("MpogSoftware") or env.plugin_enabled?("MpogSoftwarePlugin")
  25 + person = Person.where(:identifier => "noosfero_person_template").first
  26 +
  27 + if person.nil?
  28 + password = SecureRandom.hex(6)
  29 + user = User.create!(:name => "People", :login => "people", :email => "person@template.noo", :password => password , :password_confirmation => password, :environment => env)
  30 + person = user.person
  31 + end
  32 +
  33 + person.layout_template = "leftbar"
  34 + person.is_template = true
  35 +
  36 + box1 = person.boxes.where(:position => 1).first
  37 + box1.blocks.destroy_all
  38 + person.save!
26 39 puts "Person successfully created!"
  40 +
  41 + institution_block = InstitutionsBlock.new
  42 + institution_block.position = 4
  43 + institution_block.save!
  44 + box1.blocks << institution_block
  45 + box1.save!
  46 + puts "InstitutionBlock successfully added to person!"
  47 +
  48 + software_block = SoftwaresBlock.new
  49 + software_block.position = 2
  50 + software_block.save!
  51 + box1.blocks << software_block
  52 + box1.save!
  53 + puts "SoftwaresBlock successfully added to person!"
  54 +
  55 + community_block = CommunitiesBlock.new
  56 + community_block.position = 3
  57 + community_block.save!
  58 + box1.blocks << community_block
  59 + box1.save!
  60 + puts "CommunitiesBlock successfully added to person!"
  61 +
  62 + main_block = MainBlock.new
  63 + main_block.position = 1
  64 + main_block.save!
  65 + box1.blocks << main_block
  66 + box1.save!
  67 + puts "MainBlock successfully added to person!"
27 68 end
28 69 end
29 70 end
... ... @@ -42,20 +83,20 @@ namespace :templates do
42 83 task :institution => :environment do
43 84 Environment.all.each do |env|
44 85 if env.plugin_enabled?("MpogSoftware") or env.plugin_enabled?("MpogSoftwarePlugin")
45   - community = Community.create!(:name => "institution", :is_template => true, :moderated_articles => true)
  86 + community = Community.create!(:name => "institution", :is_template => true, :moderated_articles => true, :environment => env)
46 87 community.layout_template = "leftbar"
47   -
  88 +
48 89 box2 = community.boxes.where(:position => 2).first
49 90 box1 = community.boxes.where(:position => 1).first
50 91 box3 = community.boxes.where(:position => 3).first
51   -
  92 +
52 93 box2.blocks.destroy_all
53 94 box1.blocks.destroy_all
54 95 box3.blocks.destroy_all
55 96  
56 97 community.save!
57 98 puts "Institution succesfully created!"
58   -
  99 +
59 100 members_block = MembersBlock.new
60 101 members_block.limit = 16
61 102 members_block.prioritize_profiles_with_image = true
... ... @@ -67,15 +108,14 @@ namespace :templates do
67 108 members_block.save!
68 109 box1.blocks << members_block
69 110 box1.save!
70   - puts "MembersBlock successfully added!"
71   -
72   -
  111 + puts "MembersBlock successfully added to institution!"
  112 +
73 113 main_block = MainBlock.new
74 114 main_block.position = 1
75 115 main_block.save!
76 116 box1.blocks << main_block
77 117 box1.save!
78   - puts "MainBlock successfully added!"
  118 + puts "MainBlock successfully added to institution!"
79 119 end
80 120 end
81 121 end
... ... @@ -88,6 +128,13 @@ namespace :templates do
88 128 if env.plugin_enabled?("MpogSoftware") or env.plugin_enabled?("MpogSoftwarePlugin")
89 129 Community["institution"].destroy
90 130 puts "Institution template destoyed with success!"
  131 +
  132 + user = User["people"]
  133 + if !user.nil?
  134 + user.person.destroy
  135 + user.destroy
  136 + puts "Person template destroyed with success!"
  137 + end
91 138 end
92 139 end
93 140 end
... ...