Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.
Open
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
52 changes: 51 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ GEM
execjs (~> 2.0)
batch-loader (1.4.1)
bcrypt (3.1.13)
bcrypt (3.1.13-java)
better_html (1.0.14)
actionview (>= 4.0)
activesupport (>= 4.0)
Expand Down Expand Up @@ -406,6 +407,9 @@ GEM
faraday (0.15.4)
multipart-post (>= 1.2, < 3)
ffi (1.9.25)
ffi (1.9.25-java)
ffi (1.9.25-x64-mingw32)
ffi (1.9.25-x86-mingw32)
file_validators (2.3.0)
activemodel (>= 3.2)
mime-types (>= 1.0)
Expand Down Expand Up @@ -463,13 +467,15 @@ GEM
invisible_captcha (0.10.0)
rails (>= 3.2.0)
jaro_winkler (1.5.3)
jaro_winkler (1.5.3-java)
jquery-rails (4.3.5)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
jquery-tmpl-rails (1.1.0)
rails (>= 3.1.0)
json (2.2.0)
json (2.2.0-java)
jwt (2.2.1)
kaminari (1.1.1)
activesupport (>= 4.1.0)
Expand All @@ -486,8 +492,12 @@ GEM
kramdown (1.17.0)
ladle (1.0.1)
open4 (~> 1.0)
ladle (1.0.1-java)
launchy (2.4.3)
addressable (~> 2.3)
launchy (2.4.3-java)
addressable (~> 2.3)
spoon (~> 0.0.1)
letter_opener (1.7.0)
launchy (~> 2.2)
letter_opener_web (1.3.4)
Expand Down Expand Up @@ -528,9 +538,15 @@ GEM
net-ldap (0.16.1)
netrc (0.11.0)
nio4r (2.4.0)
nio4r (2.4.0-java)
nobspw (0.6.1)
nokogiri (1.10.3)
mini_portile2 (~> 2.4.0)
nokogiri (1.10.3-java)
nokogiri (1.10.3-x64-mingw32)
mini_portile2 (~> 2.4.0)
nokogiri (1.10.3-x86-mingw32)
mini_portile2 (~> 2.4.0)
nori (2.6.0)
oauth (0.5.4)
oauth2 (1.4.1)
Expand Down Expand Up @@ -568,6 +584,8 @@ GEM
parser (2.6.3.0)
ast (~> 2.4.0)
pg (1.1.4)
pg (1.1.4-x64-mingw32)
pg (1.1.4-x86-mingw32)
pg_search (2.3.0)
activerecord (>= 4.2)
activesupport (>= 4.2)
Expand All @@ -582,6 +600,10 @@ GEM
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
pry (0.12.2-java)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
spoon (~> 0.0)
pry-byebug (3.6.0)
byebug (~> 10.0)
pry (~> 0.10)
Expand All @@ -591,6 +613,7 @@ GEM
pry (>= 0.10.4)
public_suffix (3.1.1)
puma (3.12.1)
puma (3.12.1-java)
raabro (1.1.6)
rack (2.0.7)
rack-attack (5.4.2)
Expand Down Expand Up @@ -659,6 +682,21 @@ GEM
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rest-client (2.0.2-x64-mingw32)
ffi (~> 1.9)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rest-client (2.0.2-x86-mingw32)
ffi (~> 1.9)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rest-client (2.0.2-x86-mswin32)
ffi (~> 1.9)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rspec (3.7.0)
rspec-core (~> 3.7.0)
rspec-expectations (~> 3.7.0)
Expand Down Expand Up @@ -743,6 +781,8 @@ GEM
social-share-button (1.2.0)
coffee-rails
socksify (1.7.1)
spoon (0.0.6)
ffi
spreadsheet (1.2.4)
ruby-ole (>= 1.0)
spring (2.1.0)
Expand All @@ -769,18 +809,22 @@ GEM
unicode-display_width (~> 1.1, >= 1.1.1)
thor (0.20.3)
thread_safe (0.3.6)
thread_safe (0.3.6-java)
tilt (2.0.9)
tomlrb (1.2.8)
truncato (0.7.11)
htmlentities (~> 4.3.1)
nokogiri (>= 1.7.0, <= 2.0)
tzinfo (1.2.5)
thread_safe (~> 0.1)
tzinfo-data (1.2019.3)
tzinfo (>= 1.0.0)
uber (0.1.0)
uglifier (4.1.20)
execjs (>= 0.3.0, < 3)
unf (0.1.4)
unf_ext
unf (0.1.4-java)
unf_ext (0.0.7.6)
unicode-display_width (1.6.0)
unicode_utils (1.4.0)
Expand Down Expand Up @@ -810,14 +854,20 @@ GEM
hashdiff
websocket-driver (0.7.1)
websocket-extensions (>= 0.1.0)
websocket-driver (0.7.1-java)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.4)
wisper (2.0.0)
wisper-rspec (1.1.0)
xpath (3.2.0)
nokogiri (~> 1.8)

PLATFORMS
java
ruby
x64-mingw32
x86-mingw32
x86-mswin32

DEPENDENCIES
byebug
Expand Down Expand Up @@ -855,4 +905,4 @@ RUBY VERSION
ruby 2.5.1p57

BUNDLED WITH
1.16.4
1.17.3
16 changes: 16 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
module ApplicationHelper
def text_invalid_age_authorizer(status)
options = status.instance_variable_get(:@authorization_handler)
.instance_variable_get(:@action_authorizer)
.instance_variable_get(:@options)
scope = 'diba.decidim.authorization_modals.content.birthdate.invalid_field'
min_age = options['age']
max_age = options['max_age']

if min_age.present? && max_age.present?
t('both', scope: scope, max_age: max_age, min_age: min_age)
elsif min_age.present? && max_age.blank?
t('min_age', scope: scope, min_age: min_age)
elsif min_age.blank? && max_age.present?
t('max_age', scope: scope, max_age: max_age)
end
end
end
52 changes: 52 additions & 0 deletions app/views/decidim/authorization_modals/_content.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<% if current_user && !current_user.verifiable? %>
<div class="reveal__header missing-confirmation">
<h3 class="reveal__title"><%= t ".unconfirmed.title" %></h3>
</div>
<p><%= t ".unconfirmed.explanation_html", email: current_user.email %></p>
<p><%= t ".unconfirmed.confirmation_instructions" %></p>
<div class="row">
<div class="columns medium-8 medium-offset-2">
<%= link_to t(".unconfirmed.request_confirmation_instructions"), new_confirmation_path(Decidim::User), class: "button expanded" %>
</div>
</div>
<% else %>
<% base_code = authorizations.global_code || :missing %>
<div class="reveal__header <%= base_code %>-authorization">
<h3 class="reveal__title"><%= t ".#{base_code}.title" %></h3>
</div>
<% authorizations.statuses.each do |status| %>
<% next if status.ok? || authorizations.global_code && status.code != base_code %>
<p><%= t ".#{status.code}.explanation", authorization: t("#{status.handler_name}.name", scope: "decidim.authorization_handlers") %></p>
<% if status.data[:extra_explanation] %>
<p><%= t status.data[:extra_explanation][:key], **status.data[:extra_explanation][:params] %></p>
<% end %>
<% if status.data[:fields] %>
<ul>
<% status.data[:fields].each do |field, value| %>
<% case field %>
<% when :birthdate %>
<li> <strong> <%= text_invalid_age_authorizer(status) %> </strong> </li>
<% when :subcensus %>
<li> <strong> <%= t(".subcensus.invalid_field", scope: "diba")%> </strong> </li>
<% else %>
<li><strong><%= t ".#{status.code}.invalid_field", field: t("#{status.handler_name}.fields.#{field}", scope: "decidim.authorization_handlers"), value: value ? "(#{value})" : "" %></strong></li>
<% end %>
<% end %>
</ul>
<% end %>
<div class="row">
<div class="columns medium-8 medium-offset-2">
<% if status.data[:action].present? %>
<%= link_to t(".#{status.code}.#{status.data[:action]}", authorization: t("#{status.handler_name}.name", scope: "decidim.authorization_handlers")), authorize_action_path(status.handler_name), class: "button expanded" %>
<% else %>
<button class="button expanded" data-close><%= t ".#{status.code}.ok" %></button>
<% end %>
</div>
</div>
<% if status.data[:cancel] %>
<div class="text-center">
<button class="link" data-close><%= t ".#{status.code}.cancel" %></button>
</div>
<% end %>
<% end %>
<% end %>
28 changes: 28 additions & 0 deletions config/initializers/subcensus_authorizer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Decidim does not allow to use more than one ActionAuthorization inside an
# AuthorizationHandler.
# This code adds an aditional validation to the AgeActionAuthorization to validate
# the subcensus.

module SubcensusAuthorizer
def set_unmatched_fields
errors = []
errors << :birthdate unless valid_age?
errors << :subcensus unless valid_subcensus?
errors
end

def valid_subcensus?
subcensus = Decidim::Census::Subcensus.find_by(
decidim_participatory_process_id: @component&.participatory_space&.id
)

return true if subcensus.blank?

Decidim::Census::SubcensusDocument.where(
id_document: @authorization&.unique_id,
decidim_census_subcensus_id: subcensus.id
).any?
end
end

Decidim::AgeActionAuthorization::Authorizer.prepend(SubcensusAuthorizer)
11 changes: 11 additions & 0 deletions config/locales/ca.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,14 @@ ca:
user:
invalid: Correu electrònic o contrasenya no vàlids.
not_found_in_database: Correu electrònic o contrasenya no vàlids.
diba:
decidim:
authorization_modals:
content:
birthdate:
invalid_field:
both: "Aquesta acció està restringida als habitants del padró municipal entre %{min_age} i %{max_age} anys"
min_age: "Aquesta acció està restringida als habitants del padró municipal majors de %{min_age} anys"
max_age: "Aquesta acció està restringida als habitants del padró municipal menors de %{max_age} anys"
subcensus:
invalid_field: "Aquesta acció està restringida a un conjunt d'habitants del padró municipal del qual no en formes part. Contacta amb nosaltres si creus que n'hauries de formar part i aquesta acció és de teu interés."
11 changes: 11 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,14 @@ en:
proposals:
actions:
withdraw: Withdraw
diba:
decidim:
authorization_modals:
content:
birthdate:
invalid_field:
both: "This action is restricted to the inhabitants of the municipal census between %{min_age} and %{max_age} years old."
min_age: "This action is restricted to the inhabitants of the municipal census older than %{min_age} years."
max_age: "This action is restricted to the inhabitants of the municipal census under the age of %{max_age}."
subcensus:
invalid_field: "This action is restricted to a group of inhabitants of the municipal census which you are not part of. Contact us if you think you should belong to this group and you are interested in being able to perform this action."
11 changes: 11 additions & 0 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,14 @@ es:
proposals:
actions:
withdraw: Retirar
diba:
decidim:
authorization_modals:
content:
birthdate:
invalid_field:
both: "Esta acción está restringida a los habitantes del padrón municipal entre %{min_age} y %{max_age} años"
min_age: "Esta acción está restringida a los habitantes del padrón municipal mayores de %{min_age} años"
max_age: "Esta acción está restringida a los habitantes del padrón municipal menores de %{max_age} años"
subcensus:
invalid_field: "Esta acción está restringida a un conjunto de habitantes del padrón municipal del cual no formas parte. Contacta con nosotros si crees que tendrías que formar parte de este grupo y esta acción es de tu interés."
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This migration comes from decidim_census (originally 20191008121918)
class CreateDecidimCensusSubcensus < ActiveRecord::Migration[5.2]

def change
create_table :decidim_census_subcensuses do |t|
t.references :decidim_participatory_process, index: { name: 'index_decidim_census_subcensuses_on_participatory_process_id' }
t.string :name

t.timestamps
end
end

end
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This migration comes from decidim_census (originally 20191009140338)
class CreateDecidimCensusSubcensusDocuments < ActiveRecord::Migration[5.2]

def change
create_table :decidim_census_subcensus_documents do |t|
t.references :decidim_census_subcensus, index: { name: 'index_census_subcensus_documents_on_census_subcensus_id' }
t.string :id_document

t.timestamps
end
end

end
20 changes: 18 additions & 2 deletions 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: 2019_07_26_100964) do
ActiveRecord::Schema.define(version: 2019_10_17_081708) do

# These are extensions that must be enabled in order to support this database
enable_extension "ltree"
Expand Down Expand Up @@ -310,6 +310,22 @@
t.index ["decidim_organization_id"], name: "index_decidim_census_census_data_on_decidim_organization_id"
end

create_table "decidim_census_subcensus_documents", force: :cascade do |t|
t.bigint "decidim_census_subcensus_id"
t.string "id_document"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["decidim_census_subcensus_id"], name: "index_census_subcensus_documents_on_census_subcensus_id"
end

create_table "decidim_census_subcensuses", force: :cascade do |t|
t.bigint "decidim_participatory_process_id"
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["decidim_participatory_process_id"], name: "index_decidim_census_subcensuses_on_participatory_process_id"
end

create_table "decidim_coauthorships", force: :cascade do |t|
t.bigint "decidim_author_id", null: false
t.bigint "decidim_user_group_id"
Expand Down Expand Up @@ -1018,7 +1034,7 @@
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "decidim_author_type", null: false
t.index "decidim_proposal_id, decidim_author_id, COALESCE(decidim_user_group_id, ('-1'::integer)::bigint)", name: "decidim_proposals_proposal_endorsmt_proposal_auth_ugroup_uniq", unique: true
t.index "decidim_proposal_id, decidim_author_id, (COALESCE(decidim_user_group_id, ('-1'::integer)::bigint))", name: "decidim_proposals_proposal_endorsmt_proposal_auth_ugroup_uniq", unique: true
t.index ["decidim_author_id", "decidim_author_type"], name: "index_decidim_proposals_proposal_endorsements_on_decidim_author"
t.index ["decidim_proposal_id"], name: "decidim_proposals_proposal_endorsement_proposal"
t.index ["decidim_user_group_id"], name: "decidim_proposals_proposal_endorsement_user_group"
Expand Down
Loading