anhetegua 4.36 KB
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/environment'

Environment.default.categories.destroy_all
User.destroy_all
Profile.destroy_all
Role.destroy_all
RoleAssignment.destroy_all
Category.destroy_all

def new_category(parent, name, color = nil)
  category = Environment.default.categories.build(:name => name, :display_color => color, :parent_id => (parent ? parent.id: nil))
  category.save!
  category
end

def new_region(parent, name, color = nil)
  region = Environment.default.regions.build(:name => name, :display_color => color, :parent_id => (parent ? parent.id: nil))
  region.save!
  region
end

def new_validator(region, name, identifier)
  org = Organization.new(:name => name, :identifier => identifier)
  org.validation_info = ValidationInfo.new(:validation_methodology => 'some methodology we don\'t care about')
  org.save!
  region.validators << org
  region.save!
  org
end

def new_member(org, person)
  org.affiliate()
end

tematicas = new_category(nil, 'Temáticas', 1)
new_category(tematicas, 'Finanças Solidárias')
new_category(tematicas, 'Marco Legal')
new_category(tematicas, 'Software Livre')

territorios = new_region(nil, 'Territórios', 2)
ba = new_region(territorios, 'Bahia')
df = new_region(territorios, 'Distrito Federal')
rs = new_region(territorios, 'Rio Grande do Sul')

cadeias = new_category(nil, 'Cadeias', 3)
new_category(cadeias, 'Algodão')
new_category(cadeias, 'Tecnologia de Informação')

# validators
colivre = new_validator(ba, "Colivre", 'colivre')
forum_bahia = new_validator(ba, "Forum Baiano de Economia Solidaraia", 'ecosolbahia')

caritas = new_validator(df, 'Caritas', 'caritas')
fbes = new_validator(df, 'Forum Brasileiro de Economia Solidaria', 'fbes')

asl = new_validator(rs, 'Associacao Software Livre.Org', 'asl')
forum_rs = new_validator(rs, 'Forum Gaucho de Economia Solidaria', 'ecosolrs')

# Role for own things
owner_role = Role.create!(:name => 'owner', :permissions => ['edit_profile', 'destroy_profile', 'manage_memberships', 'post_content', 'edit_profile_design'])

# root user of the system, admin_role for him, the assignment of the role for him and the ownership of the system homepage
root = User.create!(:login => 'root', :email => 'root@noosfero.org', :password => 'root', :password_confirmation => 'root').person
admin_role = Role.create!(:name => 'admin', :permissions => ['view_environment_admin_panel','edit_environment_features', 'edit_environment_design', 'manage_environment_categories', 'manage_environment_roles', 'manage_environment_validators'])

RoleAssignment.create!(:accessor => root, :role => admin_role, :resource => Environment.default)

# Sample user and sample enterprise owned by him
ze = User.create!(:login => 'ze', :email => 'ze@localhost.localdomain', :password => 'test', :password_confirmation => 'test').person
empa = Enterprise.create!(:name => 'Empreendimento A', :identifier => 'empreendimento_a')

empa.affiliate(ze, owner_role)
colivre.affiliate(ze, owner_role)


produtos = ProductCategory.create!(:name => 'Produtos', :environment => Environment.default, :display_color => 4)

alimentacao = ProductCategory.new(:name => 'Alimentação', :environment => Environment.default, :parent => produtos); alimentacao.save!

vegetais = ProductCategory.new(:name => 'Vegetais', :environment => Environment.default, :parent => alimentacao); vegetais.save!

feijao = ProductCategory.new(:name => 'Feijão', :environment => Environment.default, :parent => vegetais); feijao.save!

arroz = ProductCategory.new(:name => 'Arroz', :environment => Environment.default, :parent => vegetais); arroz.save!

batata = ProductCategory.new(:name => 'Batata', :environment => Environment.default, :parent => vegetais); batata.save!

carnes = ProductCategory.new(:name => 'Carnes', :environment => Environment.default, :parent => alimentacao); carnes.save!

boi = ProductCategory.new(:name => 'Boi', :environment => Environment.default, :parent => carnes); boi.save!

frango = ProductCategory.new(:name => 'Frango', :environment => Environment.default, :parent => carnes)

vestuario = ProductCategory.new(:name => 'Vestuário', :environment => Environment.default, :parent => produtos); vestuario.save!

camisetas = ProductCategory.new(:name => 'Camisetas', :environment => Environment.default, :parent => vestuario); camisetas.save!

calcas = ProductCategory.new(:name => 'Calças', :environment => Environment.default, :parent => vestuario); calcas.save!