Commit 571380271dedf25106f78aa4d0198704cbc9e2f9
1 parent
f4b16954
Exists in
master
and in
5 other branches
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 | ... | ... |