This repository was archived by the owner on Oct 22, 2025. It is now read-only.
forked from DiputacioBarcelona/decidim-diba
-
Notifications
You must be signed in to change notification settings - Fork 1
Add subcensus authorized to the participatory processes #4
Open
artero
wants to merge
3
commits into
master
Choose a base branch
from
feature/add_subcensus
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
db/migrate/20191017081707_create_decidim_census_subcensus.decidim_census.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
13 changes: 13 additions & 0 deletions
13
db/migrate/20191017081708_create_decidim_census_subcensus_documents.decidim_census.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.