Skip to content

Commit

Permalink
decidim-census: Authorise via census using a CSV file (engine) (#15)
Browse files Browse the repository at this point in the history
Fixes #7
  • Loading branch information
danigb authored and xredo committed Nov 21, 2017
1 parent e99f11d commit 70b6b56
Show file tree
Hide file tree
Showing 136 changed files with 4,096 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ public/uploads
# Ignore env variables
.env
.env.*
.vscode/
.DS_Store
8 changes: 4 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ source 'https://rubygems.org'
ruby '2.4.0'

gem 'decidim', '~> 0.7.2'
gem 'sidekiq'
gem 'decidim-census', path: 'decidim-census'

gem 'letter_opener_web'
gem 'puma', '~> 3.10'
gem 'sidekiq'
gem 'tzinfo-data', platforms: %i(mingw mswin x64_mingw jruby)
gem 'uglifier', '>= 1.3.0'

group :development, :test do
Expand All @@ -28,6 +31,3 @@ group :development do
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'web-console'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: %i(mingw mswin x64_mingw jruby)
19 changes: 19 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
PATH
remote: decidim-census
specs:
decidim-census (0.7.2)
decidim (= 0.7.2)
decidim-admin (= 0.7.2)
rails (~> 5.1.4)
virtus-multiparams (~> 0.1.1)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -326,6 +335,12 @@ GEM
kaminari-core (1.0.1)
launchy (2.4.3)
addressable (~> 2.3)
letter_opener (1.4.1)
launchy (~> 2.2)
letter_opener_web (1.3.1)
actionmailer (>= 3.2)
letter_opener (~> 1.0)
railties (>= 3.2)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
Expand Down Expand Up @@ -564,6 +579,8 @@ GEM
coercible (~> 1.0)
descendants_tracker (~> 0.0, >= 0.0.3)
equalizer (~> 0.0, >= 0.0.9)
virtus-multiparams (0.1.1)
virtus (~> 1.0)
warden (1.2.7)
rack (>= 1.0)
web-console (3.5.0)
Expand All @@ -589,9 +606,11 @@ PLATFORMS
DEPENDENCIES
byebug
decidim (~> 0.7.2)
decidim-census!
decidim-dev (~> 0.7.2)
factory_girl_rails
faker (~> 1.7.3)
letter_opener_web
listen (~> 3.1.0)
pry-byebug
pry-coolline
Expand Down
5 changes: 5 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
Rails.application.routes.draw do
mount Decidim::Core::Engine => '/'
mount Decidim::Census::AdminEngine => '/admin'

if Rails.env.development?
mount LetterOpenerWeb::Engine, at: '/letter_opener'
end

resource :system_status, only: :show
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
class AddReferenceToResults < ActiveRecord::Migration[5.0]
def change
add_column :decidim_results_results, :reference, :string
Decidim::Results::Result.find_each(&:save)
# FIXME: why
# Decidim::Results::Result.find_each(&:save)
change_column_null :decidim_results_results, :reference, false
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ class AddAvailableAuthorizationsToOrganization < ActiveRecord::Migration[5.0]
def change
add_column :decidim_organizations, :available_authorizations, :string, array: true, default: []

handlers = Decidim.authorization_handlers.map(&:name)
# TODO: create a PR in the decidim project
handlers = Decidim.authorization_handlers # .map(&:name)
Decidim::Organization.find_each do |org|
org.update_attributes(available_authorizations: handlers)
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This migration comes from decidim_census (originally 20171110102910)
class CreateDecidimCensusCensusDatum < ActiveRecord::Migration[5.1]

def change
create_table :decidim_census_census_data do |t|
t.references :decidim_organization, foreign_key: true, index: true
t.string :id_document
t.date :birthdate

# The rows in this table are immutable (insert or delete, not update)
# To explicitly reflect this fact there is no `updated_at` column
t.datetime 'created_at', null: false
end
end

end
11 changes: 10 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20171107144186) do
ActiveRecord::Schema.define(version: 20171120130226) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -132,6 +132,14 @@
t.index ["decidim_category_id"], name: "index_decidim_categorizations_on_decidim_category_id"
end

create_table "decidim_census_census_data", force: :cascade do |t|
t.bigint "decidim_organization_id"
t.string "id_document"
t.date "birthdate"
t.datetime "created_at", null: false
t.index ["decidim_organization_id"], name: "index_decidim_census_census_data_on_decidim_organization_id"
end

create_table "decidim_comments_comment_votes", id: :serial, force: :cascade do |t|
t.integer "weight", null: false
t.integer "decidim_comment_id", null: false
Expand Down Expand Up @@ -607,6 +615,7 @@

add_foreign_key "decidim_authorizations", "decidim_users"
add_foreign_key "decidim_categorizations", "decidim_categories"
add_foreign_key "decidim_census_census_data", "decidim_organizations"
add_foreign_key "decidim_identities", "decidim_organizations"
add_foreign_key "decidim_newsletters", "decidim_users", column: "author_id"
add_foreign_key "decidim_participatory_process_steps", "decidim_participatory_processes"
Expand Down
8 changes: 8 additions & 0 deletions decidim-census/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.bundle/
log/*.log
pkg/
test/dummy/db/*.sqlite3
test/dummy/db/*.sqlite3-journal
test/dummy/log/*.log
test/dummy/tmp/
examples/example.csv
14 changes: 14 additions & 0 deletions decidim-census/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
source 'https://rubygems.org'

# Declare your gem's dependencies in decidim-census.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group.
gemspec

# Declare any dependencies that are still in development here instead of in
# your gemspec. These might include edge Rails or gems from your path or
# Git. Remember to move these dependencies to your gemspec before releasing
# your gem to rubygems.org.

# To use a debugger
gem 'pry-byebug', group: %i(development test)

0 comments on commit 70b6b56

Please sign in to comment.