-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4dd10fc
commit 9a37566
Showing
5 changed files
with
129 additions
and
5 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
app/controllers/concerns/decidim/anonymous_codes/surveys_controller_override.rb
This file contains 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,35 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module AnonymousCodes | ||
module SurveysControllerOverride | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
before_action do | ||
unless token_groups.any? && current_token.present? | ||
flash.now[:alert] = I18n.t("decidim.anonymous_codes.invalid_code") if params.has_key?(:token) | ||
render "decidim/anonymous_codes/surveys/code_required" | ||
end | ||
end | ||
|
||
private | ||
|
||
def token_groups | ||
@token_groups ||= Decidim::AnonymousCodes::Group.where(resource: survey) | ||
end | ||
|
||
def current_token | ||
@current_token ||= Decidim::AnonymousCodes::Token.where(group: token_groups).find_by(token: token_param) | ||
end | ||
|
||
def token_param | ||
@token_param ||= begin | ||
session[:anonymous_codes_token] = params[:token] if params.has_key?(:token) | ||
session[:anonymous_codes_token] | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
50 changes: 50 additions & 0 deletions
50
app/views/decidim/anonymous_codes/surveys/code_required.html.erb
This file contains 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,50 @@ | ||
<% add_decidim_meta_tags({ | ||
title: translated_attribute(questionnaire.title), | ||
description: translated_attribute(questionnaire.description), | ||
}) %> | ||
<%= render partial: "decidim/shared/component_announcement" if current_component.manifest_name == "surveys" %> | ||
|
||
<div class="row columns"> | ||
<h2 class="section-heading"><%= translated_attribute questionnaire.title %></h2> | ||
<div class="row"> | ||
<div class="columns large-6 medium-centered lead"> | ||
<%= decidim_sanitize_editor_admin translated_attribute questionnaire.description %> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="row"> | ||
<div class="columns large-6 medium-centered"> | ||
<div class="card"> | ||
<div class="card__content"> | ||
<% unless questionnaire_for.try(:component)&.try(:published?) %> | ||
<div class="section"> | ||
<div class="callout warning"> | ||
<p><%= t("questionnaire_not_published.body", scope: "decidim.forms.questionnaires.show") %></p> | ||
</div> | ||
</div> | ||
<% end %> | ||
|
||
<div class="section"> | ||
<div class="callout warning"> | ||
<h3 class="heading4"><%= t(".title") %></h3> | ||
<p><%= t(".body") %></p> | ||
</div> | ||
<fi3eldset class="field"> | ||
<label class="field__label" for="code"><%= t(".label") %></label> | ||
<div class="field__input"> | ||
<form method="get"> | ||
<%= text_field_tag :token, nil, class: "input", required: true %> | ||
<button type="submit" class="button"><%= t(".submit") %></button> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<% content_for :js_content do %> | ||
<%= javascript_pack_tag "decidim_forms" %> | ||
<% end %> |
This file contains 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 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 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