Merge branch 'master' into polls

This commit is contained in:
Juanjo Bazán
2017-01-19 16:51:19 +01:00
254 changed files with 10658 additions and 871 deletions

View File

@@ -26,8 +26,9 @@ Setting.create(key: 'org_name', value: 'Consul')
Setting.create(key: 'place_name', value: 'City')
Setting.create(key: 'feature.debates', value: "true")
Setting.create(key: 'feature.polls', value: "true")
Setting.create(key: 'feature.spending_proposals', value: "true")
Setting.create(key: 'feature.spending_proposal_features.voting_allowed', value: "true")
Setting.create(key: 'feature.spending_proposals', value: nil)
Setting.create(key: 'feature.spending_proposal_features.voting_allowed', value: nil)
Setting.create(key: 'feature.budgets', value: "true")
Setting.create(key: 'feature.twitter_login', value: "true")
Setting.create(key: 'feature.facebook_login', value: "true")
Setting.create(key: 'feature.google_login', value: "true")
@@ -39,6 +40,7 @@ Setting.create(key: 'mailer_from_address', value: 'noreply@consul.dev')
Setting.create(key: 'meta_description', value: 'Citizen Participation and Open Government Application')
Setting.create(key: 'meta_keywords', value: 'citizen participation, open government')
Setting.create(key: 'verification_offices_url', value: 'http://oficinas-atencion-ciudadano.url/')
Setting.create(key: 'min_age_to_participate', value: '16')
puts "Creating Geozones"
@@ -55,10 +57,14 @@ end
admin = create_user('admin@consul.dev', 'admin')
admin.create_administrator
admin.update(residence_verified_at: Time.current, confirmed_phone: Faker::PhoneNumber.phone_number, document_type: "1", verified_at: Time.current, document_number: "1111111111")
moderator = create_user('mod@consul.dev', 'mod')
moderator.create_moderator
manager = create_user('manager@consul.dev', 'manager')
manager.create_manager
valuator = create_user('valuator@consul.dev', 'valuator')
valuator.create_valuator
@@ -348,6 +354,73 @@ puts "Creating Valuation Assignments"
SpendingProposal.reorder("RANDOM()").first.valuators << valuator.valuator
end
puts "Creating Budgets"
Budget::PHASES.each_with_index do |phase, i|
descriptions = Hash[Budget::PHASES.map{ |p| ["description_#{p}",
"<p>#{Faker::Lorem.paragraphs(2).join('</p><p>')}</p>"] }]
budget = Budget.create!(
descriptions.merge(
name: (Date.current - 10 + i).to_s,
currency_symbol: "",
phase: phase
)
)
puts budget.name
(1..([1, 2, 3].sample)).each do
group = budget.groups.create!(name: Faker::StarWars.planet)
geozones = Geozone.reorder("RANDOM()").limit([2, 5, 6, 7].sample)
geozones.each do |geozone|
group.headings << group.headings.create!(name: geozone.name,
#geozone: geozone,
price: rand(1 .. 100) * 100000)
end
print "#{group.name} "
end
puts ""
end
puts "Creating Investments"
tags = Faker::Lorem.words(10)
(1..100).each do |i|
heading = Budget::Heading.reorder("RANDOM()").first
investment = Budget::Investment.create!(
author: User.reorder("RANDOM()").first,
heading: heading,
group: heading.group,
budget: heading.group.budget,
title: Faker::Lorem.sentence(3).truncate(60),
external_url: Faker::Internet.url,
description: "<p>#{Faker::Lorem.paragraphs.join('</p><p>')}</p>",
created_at: rand((Time.now - 1.week) .. Time.now),
feasibility: %w{undecided unfeasible feasible feasible feasible feasible}.sample,
unfeasibility_explanation: Faker::Lorem.paragraph,
valuation_finished: [false, true].sample,
tag_list: tags.sample(3).join(','),
price: rand(1 .. 100) * 100000,
terms_of_service: "1")
puts " #{investment.title}"
end
puts "Selecting Investments"
Budget.balloting.reorder("RANDOM()").limit(3).each do |budget|
budget.investments.feasible.reorder("RANDOM()").limit(10).update_all(selected: true)
end
puts "Creating Valuation Assignments"
(1..17).to_a.sample.times do
Budget::Investment.reorder("RANDOM()").first.valuators << valuator.valuator
end
puts "Creating Legislation"
Legislation.create!(title: 'Participatory Democracy', body: 'In order to achieve...')

View File

@@ -0,0 +1,15 @@
class CreateBudgets < ActiveRecord::Migration
def change
create_table :budgets do |t|
t.string "name", limit: 30
t.text "description"
t.string "currency_symbol", limit: 10
t.string "phase", default: "on_hold", limit: 15
t.boolean "valuating", default: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
end
end

View File

@@ -0,0 +1,38 @@
class CreateBudgetInvestments < ActiveRecord::Migration
def change
create_table :budget_investments do |t|
t.references "geozone"
t.integer "author_id", index: true
t.integer "administrator_id", index: true
t.string "title"
t.text "description"
t.string "external_url"
t.integer "price", limit: 8
t.string "feasibility", default: "undecided", limit: 15
t.text "price_explanation"
t.text "unfeasibility_explanation"
t.text "internal_comments"
t.boolean "valuation_finished", default: false
t.integer "valuation_assignments_count", default: 0
t.integer "price_first_year", limit: 8
t.string "duration"
t.datetime "hidden_at"
t.integer "cached_votes_up", default: 0
t.integer "comments_count", default: 0
t.integer "confidence_score", default: 0, null: false
t.integer "physical_votes", default: 0
t.tsvector "tsv"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index :budget_investments, :tsv, using: "gin"
end
end

View File

@@ -0,0 +1,12 @@
class CreateBudgetBallots < ActiveRecord::Migration
def change
create_table :budget_ballots do |t|
t.references :geozone
t.references :user
t.references :budget
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
end
end

View File

@@ -0,0 +1,11 @@
class CreateBudgetBallotLines < ActiveRecord::Migration
def change
create_table :budget_ballot_lines do |t|
t.integer :ballot_id, index: true
t.integer :investment_id, index: true
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
end
end

View File

@@ -0,0 +1,10 @@
class CreateBudgetHeading < ActiveRecord::Migration
def change
create_table :budget_headings do |t|
t.references :group, index: true
t.references :geozone
t.string :name, limit: 50
t.integer :price, limit: 8
end
end
end

View File

@@ -0,0 +1,9 @@
class ReplaceGeozonesByHeadingsInBudgets < ActiveRecord::Migration
def change
remove_column :budget_investments, :geozone_id
remove_column :budget_ballots, :geozone_id
add_reference :budget_investments, :heading, index: true
add_reference :budget_ballots, :heading, index: true
end
end

View File

@@ -0,0 +1,5 @@
class AddBudgetIdToInvestments < ActiveRecord::Migration
def change
add_reference :budget_investments, :budget, index: true
end
end

View File

@@ -0,0 +1,9 @@
class CreateBudgetValuatorAssignments < ActiveRecord::Migration
def change
create_table :budget_valuator_assignments, index: false do |t|
t.belongs_to :valuator
t.integer :investment_id, index: true
t.timestamps null: false
end
end
end

View File

@@ -0,0 +1,5 @@
class DeletesHeadingIdFromBallot < ActiveRecord::Migration
def change
remove_column :budget_ballots, :heading_id
end
end

View File

@@ -0,0 +1,5 @@
class AddBudgetInvestmentsCountToValuators < ActiveRecord::Migration
def change
add_column :valuators, :budget_investments_count, :integer, default: 0
end
end

View File

@@ -0,0 +1,5 @@
class RenameBiValuationCount < ActiveRecord::Migration
def change
rename_column :budget_investments, :valuation_assignments_count, :valuator_assignments_count
end
end

View File

@@ -0,0 +1,5 @@
class AddResponsibleNameToBudgetInvestments < ActiveRecord::Migration
def change
add_column :budget_investments, :responsible_name, :string
end
end

View File

@@ -0,0 +1,6 @@
class AddHeadingIdToBudgetBallot < ActiveRecord::Migration
def change
add_column :budget_ballots, :heading_id, :integer
add_index :budget_ballots, :heading_id
end
end

View File

@@ -0,0 +1,5 @@
class AddPriceToBudget < ActiveRecord::Migration
def change
add_column :budgets, :price, :integer
end
end

View File

@@ -0,0 +1,5 @@
class AddBudgetInvestmentsCountToTags < ActiveRecord::Migration
def change
add_column :tags, "budget/investments_count", :integer, default: 0
end
end

View File

@@ -0,0 +1,10 @@
class CreateBudgetGroup < ActiveRecord::Migration
def change
create_table :budget_groups do |t|
t.references :budget
t.string :name, limit: 50
end
add_index :budget_groups, :budget_id
end
end

View File

@@ -0,0 +1,5 @@
class RemovePriceFromBudget < ActiveRecord::Migration
def change
remove_column :budgets, :price, :integer
end
end

View File

@@ -0,0 +1,5 @@
class RemoveBudgetIdFromInvestments < ActiveRecord::Migration
def change
remove_column :budget_investments, :budget_id, :integer
end
end

View File

@@ -0,0 +1,7 @@
class DesnormalizeBallotLine < ActiveRecord::Migration
def change
add_column :budget_ballot_lines, :budget_id, :integer, index: true
add_column :budget_ballot_lines, :group_id, :integer, index: true
add_column :budget_ballot_lines, :heading_id, :integer, index: true
end
end

View File

@@ -0,0 +1,5 @@
class RemoveHeadingIdFromBallot < ActiveRecord::Migration
def change
remove_column :budget_ballots, :heading_id, :integer
end
end

View File

@@ -0,0 +1,6 @@
class DenormalizeInvestments < ActiveRecord::Migration
def change
add_column :budget_investments, :budget_id, :integer, index: true
add_column :budget_investments, :group_id, :integer, index: true
end
end

View File

@@ -0,0 +1,5 @@
class AddSelectedToBudgetInvestment < ActiveRecord::Migration
def change
add_column :budget_investments, :selected, :bool, default: false, index: true
end
end

View File

@@ -0,0 +1,5 @@
class AddLocationToBudgetInvestments < ActiveRecord::Migration
def change
add_column :budget_investments, :location, :string
end
end

View File

@@ -0,0 +1,5 @@
class RemoveValuatingFromBudgets < ActiveRecord::Migration
def change
remove_column :budgets, :valuating, :bool
end
end

View File

@@ -0,0 +1,12 @@
class ChangeBudgetDescription < ActiveRecord::Migration
def change
remove_column :budgets, :description, :text
add_column :budgets, :description_accepting, :text
add_column :budgets, :description_reviewing, :text
add_column :budgets, :description_selecting, :text
add_column :budgets, :description_valuating, :text
add_column :budgets, :description_balloting, :text
add_column :budgets, :description_reviewing_ballots, :text
add_column :budgets, :description_finished, :text
end
end

View File

@@ -0,0 +1,5 @@
class AdjustBudgetFields < ActiveRecord::Migration
def change
change_column :budgets, :phase, :string, limit: 40, default: 'accepting'
end
end

View File

@@ -0,0 +1,5 @@
class RemoveGeozoneIdFromBudgetHeadings < ActiveRecord::Migration
def change
remove_column :budget_headings, :geozone_id
end
end

View File

@@ -0,0 +1,5 @@
class AddOrganizationNameFieldToBudgetInvestment < ActiveRecord::Migration
def change
add_column :budget_investments, :organization_name, :string
end
end

View File

@@ -0,0 +1,5 @@
class AddUnfeasibleEmailSentAtToBudgetInvestments < ActiveRecord::Migration
def change
add_column :budget_investments, :unfeasible_email_sent_at, :datetime
end
end

View File

@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170103191711) do
ActiveRecord::Schema.define(version: 20170114154421) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -78,6 +78,103 @@ ActiveRecord::Schema.define(version: 20170103191711) do
add_index "banners", ["hidden_at"], name: "index_banners_on_hidden_at", using: :btree
create_table "budget_ballot_lines", force: :cascade do |t|
t.integer "ballot_id"
t.integer "investment_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "budget_id"
t.integer "group_id"
t.integer "heading_id"
end
add_index "budget_ballot_lines", ["ballot_id"], name: "index_budget_ballot_lines_on_ballot_id", using: :btree
add_index "budget_ballot_lines", ["investment_id"], name: "index_budget_ballot_lines_on_investment_id", using: :btree
create_table "budget_ballots", force: :cascade do |t|
t.integer "user_id"
t.integer "budget_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "budget_groups", force: :cascade do |t|
t.integer "budget_id"
t.string "name", limit: 50
end
add_index "budget_groups", ["budget_id"], name: "index_budget_groups_on_budget_id", using: :btree
create_table "budget_headings", force: :cascade do |t|
t.integer "group_id"
t.string "name", limit: 50
t.integer "price", limit: 8
end
add_index "budget_headings", ["group_id"], name: "index_budget_headings_on_group_id", using: :btree
create_table "budget_investments", force: :cascade do |t|
t.integer "author_id"
t.integer "administrator_id"
t.string "title"
t.text "description"
t.string "external_url"
t.integer "price", limit: 8
t.string "feasibility", limit: 15, default: "undecided"
t.text "price_explanation"
t.text "unfeasibility_explanation"
t.text "internal_comments"
t.boolean "valuation_finished", default: false
t.integer "valuator_assignments_count", default: 0
t.integer "price_first_year", limit: 8
t.string "duration"
t.datetime "hidden_at"
t.integer "cached_votes_up", default: 0
t.integer "comments_count", default: 0
t.integer "confidence_score", default: 0, null: false
t.integer "physical_votes", default: 0
t.tsvector "tsv"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "heading_id"
t.string "responsible_name"
t.integer "budget_id"
t.integer "group_id"
t.boolean "selected", default: false
t.string "location"
t.string "organization_name"
t.datetime "unfeasible_email_sent_at"
end
add_index "budget_investments", ["administrator_id"], name: "index_budget_investments_on_administrator_id", using: :btree
add_index "budget_investments", ["author_id"], name: "index_budget_investments_on_author_id", using: :btree
add_index "budget_investments", ["heading_id"], name: "index_budget_investments_on_heading_id", using: :btree
add_index "budget_investments", ["tsv"], name: "index_budget_investments_on_tsv", using: :gin
create_table "budget_valuator_assignments", force: :cascade do |t|
t.integer "valuator_id"
t.integer "investment_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "budget_valuator_assignments", ["investment_id"], name: "index_budget_valuator_assignments_on_investment_id", using: :btree
create_table "budgets", force: :cascade do |t|
t.string "name", limit: 30
t.string "currency_symbol", limit: 10
t.string "phase", limit: 40, default: "accepting"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.text "description_accepting"
t.text "description_reviewing"
t.text "description_selecting"
t.text "description_valuating"
t.text "description_balloting"
t.text "description_reviewing_ballots"
t.text "description_finished"
end
create_table "campaigns", force: :cascade do |t|
t.string "name"
t.string "track_id"
@@ -490,6 +587,7 @@ ActiveRecord::Schema.define(version: 20170103191711) do
t.integer "proposals_count", default: 0
t.integer "spending_proposals_count", default: 0
t.string "kind"
t.integer "budget/investments_count", default: 0
end
add_index "tags", ["debates_count"], name: "index_tags_on_debates_count", using: :btree
@@ -599,6 +697,7 @@ ActiveRecord::Schema.define(version: 20170103191711) do
t.integer "user_id"
t.string "description"
t.integer "spending_proposals_count", default: 0
t.integer "budget_investments_count", default: 0
end
add_index "valuators", ["user_id"], name: "index_valuators_on_user_id", using: :btree

View File

@@ -63,16 +63,17 @@ Setting["meta_keywords"] = nil
# Feature flags
Setting['feature.debates'] = true
Setting['feature.spending_proposals'] = true
Setting['feature.spending_proposals'] = nil
Setting['feature.polls'] = true
Setting['feature.twitter_login'] = true
Setting['feature.facebook_login'] = true
Setting['feature.google_login'] = true
Setting['feature.public_stats'] = true
Setting['feature.budgets'] = true
Setting['feature.signature_sheets'] = true
# Spending proposals feature flags
Setting['feature.spending_proposal_features.voting_allowed'] = true
Setting['feature.spending_proposal_features.voting_allowed'] = nil
# Banner styles
Setting['banner-style.banner-style-one'] = "Banner style 1"
@@ -94,3 +95,4 @@ Setting['mailer_from_address'] = 'noreply@consul.dev'
# Verification settings
Setting['verification_offices_url'] = 'http://oficinas-atencion-ciudadano.url/'
Setting['min_age_to_participate'] = 16