Skip to content

Commit

Permalink
Merge branch 'release-0.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Levia committed Dec 12, 2018
2 parents dc3e324 + ceb6905 commit cfa498f
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 6 deletions.
15 changes: 15 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
ADMIN_PASSWORD=XXXXXXXXXX
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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,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
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,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)
Expand Down Expand Up @@ -405,6 +407,7 @@ DEPENDENCIES
rails (= 3.2.22)
rails-secrets
rake (= 10.0.3)
recaptcha
redis
redis-session-store
rubocop
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/sections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,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
Expand Down
1 change: 1 addition & 0 deletions app/models/questionnaire.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 6 additions & 3 deletions app/reports/questionnaire_pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -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
Expand Down Expand Up @@ -232,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 "<color rgb='#104E8B'><u><a target='_blank' href='#{url_prefix + document.doc.url.split('?')[0]}'>#{document.doc_file_name}</a></u></color> #{document.description.present? ? "- #{document.description}" : " "}", :inline_format => true
text "<u><a target='_blank' href='#{url_prefix + document.doc.url.split('?')[0]}'>#{document.doc_file_name}</a></u> #{document.description.present? ? "- #{document.description}" : ""}", :inline_format => true
move_down 2
Expand Down
2 changes: 1 addition & 1 deletion app/views/loop_item_names/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<% if @loop_item_name.loop_item_type.is_filtering_field? -%>
<div class="row padded group">
<div class="col col-3">Associated filtering field</div>
<div class="col col-9 border-left"><%= link_to h(@loop_item_name.loop_item_type.filtering_field.name), filtering_field_path(@loop_item_name.loop_item_type.filtering_field) %></div>
<div class="col col-9 border-left"><%= link_to h(@loop_item_name.loop_item_type.filtering_field.name), questionnaire_filtering_field_path(@loop_item_name.loop_item_type.filtering_field) %></div>
</div>
<% end -%>
<% @loop_item_name.loop_item_name_fields.each do |field| %>
Expand Down
1 change: 1 addition & 0 deletions app/views/users/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<%= f.label :password_confirmation, t("generic.password_c") %><br />
<%= f.password_field :password_confirmation %>
</p>
<%= recaptcha_tags %>
<p><%= f.submit t("user_new.sign_up") %></p>
<% end %>
</div>
1 change: 1 addition & 0 deletions lib/modules/sections_and_questions_shared.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand Down
45 changes: 45 additions & 0 deletions lib/tasks/export_documents.rake
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit cfa498f

Please sign in to comment.