Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce a module for ephemeral participation and a integrated Census+SMS verification #368

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@
/imports

.rspec-failures
Capfile
config/deploy*
34 changes: 10 additions & 24 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Style/Alias:
- prefer_alias_method

# Align the elements of a hash literal if they span more than one line.
Layout/AlignHash:
Layout/HashAlignment:
# Alignment of entries using hash rocket as separator. Valid values are:
#
# key - left alignment of keys
Expand Down Expand Up @@ -152,7 +152,7 @@ Layout/AlignHash:
- ignore_implicit
- ignore_explicit

Layout/AlignParameters:
Layout/ParameterAlignment:
# Alignment of parameters in multi-line method calls.
#
# The `with_first_parameter` style aligns the following lines along the same
Expand Down Expand Up @@ -263,20 +263,6 @@ Style/BlockDelimiters:
- proc
- it

Style/BracesAroundHashParameters:
EnforcedStyle: no_braces
SupportedStyles:
# The `braces` style enforces braces around all method parameters that are
# hashes.
- braces
# The `no_braces` style checks that the last parameter doesn't have braces
# around it.
- no_braces
# The `context_dependent` style checks that the last parameter doesn't have
# braces around it, but requires braces if the second to last parameter is
# also a hash literal.
- context_dependent

# Indentation of `when`.
Layout/CaseIndentation:
EnforcedStyle: case
Expand Down Expand Up @@ -469,7 +455,7 @@ Naming/FileName:
# files with a shebang in the first line).
IgnoreExecutableScripts: true

Layout/IndentFirstArgument:
Layout/FirstArgumentIndentation:
EnforcedStyle: special_for_inner_method_call_in_parentheses
SupportedStyles:
# The first parameter should always be indented one step more than the
Expand Down Expand Up @@ -557,7 +543,7 @@ Layout/IndentationWidth:
Width: 2

# Checks the indentation of the first element in an array literal.
Layout/IndentFirstArrayElement:
Layout/FirstArrayElementIndentation:
# The value `special_inside_parentheses` means that array literals with
# brackets that have their opening bracket on the same line as a surrounding
# opening round parenthesis, shall have their first element indented relative
Expand All @@ -579,13 +565,13 @@ Layout/IndentFirstArrayElement:
IndentationWidth: ~

# Checks the indentation of assignment RHS, when on a different line from LHS
Layout/IndentAssignment:
Layout/AssignmentIndentation:
# By default, the indentation width from Style/IndentationWidth is used
# But it can be overridden by setting this parameter
IndentationWidth: ~

# Checks the indentation of the first key in a hash literal.
Layout/IndentFirstHashElement:
Layout/FirstHashElementIndentation:
# The value `special_inside_parentheses` means that hash literals with braces
# that have their opening brace on the same line as a surrounding opening
# round parenthesis, shall have their first key indented relative to the
Expand Down Expand Up @@ -792,12 +778,12 @@ Naming/PredicateName:
- has_
- have_
# Predicate name prefixes that should be removed.
NamePrefixBlacklist:
ForbiddenPrefixes:
- is_
- have_
# Predicate names which, despite having a blacklisted prefix, or no ?,
# should still be accepted
NameWhitelist:
AllowedMethods:
- is_a?
# Exclude Rspec specs because there is a strong convetion to write spec
# helpers in the form of `have_something` or `be_something`.
Expand Down Expand Up @@ -978,7 +964,7 @@ Style/TernaryParentheses:
- require_no_parentheses
AllowSafeAssignment: true

Layout/TrailingBlankLines:
Layout/TrailingEmptyLines:
EnforcedStyle: final_newline
SupportedStyles:
- final_newline
Expand Down Expand Up @@ -1028,7 +1014,7 @@ Style/TrivialAccessors:
# Commonly used in DSLs
AllowDSLWriters: false
IgnoreClassMethods: false
Whitelist:
AllowedMethods:
- to_ary
- to_a
- to_c
Expand Down
8 changes: 7 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
source "https://rubygems.org"

DECIDIM_VERSION = { git: "https://github.com/decidim/decidim", branch: "release/0.24-stable" }
DECIDIM_MAIN_BRANCH = "feature/bcn-budget-v0.24"

DECIDIM_VERSION = { git: "https://github.com/AjuntamentdeBarcelona/decidim", branch: DECIDIM_MAIN_BRANCH }.freeze

ruby '2.7.2'

gem "decidim", DECIDIM_VERSION
gem "decidim-census_sms", path: "decidim-census_sms"
gem "decidim-dataviz", path: "decidim-dataviz"
gem "decidim-initiatives", DECIDIM_VERSION
gem "decidim-sortitions", DECIDIM_VERSION
gem "decidim-stats", path: "decidim-stats"
gem "decidim-valid_auth", path: "decidim-valid_auth"
gem "decidim-ephemeral_participation", path: "decidim-ephemeral_participation"
gem "decidim-navigation_maps", "~> 1.2.0"

# Change term_customizer dependency to ruby-gems' when term-customizer is compatible with DECIDIM_VERSION
Expand Down Expand Up @@ -49,6 +53,8 @@ group :development do
end

group :production do
# can be removed after
gem "letter_opener_web"
gem "sidekiq"
gem "rails_12factor"
gem "fog-aws"
Expand Down
48 changes: 31 additions & 17 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
GIT
remote: https://github.com/CodiTramuntana/decidim-module-term_customizer
revision: c4ed0ffa87bd9977c6b470aa815d5dc2ed9f88a5
specs:
decidim-term_customizer (0.18.0)
decidim-admin (>= 0.18.0)
decidim-core (>= 0.18.0)

GIT
remote: https://github.com/decidim/decidim
revision: 2f1e3c8ad256dfc2616530a5049107e6335eceea
branch: release/0.24-stable
remote: https://github.com/AjuntamentdeBarcelona/decidim
revision: e471864fcb4011b096ed31ea312814d6299b9f3d
branch: feature/bcn-budget-v0.24
specs:
decidim (0.24.2)
decidim-accountability (= 0.24.2)
Expand Down Expand Up @@ -225,12 +217,32 @@ GIT
decidim-verifications (0.24.2)
decidim-core (= 0.24.2)

GIT
remote: https://github.com/CodiTramuntana/decidim-module-term_customizer
revision: c4ed0ffa87bd9977c6b470aa815d5dc2ed9f88a5
specs:
decidim-term_customizer (0.18.0)
decidim-admin (>= 0.18.0)
decidim-core (>= 0.18.0)

PATH
remote: decidim-census_sms
specs:
decidim-census_sms (0.0.1)
decidim-core

PATH
remote: decidim-dataviz
specs:
decidim-dataviz (0.0.1)
decidim-core

PATH
remote: decidim-ephemeral_participation
specs:
decidim-ephemeral_participation (0.0.1)
decidim-verifications

PATH
remote: decidim-stats
specs:
Expand Down Expand Up @@ -352,7 +364,7 @@ GEM
actionpack (>= 3.0)
cells (>= 4.1.6, < 5.0.0)
charlock_holmes (0.7.7)
chef-utils (17.0.242)
chef-utils (17.1.35)
concurrent-ruby
childprocess (3.0.0)
coercible (1.0.0)
Expand Down Expand Up @@ -410,7 +422,7 @@ GEM
doc2text (0.4.3)
nokogiri (~> 1.11.1)
rubyzip (~> 2.3.0)
docile (1.3.5)
docile (1.4.0)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
doorkeeper (5.5.1)
Expand Down Expand Up @@ -503,7 +515,7 @@ GEM
graphiql-rails (1.4.11)
railties
sprockets-rails
graphql (1.12.9)
graphql (1.12.10)
hashdiff (1.0.1)
hashie (4.1.0)
highline (2.0.3)
Expand Down Expand Up @@ -653,7 +665,7 @@ GEM
activerecord (>= 5.2)
activesupport (>= 5.2)
polyglot (0.3.5)
premailer (1.14.3)
premailer (1.15.0)
addressable
css_parser (>= 1.6.0)
htmlentities (>= 4.0.0)
Expand Down Expand Up @@ -839,7 +851,7 @@ GEM
smart_properties (1.15.0)
social-share-button (1.2.4)
coffee-rails
spreadsheet (1.2.8)
spreadsheet (1.2.9)
ruby-ole
spring (2.1.1)
spring-watcher-listen (2.0.1)
Expand Down Expand Up @@ -891,7 +903,7 @@ GEM
virtus (~> 1.0)
warden (1.2.9)
rack (>= 2.0.9)
webmock (3.12.2)
webmock (3.13.0)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
Expand All @@ -917,8 +929,10 @@ DEPENDENCIES
dalli
database_cleaner
decidim!
decidim-census_sms!
decidim-dataviz!
decidim-dev!
decidim-ephemeral_participation!
decidim-initiatives!
decidim-navigation_maps (~> 1.2.0)
decidim-sortitions!
Expand Down
1 change: 1 addition & 0 deletions app/assets/stylesheets/_barcelona.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
@import "theme-barcelona/hero-custom";
@import "theme-barcelona/event-days";
@import "theme-barcelona/special-process";
@import "theme-barcelona/budgets";
11 changes: 11 additions & 0 deletions app/assets/stylesheets/theme-barcelona/_budgets.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.budget-progress {
.progress-meter {
&:not(&--minimum) {
background-color: $red-light;
}
}
}

#project .card.extra .button_to {
display: none;
}
8 changes: 6 additions & 2 deletions app/services/census_authorization_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def census_document_types

def unique_id
Digest::MD5.hexdigest(
"#{document_number&.upcase}-#{Rails.application.secrets.secret_key_base}"
"#{sanitized_document_number}-#{Rails.application.secrets.secret_key_base}"
)
end

Expand All @@ -83,6 +83,10 @@ def document_type_valid
errors.add(:document_number, I18n.t("census_authorization_handler.invalid_document")) unless response.xpath("//codiRetorn").text == "01"
end

def sanitized_document_number
document_number&.gsub(/[^A-Za-z0-9]/, "")&.upcase
end

def response
return nil if document_number.blank? ||
document_type.blank? ||
Expand All @@ -109,7 +113,7 @@ def request_body
<sch:usuari>PAM</sch:usuari>
<sch:Dades>
<sch:tipDocument>#{sanitized_document_type}</sch:tipDocument>
<sch:docId>#{sanitize document_number&.upcase}</sch:docId>
<sch:docId>#{sanitized_document_number}</sch:docId>
<sch:codiPostal>#{sanitize postal_code}</sch:codiPostal>
<sch:dataNaixConst>#{sanitized_date_of_birth}</sch:dataNaixConst>
</sch:Dades>
Expand Down
18 changes: 18 additions & 0 deletions config/initializers/decidim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@

if Rails.application.secrets.sms.values.all?(&:present?)
config.sms_gateway_service = "SmsGateway"

Decidim::Verifications.register_workflow(:census_sms_authorization_handler) do |auth|
auth.engine = Decidim::CensusSms::Verification::Engine
auth.action_authorizer = "Decidim::CensusSms::Verification::ActionAuthorizer"
auth.renewable = true
auth.time_between_renewals = 1.day
auth.ephemerable = true

auth.options do |options|
parent_scope = Decidim::Scope.where("name->>'ca' = 'Ciutat'").first

Decidim::Scope.where(parent: parent_scope).pluck(:code).each do |code|
options.attribute :"scope_code_#{code}", type: :boolean, required: false
end
end
end
end

config.timestamp_service = "TimestampService"
Expand All @@ -38,11 +54,13 @@
auth.renewable = true
auth.time_between_renewals = 1.day
auth.metadata_cell = "census_authorization_metadata"
auth.ephemerable = true
end

Decidim::Verifications.register_workflow(:census16_authorization_handler) do |auth|
auth.form = "Census16AuthorizationHandler"
auth.renewable = true
auth.time_between_renewals = 1.day
auth.metadata_cell = "census16_authorization_metadata"
auth.ephemerable = true
end
2 changes: 2 additions & 0 deletions config/initializers/decidim_budgets.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# frozen_string_literal: true

require "budgets_workflow_pam2020"
require "budgets_workflow_pam2021"
Decidim::Budgets.workflows[:pam2020] = BudgetsWorkflowPam2020
Decidim::Budgets.workflows[:pam2021] = BudgetsWorkflowPam2021
5 changes: 4 additions & 1 deletion config/locales/ca.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ ca:
first_login:
actions:
census_authorization_handler: Verifica't amb el padró
census16_authorization_handler: Verifica't amb el padró (16+)
census_sms_authorization_handler: Verifica't amb el padró i el teu mòbil
valid_auth: Valid auth
initiatives:
initiatives:
supports:
Expand All @@ -154,4 +157,4 @@ ca:
home:
extended:
debates_explanation: Espais per informar-te i decidir sobre les propostes
de cada procés.
de cada procés.
11 changes: 11 additions & 0 deletions config/locales/decidim_budgets_workflows_ca.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ca:
decidim:
components:
budgets:
settings:
global:
ephemerous_census_data_verification: Ephemerous Census Data Verification
workflow_choices:
pam2020: "PAM 2020: allows to Vote in the participant's district and in another of free choice."
pam2021: "PAM 2021: allows to Vote in the participant's district and in another of free choice."

2 changes: 2 additions & 0 deletions config/locales/decidim_budgets_workflows_en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ en:
budgets:
settings:
global:
ephemerous_census_data_verification: Ephemerous Census Data Verification
workflow_choices:
pam2020: "PAM 2020: allows to Vote in the participant's district and in another of free choice."
pam2021: "PAM 2021: allows to Vote in the participant's district and in another of free choice."
11 changes: 11 additions & 0 deletions config/locales/decidim_budgets_workflows_es.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
es:
decidim:
components:
budgets:
settings:
global:
ephemerous_census_data_verification: Ephemerous Census Data Verification
workflow_choices:
pam2020: "PAM 2020: allows to Vote in the participant's district and in another of free choice."
pam2021: "PAM 2021: allows to Vote in the participant's district and in another of free choice."

Loading