From b036806579f5354212fa03d406c1ade013c53ecf Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Thu, 15 Feb 2018 10:35:22 +0000 Subject: [PATCH 01/11] Return if no answer type --- lib/modules/sections_and_questions_shared.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/modules/sections_and_questions_shared.rb b/lib/modules/sections_and_questions_shared.rb index 02ab3ee..d04731d 100644 --- a/lib/modules/sections_and_questions_shared.rb +++ b/lib/modules/sections_and_questions_shared.rb @@ -20,6 +20,7 @@ def description private def destroy_answer_type + return true unless self.answer_type #return true without deleting the answer type if the answer_type is associated #with other objects (be it questions or sections) return true if self.is_a?(Question) && From 51de9d8407c0e4e59110f8f55245d3aacda73804 Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Tue, 20 Mar 2018 10:19:59 +0000 Subject: [PATCH 02/11] Fix wrong path for filtering_fields --- app/views/loop_item_names/show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/loop_item_names/show.html.erb b/app/views/loop_item_names/show.html.erb index cad0e2a..43e335f 100644 --- a/app/views/loop_item_names/show.html.erb +++ b/app/views/loop_item_names/show.html.erb @@ -25,7 +25,7 @@ <% if @loop_item_name.loop_item_type.is_filtering_field? -%>
Associated filtering field
-
<%= link_to h(@loop_item_name.loop_item_type.filtering_field.name), filtering_field_path(@loop_item_name.loop_item_type.filtering_field) %>
+
<%= link_to h(@loop_item_name.loop_item_type.filtering_field.name), questionnaire_filtering_field_path(@loop_item_name.loop_item_type.filtering_field) %>
<% end -%> <% @loop_item_name.loop_item_name_fields.each do |field| %> From d4132612897e0643610377fc3fc2adf543b04d59 Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Tue, 20 Mar 2018 12:27:19 +0000 Subject: [PATCH 03/11] Add loop item name to PDF --- app/reports/questionnaire_pdf.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/reports/questionnaire_pdf.rb b/app/reports/questionnaire_pdf.rb index be07d61..9699faf 100644 --- a/app/reports/questionnaire_pdf.rb +++ b/app/reports/questionnaire_pdf.rb @@ -120,7 +120,7 @@ def to_pdf requester, user, questionnaire, url_prefix, short_version=false def root_section_to_pdf language, section, user, fields, answers, url_prefix, short_version loop_sources_items = {} - multiplier = 1 + #multiplier = 1 if section.looping? loop_items = section.loop_item_type.loop_items loop_items.each do |loop_item| @@ -146,8 +146,9 @@ def section_to_pdf language, section, user, fields, answers, url_prefix, short_v return if short_version && (answers.empty? || !section.any_answers_from?(user, loop_sources_items, loop_item, looping_identifier)) conditions_met_or_inexistent = section.depends_on_option.present? ? section.dependency_condition_met?(user, looping_identifier) : true #If section is hidden and is a looping section and the loop_item is present, print the loop_item name since there is no drop down list like in the Web Sumbission page - #if section.is_hidden? && section.looping? && loop_item.present? - # text "#{loop_item.item_name(language)}", :size => 11, :style => :bold, :inline_format => true + if section.is_hidden? && section.looping? && loop_item.present? + text "#{loop_item.item_name(language)}", :size => 11, :style => :bold, :inline_format => true + end if !section.is_hidden? field_to_use = fields[:sections_field][section.id.to_s] && fields[:sections_field][section.id.to_s].title.present? ? fields[:sections_field][section.id.to_s] : fields[:sections_field_default][section.id.to_s] size_to_print = section.root? ? 14 : 11 From d330fd77d8040ec3515cbcc0650e7ccaa5dfb55f Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Thu, 29 Mar 2018 12:42:06 +0100 Subject: [PATCH 04/11] Fix answer not found. Answers can get deleted in a previous action --- app/controllers/sections_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/sections_controller.rb b/app/controllers/sections_controller.rb index 76ece7f..f5e0192 100644 --- a/app/controllers/sections_controller.rb +++ b/app/controllers/sections_controller.rb @@ -290,7 +290,7 @@ def save_delegate_text_answers params[:delegate_text_answers].each do |unique_id, inner_params| question_id, looping_id = unique_id.split("_") id = inner_params[:delegate_answer_id] - answer = inner_params[:answer_id] ? Answer.find(inner_params[:answer_id]) : nil + answer = Answer.find_by_id(inner_params[:answer_id]) # looping_id = inner_params[:looping_id] value = inner_params[:value] if value.present? From 594ddc6197887c97d61e9496d2fc440685304576 Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Fri, 13 Apr 2018 15:37:50 +0100 Subject: [PATCH 05/11] Create rake task to export documents --- app/models/questionnaire.rb | 1 + lib/tasks/export_documents.rake | 45 +++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 lib/tasks/export_documents.rake diff --git a/app/models/questionnaire.rb b/app/models/questionnaire.rb index 965b0ba..43efbf8 100644 --- a/app/models/questionnaire.rb +++ b/app/models/questionnaire.rb @@ -31,6 +31,7 @@ class Questionnaire < ActiveRecord::Base has_many :loop_sources, :include => :loop_item_type, :dependent => :destroy has_many :answers, :dependent => :destroy has_many :documents, :through => :answers #documents from the users answers + has_many :answer_links, :through => :answers #links from the users answes has_many :questionnaire_fields, :dependent => :destroy accepts_nested_attributes_for :questionnaire_fields, :reject_if => lambda { |a| a.values.all?(&:blank?) }, :allow_destroy => true # belongs_to :source_questionnaire, :foreign_key => :original_id, :class_name => "Questionnaire" diff --git a/lib/tasks/export_documents.rake b/lib/tasks/export_documents.rake new file mode 100644 index 0000000..1b814f0 --- /dev/null +++ b/lib/tasks/export_documents.rake @@ -0,0 +1,45 @@ +require 'csv' + +namespace :export do + task :documents, [:questionnaire_id] => :environment do |t, args| + questionnaire = Questionnaire.find(args.questionnaire_id) + documents = questionnaire.documents + links = questionnaire.answer_links + + header = ["Name", "Link", "Question title", "Question ID", "Respondent", "Country", "Region"] + + documents_filename = "q#{questionnaire.id}_docments.csv" + links_filename = "q#{questionnaire.id}_links.csv" + + CSV.open(documents_filename, 'w') do |csv| + csv << header + documents.each do |doc| + question = doc.answer.question + user = doc.answer.user + + q_title = Sanitize.clean(question.title) + + csv << [ + doc.doc_file_name, doc.doc.url, q_title, question.id, + "#{user.first_name} #{user.last_name}", user.country, user.region + ] + end + end + + CSV.open(links_filename, 'w') do |csv| + csv << header + links.each do |link| + question = link.answer.question + user = link.answer.user + + q_title = Sanitize.clean(question.title) + + csv << [ + link.title, link.url, q_title, question.id, + "#{user.first_name} #{user.last_name}", user.country, user.region + ] + end + end + + end +end From d5adc954172792e5e025e256339d870c0aa26797 Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Thu, 21 Jun 2018 12:41:42 +0100 Subject: [PATCH 06/11] If document doesn't exist, use original document. Skip otherwise --- app/reports/questionnaire_pdf.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/reports/questionnaire_pdf.rb b/app/reports/questionnaire_pdf.rb index 9699faf..0b153f0 100644 --- a/app/reports/questionnaire_pdf.rb +++ b/app/reports/questionnaire_pdf.rb @@ -233,6 +233,8 @@ def question_to_pdf language, question, answer, loop_item, fields, loop_sources_ text "#{I18n.t('submission_pages.files_you_have')}" move_down 4 answer.documents.each do |document| + document = document.doc.exists? ? document : document.original + next unless document #text "#{document.doc_file_name} #{document.description.present? ? "- #{document.description}" : " "}", :inline_format => true text "#{document.doc_file_name} #{document.description.present? ? "- #{document.description}" : ""}", :inline_format => true move_down 2 From 2303dc8fcd8724cdb954bdf20b3ee9416fe92c74 Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Tue, 11 Dec 2018 11:36:41 +0000 Subject: [PATCH 07/11] Install recaptcha gem --- Gemfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Gemfile b/Gemfile index bfad567..45aee2c 100644 --- a/Gemfile +++ b/Gemfile @@ -51,6 +51,8 @@ gem 'appsignal' gem 'traco' +gem "recaptcha", require: "recaptcha/rails" + # Gems used only for assets and not required # in production environments by default. group :assets do From 576189ae1648392618cba742cb3cf2a3de6c52ad Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Tue, 11 Dec 2018 11:37:16 +0000 Subject: [PATCH 08/11] Ask and verify recaptcha in registration form --- Gemfile.lock | 5 ++++- app/controllers/users_controller.rb | 2 +- app/views/users/new.html.erb | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 476a258..c76c50a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -257,6 +257,8 @@ GEM rake (10.0.3) rdoc (3.12.2) json (~> 1.4) + recaptcha (4.9.0) + json redis (3.2.1) redis-namespace (1.5.2) redis (~> 3.0, >= 3.0.4) @@ -385,6 +387,7 @@ DEPENDENCIES rails (= 3.2.22) rails-secrets rake (= 10.0.3) + recaptcha redis redis-session-store rubocop @@ -406,4 +409,4 @@ DEPENDENCIES uglifier BUNDLED WITH - 1.11.2 + 1.16.1 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 5716d60..1dfb5d2 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -19,7 +19,7 @@ def create # page, the correct fields needed for that questionnaire are present in the form @questionnaire = Questionnaire.find(params[:questionnaire_id], :include => :questionnaire_fields) if params[:questionnaire_id] @user.roles << Role.find_by_name("respondent") unless @user.roles.any? - if @user.save + if verify_recaptcha(model: @user) && @user.save @user.add_or_update_filtering_fields(params[:filtering_field]) if params[:filtering_field] url = "http://#{request.host}/" if !current_user diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index c3dbce1..5af33c1 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -57,6 +57,7 @@ <%= f.label :password_confirmation, t("generic.password_c") %>
<%= f.password_field :password_confirmation %>

+ <%= recaptcha_tags %>

<%= f.submit t("user_new.sign_up") %>

<% end %> From dbb205ce7ec9e44c7654cae2bd4240b1df9b504c Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Tue, 11 Dec 2018 11:38:51 +0000 Subject: [PATCH 09/11] Add env example --- .env.example | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..408d86f --- /dev/null +++ b/.env.example @@ -0,0 +1,7 @@ +APPSIGNAL_PUSH_API_KEY=XXXXXXXXXX +TITANIC_SSH_HOST=XXXXXXXXXX +TITANIC_SSH_USERNAME=XXXXXXXXXX +TITANIC_SSH_FILEPATH=XXXXXXXXXX +export RECAPTCHA_SITE_KEY=XXXXXXXXXX +export RECAPTCHA_SECRET_KEY=XXXXXXXXXX + From 08dcf909b4a27f5e7828832f113ddcd68efcc416 Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Tue, 11 Dec 2018 12:01:25 +0000 Subject: [PATCH 10/11] Further update .env.example --- .env.example | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 408d86f..46c4631 100644 --- a/.env.example +++ b/.env.example @@ -2,6 +2,14 @@ APPSIGNAL_PUSH_API_KEY=XXXXXXXXXX TITANIC_SSH_HOST=XXXXXXXXXX TITANIC_SSH_USERNAME=XXXXXXXXXX TITANIC_SSH_FILEPATH=XXXXXXXXXX +MAILER_ADDRESS_KEY=XXXXXXXXXX +MAILER_PORT_KEY=XXXXXXXXXX +MAILER_DOMAIN_KEY=XXXXXXXXXX +MAILER_USERNAME_KEY=XXXXXXXXXX +MAILER_PASSWORD_KEY=XXXXXXXXXX +MAILER_ASSET_HOST_KEY=XXXXXXXXXX +MAILER_HOST_KEY=XXXXXXXXXX +REDIS_NAMESPACE=XXXXXXXXXX +REDIS_URL=XXXXXXXXXX export RECAPTCHA_SITE_KEY=XXXXXXXXXX export RECAPTCHA_SECRET_KEY=XXXXXXXXXX - From ceb690544aae9a70cd506293f67352e61f6cd507 Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Wed, 12 Dec 2018 16:06:38 +0000 Subject: [PATCH 11/11] Update CHANGELOG --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1627aa8..99e54cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +### 0.3.0 (2018-12-12) + +* Bugfixing + - Fix bug preventing to delete question from admin interface + - Fix wrong filtering fields path + - Add loop item name to PDF + - In the exported pdf, retrieve original document if copied one is not found + +* Add Google reCAPTCHA in sign up form to prevent spam emails + ### 0.2.1 (2018-03-19) * Bugfixing - Fix for a major bug for radio button answers with details text; multiple answers were submitted.