From a83c259a04904c4448bfccd58818af7d1363fa99 Mon Sep 17 00:00:00 2001 From: Angel Perez Date: Wed, 4 Oct 2017 15:49:15 -0400 Subject: [PATCH 01/91] Remove 'description' attribute from Poll::Question This avoid an exception when seeding the database See PR #1977 --- db/dev_seeds.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index b151a45cf..3ce1a439f 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -559,7 +559,6 @@ print "Creating Poll Questions" open_at = rand(2.months.ago..2.months.from_now) question = Poll::Question.create!(author: author, title: Faker::Lorem.sentence(3).truncate(60), - description: description, valid_answers: Faker::Lorem.words((2..7).to_a.sample).join(', '), poll: poll) end From f4774894e7ee94a904c5501d3e2c30529b48ca9e Mon Sep 17 00:00:00 2001 From: Angel Perez Date: Wed, 4 Oct 2017 16:59:23 -0400 Subject: [PATCH 02/91] Adapt Admin::Poll::Question 'show' action to new design MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changes required as per issues #1855 and #1951 Fixes PR #1977, note n° 2 --- app/views/admin/poll/questions/show.html.erb | 48 +++++++++++--------- config/locales/en/admin.yml | 4 +- config/locales/es/admin.yml | 5 +- config/locales/fr/admin.yml | 10 ++-- 4 files changed, 40 insertions(+), 27 deletions(-) diff --git a/app/views/admin/poll/questions/show.html.erb b/app/views/admin/poll/questions/show.html.erb index 7037afd5f..1cde20f5c 100644 --- a/app/views/admin/poll/questions/show.html.erb +++ b/app/views/admin/poll/questions/show.html.erb @@ -24,29 +24,35 @@ <%= link_to @question.author.name, user_path(@question.author) %>

- - - - - +
- <%= t('admin.questions.show.valid_answers') %> - - <%= link_to t("admin.questions.show.add_answer"), - new_admin_question_answer_path(@question), - class: "button hollow float-right" %> -
+ + + + + - - - - + + + + + + - <% @question.question_answers.each do |answer| %> - - - - - <% end %> + + <% @question.question_answers.each do |answer| %> + + + + + + <% end %> +
+ <%= t('admin.questions.show.valid_answers') %> + + <%= link_to t("admin.questions.show.add_answer"), + new_admin_question_answer_path(@question), + class: "button hollow float-right" %> +
<%= t("admin.questions.show.answers.title") %><%= t("admin.questions.show.answers.description") %>
<%= t("admin.questions.show.answers.title") %><%= t("admin.questions.show.answers.description") %><%= t("admin.questions.show.answers.videos") %>
<%= answer.title %><%= answer.description %>
<%= answer.title %><%= answer.description %><%= link_to t("admin.questions.show.answers.video_list", count: 0), "#" %>
<% if @question.video_url.present? %> diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 8202695f1..e28c7f40b 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -592,12 +592,14 @@ en: author: Author title: Title valid_answers: Valid answers - add_answer: "Add answer" + add_answer: Add answer video_url: External video documents: Documents (1) answers: title: Answer description: Description + videos: Videos + video_list: Video list (%{count}) answers: new: title: "New answer" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 3ff3abcb5..f025437cf 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -592,14 +592,15 @@ es: author: Autor title: Título valid_answers: Respuestas válidas - add_answer: "Añadir respuesta" - description: Descripción + add_answer: Añadir respuesta video_url: Video externo documents: Documentos (1) preview: Ver en la web answers: title: Respuesta description: Descripción + videos: Vídeos + video_list: Lista de vídeos (%{count}) answers: new: title: "Nueva respuesta" diff --git a/config/locales/fr/admin.yml b/config/locales/fr/admin.yml index e000c8a28..0217c9217 100644 --- a/config/locales/fr/admin.yml +++ b/config/locales/fr/admin.yml @@ -382,10 +382,14 @@ fr: author: Auteur title: Titre valid_answers: Réponses valides - add_answer: "Ajouter une réponse" - answer: "Réponse" - description: Description + add_answer: Ajouter une réponse + documents: Documents (1) preview: Voir l'aperçu + answers: + title: Réponse + description: Description + videos: Vidéos + video_list: Liste des vidéos (%{count}) answers: new: title: "Nouvelle réponse" From 32f3b643b009bda6e4c8bb654aa9d6a855967451 Mon Sep 17 00:00:00 2001 From: Angel Perez Date: Wed, 4 Oct 2017 17:25:51 -0400 Subject: [PATCH 03/91] Create 'poll_question_answer_videos' table and model --- app/models/poll/question/answer.rb | 1 + app/models/poll/question/answer/video.rb | 16 ++++++++++++++++ ...4210108_create_poll_question_answer_videos.rb | 11 +++++++++++ db/schema.rb | 11 ++++++++++- 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 app/models/poll/question/answer/video.rb create mode 100644 db/migrate/20171004210108_create_poll_question_answer_videos.rb diff --git a/app/models/poll/question/answer.rb b/app/models/poll/question/answer.rb index 3f8f4a172..cb43e2d44 100644 --- a/app/models/poll/question/answer.rb +++ b/app/models/poll/question/answer.rb @@ -1,5 +1,6 @@ class Poll::Question::Answer < ActiveRecord::Base belongs_to :question, class_name: 'Poll::Question', foreign_key: 'question_id' + has_many :videos, class_name: 'Poll::Question::Answer::Video' validates :title, presence: true diff --git a/app/models/poll/question/answer/video.rb b/app/models/poll/question/answer/video.rb new file mode 100644 index 000000000..3d214af96 --- /dev/null +++ b/app/models/poll/question/answer/video.rb @@ -0,0 +1,16 @@ +class Poll::Question::Answer::Video < ActiveRecord::Base + belongs_to :answer, class_name: 'Poll::Question::Answer', foreign_key: 'answer_id' + + VIMEO_REGEX = /vimeo.*(staffpicks\/|channels\/|videos\/|video\/|\/)([^#\&\?]*).*/ + YOUTUBE_REGEX = /youtu.*(be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/ + + validates :title, presence: true + validate :valid_url? + + def valid_url? + return if url.blank? + return if url.match(VIMEO_REGEX) + return if url.match(YOUTUBE_REGEX) + errors.add(:url, :invalid) + end +end diff --git a/db/migrate/20171004210108_create_poll_question_answer_videos.rb b/db/migrate/20171004210108_create_poll_question_answer_videos.rb new file mode 100644 index 000000000..7cce33b29 --- /dev/null +++ b/db/migrate/20171004210108_create_poll_question_answer_videos.rb @@ -0,0 +1,11 @@ +class CreatePollQuestionAnswerVideos < ActiveRecord::Migration + def change + create_table :poll_question_answer_videos do |t| + t.string :title + t.string :url + t.integer :answer_id, index: true + end + + add_foreign_key :poll_question_answer_videos, :poll_question_answers, column: :answer_id + end +end diff --git a/db/schema.rb b/db/schema.rb index dbbd3ec46..22e362a1f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171004151553) do +ActiveRecord::Schema.define(version: 20171004210108) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -668,6 +668,14 @@ ActiveRecord::Schema.define(version: 20171004151553) do add_index "poll_partial_results", ["origin"], name: "index_poll_partial_results_on_origin", using: :btree add_index "poll_partial_results", ["question_id"], name: "index_poll_partial_results_on_question_id", using: :btree + create_table "poll_question_answer_videos", force: :cascade do |t| + t.string "title" + t.string "url" + t.integer "answer_id" + end + + add_index "poll_question_answer_videos", ["answer_id"], name: "index_poll_question_answer_videos_on_answer_id", using: :btree + create_table "poll_question_answers", force: :cascade do |t| t.string "title" t.text "description" @@ -1152,6 +1160,7 @@ ActiveRecord::Schema.define(version: 20171004151553) do add_foreign_key "poll_partial_results", "poll_officer_assignments", column: "officer_assignment_id" add_foreign_key "poll_partial_results", "poll_questions", column: "question_id" add_foreign_key "poll_partial_results", "users", column: "author_id" + add_foreign_key "poll_question_answer_videos", "poll_question_answers", column: "answer_id" add_foreign_key "poll_question_answers", "poll_questions", column: "question_id" add_foreign_key "poll_questions", "polls" add_foreign_key "poll_questions", "proposals" From 5b129b933fc2cb3428ad58e3cd79debfb504ec5f Mon Sep 17 00:00:00 2001 From: iagirre Date: Thu, 5 Oct 2017 13:38:19 +0200 Subject: [PATCH 04/91] Removed documents from questions (documentable from model and uploader from _form in views) --- app/models/poll/question.rb | 5 ----- app/views/admin/poll/questions/_form.html.erb | 4 ---- 2 files changed, 9 deletions(-) diff --git a/app/models/poll/question.rb b/app/models/poll/question.rb index 1e94e0180..e6ef482a9 100644 --- a/app/models/poll/question.rb +++ b/app/models/poll/question.rb @@ -1,11 +1,6 @@ class Poll::Question < ActiveRecord::Base include Measurable include Searchable - include Documentable - documentable max_documents_allowed: 1, - max_file_size: 3.megabytes, - accepted_content_types: [ "application/pdf" ] - accepts_nested_attributes_for :documents, allow_destroy: true acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases diff --git a/app/views/admin/poll/questions/_form.html.erb b/app/views/admin/poll/questions/_form.html.erb index 56b7ec93f..d97e498f6 100644 --- a/app/views/admin/poll/questions/_form.html.erb +++ b/app/views/admin/poll/questions/_form.html.erb @@ -16,10 +16,6 @@ <%= f.text_field :title, maxlength: Poll::Question.title_max_length %> -
- <%= render 'documents/nested_documents', documentable: @question, f: f %> -
-
<%= f.label :video_url, t("proposals.form.proposal_video_url") %>

<%= t("proposals.form.proposal_video_url_note") %>

From ab09bde7dd3481be9071f0c2bd9e865a2fbb9405 Mon Sep 17 00:00:00 2001 From: Angel Perez Date: Thu, 5 Oct 2017 08:11:15 -0400 Subject: [PATCH 05/91] Fix broken translations for Poll::Question::Answer model Poll::QuestionAnswer model was renamed to Poll::Question::Answer which made the previous I18n keys unavailable for the views See PR #1977, commit 461410a --- config/locales/en/activerecord.yml | 2 +- config/locales/es/activerecord.yml | 2 +- config/locales/fr/activerecord.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/locales/en/activerecord.yml b/config/locales/en/activerecord.yml index 5ef1917d3..6a6e2ad85 100644 --- a/config/locales/en/activerecord.yml +++ b/config/locales/en/activerecord.yml @@ -213,7 +213,7 @@ en: image: title: Title attachment: Attachment - poll/question_answer: + poll/question/answer: title: "Answer" description: "Description" errors: diff --git a/config/locales/es/activerecord.yml b/config/locales/es/activerecord.yml index 9b3260680..9b83d9516 100644 --- a/config/locales/es/activerecord.yml +++ b/config/locales/es/activerecord.yml @@ -207,7 +207,7 @@ es: image: title: Título attachment: Archivo adjunto - poll/question_answer: + poll/question/answer: title: "Respuesta" description: "Descripción" errors: diff --git a/config/locales/fr/activerecord.yml b/config/locales/fr/activerecord.yml index d6ab5db80..5c6117d31 100644 --- a/config/locales/fr/activerecord.yml +++ b/config/locales/fr/activerecord.yml @@ -147,7 +147,7 @@ fr: name: Nom locale: Langue body: Contenu - poll/question_answer: + poll/question/answer: title: "Réponse" description: "Description" errors: From 75d841e2fe4da632c901ab2b745aba3bd1b2ee68 Mon Sep 17 00:00:00 2001 From: iagirre Date: Thu, 5 Oct 2017 15:31:21 +0200 Subject: [PATCH 06/91] Fixed the correct specs and views to make the test pass. --- app/views/admin/poll/questions/show.html.erb | 8 -------- spec/features/admin/poll/questions_spec.rb | 18 ------------------ 2 files changed, 26 deletions(-) diff --git a/app/views/admin/poll/questions/show.html.erb b/app/views/admin/poll/questions/show.html.erb index 7037afd5f..959cc0fd4 100644 --- a/app/views/admin/poll/questions/show.html.erb +++ b/app/views/admin/poll/questions/show.html.erb @@ -56,13 +56,5 @@ <%= @question.video_url %>

<% end %> - - <% if @question.documents.any? %> -

- <%= t("admin.questions.show.documents") %> -
- <%= @question.documents.first.title %> -

- <% end %>
diff --git a/spec/features/admin/poll/questions_spec.rb b/spec/features/admin/poll/questions_spec.rb index 7e103c647..5c8cba9c1 100644 --- a/spec/features/admin/poll/questions_spec.rb +++ b/spec/features/admin/poll/questions_spec.rb @@ -111,22 +111,4 @@ feature 'Admin poll questions' do pending "Mark all city by default when creating a poll question from a successful proposal" - it_behaves_like "nested documentable", - "administrator", - "poll_question", - "new_admin_question_path", - { }, - "documentable_fill_new_valid_poll_question", - "Save", - "Star Wars: Episode IV - A New Hope" - - it_behaves_like "nested documentable", - "administrator", - "poll_question", - "edit_admin_question_path", - { "id": "id" }, - nil, - "Save", - "Changes saved" - end From 82cf1fc28526133c4c3a0d425c4ddb8219125ae0 Mon Sep 17 00:00:00 2001 From: iagirre Date: Thu, 5 Oct 2017 15:55:37 +0200 Subject: [PATCH 07/91] Remove unused i18n-keys: admin.questions.show.documents, value: Documents(1) (en and es) --- config/locales/en/admin.yml | 1 - config/locales/es/admin.yml | 1 - 2 files changed, 2 deletions(-) diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 8202695f1..6446c0d05 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -594,7 +594,6 @@ en: valid_answers: Valid answers add_answer: "Add answer" video_url: External video - documents: Documents (1) answers: title: Answer description: Description diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 3ff3abcb5..1d5f6b86d 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -595,7 +595,6 @@ es: add_answer: "Añadir respuesta" description: Descripción video_url: Video externo - documents: Documentos (1) preview: Ver en la web answers: title: Respuesta From 5f6d218a15542b8a213e099881fae49e557f5073 Mon Sep 17 00:00:00 2001 From: Angel Perez Date: Thu, 5 Oct 2017 10:32:09 -0400 Subject: [PATCH 08/91] Rename param in Admin::Poll::Questions::AnswersController 'poll_question_id' attribute was renamed to 'question_id' on PR #1977, commit 4aaf681 --- app/controllers/admin/poll/questions/answers_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/admin/poll/questions/answers_controller.rb b/app/controllers/admin/poll/questions/answers_controller.rb index d0a7c4cc7..660339844 100644 --- a/app/controllers/admin/poll/questions/answers_controller.rb +++ b/app/controllers/admin/poll/questions/answers_controller.rb @@ -21,7 +21,7 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController private def answer_params - params.require(:poll_question_answer).permit(:title, :description, :poll_question_id) + params.require(:poll_question_answer).permit(:title, :description, :question_id) end def load_question From b31abb64d75a8028f75eedf2999b2084f961c563 Mon Sep 17 00:00:00 2001 From: iagirre Date: Thu, 5 Oct 2017 17:28:24 +0200 Subject: [PATCH 09/91] Removed the methods not used from nested_documentable specs (the ones that were deleted in the questions specs) and removed also the document params from questions_params (not used anymore). --- app/controllers/admin/poll/questions_controller.rb | 3 +-- spec/shared/features/nested_documentable.rb | 8 +------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/app/controllers/admin/poll/questions_controller.rb b/app/controllers/admin/poll/questions_controller.rb index 107c06740..5cf587735 100644 --- a/app/controllers/admin/poll/questions_controller.rb +++ b/app/controllers/admin/poll/questions_controller.rb @@ -56,8 +56,7 @@ class Admin::Poll::QuestionsController < Admin::Poll::BaseController private def question_params - params.require(:poll_question).permit(:poll_id, :title, :question, :proposal_id, :valid_answers, :video_url, - documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]) + params.require(:poll_question).permit(:poll_id, :title, :question, :proposal_id, :valid_answers, :video_url) end def search_params diff --git a/spec/shared/features/nested_documentable.rb b/spec/shared/features/nested_documentable.rb index 8780936a7..255f018e5 100644 --- a/spec/shared/features/nested_documentable.rb +++ b/spec/shared/features/nested_documentable.rb @@ -263,7 +263,6 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na end - end end @@ -275,7 +274,7 @@ rescue return end -def documentable_attach_new_file(documentable_factory_name, index, path, success = true) +def documentable_attach_new_file(_documentable_factory_name, index, path, success = true) click_link "Add new document" document = all(".document")[index] document_input = document.find("input[type=file]", visible: false) @@ -318,8 +317,3 @@ def documentable_fill_new_valid_budget_investment fill_in_ckeditor "budget_investment_description", with: "Budget investment description" check :budget_investment_terms_of_service end - -def documentable_fill_new_valid_poll_question - page.select documentable.poll.name, from: 'poll_question_poll_id' - fill_in 'poll_question_title', with: "Star Wars: Episode IV - A New Hope" -end From 5862eea516c2cb03bb11e29c04952b0b3b1b1908 Mon Sep 17 00:00:00 2001 From: Angel Perez Date: Thu, 5 Oct 2017 12:34:20 -0400 Subject: [PATCH 10/91] Add controllers/views for Poll::Question::Answer::Video --- .../questions/answers/videos_controller.rb | 57 +++++++++++++++++++ .../questions/answers/videos/_form.html.erb | 21 +++++++ .../questions/answers/videos/edit.html.erb | 9 +++ .../questions/answers/videos/index.html.erb | 47 +++++++++++++++ .../questions/answers/videos/new.html.erb | 9 +++ app/views/admin/poll/questions/show.html.erb | 16 +++--- config/locales/en/activerecord.yml | 3 + config/locales/en/admin.yml | 12 +++- config/locales/en/responders.yml | 2 + config/locales/es/activerecord.yml | 3 + config/locales/es/admin.yml | 10 ++++ config/locales/es/responders.yml | 2 + config/locales/fr/activerecord.yml | 3 + config/locales/fr/admin.yml | 10 ++++ config/locales/fr/responders.yml | 3 + config/routes.rb | 6 +- .../questions/answers/videos/videos_spec.rb | 33 +++++++++++ 17 files changed, 236 insertions(+), 10 deletions(-) create mode 100644 app/controllers/admin/poll/questions/answers/videos_controller.rb create mode 100644 app/views/admin/poll/questions/answers/videos/_form.html.erb create mode 100644 app/views/admin/poll/questions/answers/videos/edit.html.erb create mode 100644 app/views/admin/poll/questions/answers/videos/index.html.erb create mode 100644 app/views/admin/poll/questions/answers/videos/new.html.erb create mode 100644 spec/features/admin/poll/questions/answers/videos/videos_spec.rb diff --git a/app/controllers/admin/poll/questions/answers/videos_controller.rb b/app/controllers/admin/poll/questions/answers/videos_controller.rb new file mode 100644 index 000000000..a231c1a20 --- /dev/null +++ b/app/controllers/admin/poll/questions/answers/videos_controller.rb @@ -0,0 +1,57 @@ +class Admin::Poll::Questions::Answers::VideosController < Admin::Poll::BaseController + before_action :load_answer, only: [:index, :new, :create] + before_action :load_video, only: [:edit, :update, :destroy] + + def index + end + + def new + @video = ::Poll::Question::Answer::Video.new + end + + def create + @video = ::Poll::Question::Answer::Video.new(video_params) + + if @video.save + redirect_to admin_answer_videos_path(@answer), + notice: t("flash.actions.create.poll_question_answer_video") + else + render :new + end + end + + def edit + end + + def update + if @video.update(video_params) + redirect_to admin_answer_videos_path(@video.answer_id), + notice: t("flash.actions.save_changes.notice") + else + render :edit + end + end + + def destroy + if @video.destroy + notice = t("flash.actions.destroy.poll_question_answer_video") + else + notice = t("flash.actions.destroy.error") + end + redirect_to :back, notice: notice + end + + private + + def video_params + params.require(:poll_question_answer_video).permit(:title, :url, :answer_id) + end + + def load_answer + @answer = ::Poll::Question::Answer.find(params[:answer_id]) + end + + def load_video + @video = ::Poll::Question::Answer::Video.find(params[:id]) + end +end diff --git a/app/views/admin/poll/questions/answers/videos/_form.html.erb b/app/views/admin/poll/questions/answers/videos/_form.html.erb new file mode 100644 index 000000000..28035c397 --- /dev/null +++ b/app/views/admin/poll/questions/answers/videos/_form.html.erb @@ -0,0 +1,21 @@ +<%= form_for(@video, url: form_url) do |f| %> + + <%= render 'shared/errors', resource: @video %> + + <%= f.hidden_field :answer_id, value: @video.answer_id || @answer.id %> + +
+
+ + <%= f.text_field :title %> + <%= f.text_field :url %> + +
+
+ <%= f.submit(class: "button expanded", value: t("shared.save")) %> +
+
+ +
+
+<% end %> diff --git a/app/views/admin/poll/questions/answers/videos/edit.html.erb b/app/views/admin/poll/questions/answers/videos/edit.html.erb new file mode 100644 index 000000000..31b59c2dd --- /dev/null +++ b/app/views/admin/poll/questions/answers/videos/edit.html.erb @@ -0,0 +1,9 @@ +<%= back_link_to %> + +

+ <%= t("admin.answers.videos.edit.title") %> +

+ +
+ <%= render "form", form_url: admin_video_path(@video) %> +
diff --git a/app/views/admin/poll/questions/answers/videos/index.html.erb b/app/views/admin/poll/questions/answers/videos/index.html.erb new file mode 100644 index 000000000..0ea64c570 --- /dev/null +++ b/app/views/admin/poll/questions/answers/videos/index.html.erb @@ -0,0 +1,47 @@ +<%= back_link_to admin_question_path(@answer.question_id) %> + +
+ +

+ <%= t("admin.answers.videos.index.title") %> +

+ +<%= link_to t("admin.answers.videos.index.add_video"), + new_admin_answer_video_path, + class: "button success float-right" %> + +
+ + + + + + + + + + + + <% @answer.videos.each do |video| %> + + + + + + <% end %> + +
<%= t("admin.answers.videos.index.video_title") %><%= t("admin.answers.videos.index.video_url") %> + <%= t("admin.actions.actions") %> +
<%= video.title %><%= link_to "#{video.url}", video.url %> + + <%= link_to t("shared.edit"), + edit_admin_video_path(video), + class: "button hollow" %> + + <%= link_to t("shared.delete"), + admin_video_path(video), + class: "button hollow alert", + method: :delete %> +
+ +
diff --git a/app/views/admin/poll/questions/answers/videos/new.html.erb b/app/views/admin/poll/questions/answers/videos/new.html.erb new file mode 100644 index 000000000..d114b9104 --- /dev/null +++ b/app/views/admin/poll/questions/answers/videos/new.html.erb @@ -0,0 +1,9 @@ +<%= back_link_to admin_answer_videos_path(@answer) %> + +

+ <%= t('admin.answers.videos.new.title') %> +

+ +
+ <%= render "form", form_url: admin_answer_videos_path %> +
diff --git a/app/views/admin/poll/questions/show.html.erb b/app/views/admin/poll/questions/show.html.erb index 1cde20f5c..84a07622f 100644 --- a/app/views/admin/poll/questions/show.html.erb +++ b/app/views/admin/poll/questions/show.html.erb @@ -24,13 +24,13 @@ <%= link_to @question.author.name, user_path(@question.author) %>

- +
- - - - - + + + @@ -49,7 +49,9 @@ - + <% end %> diff --git a/config/locales/en/activerecord.yml b/config/locales/en/activerecord.yml index 6a6e2ad85..f6b6be383 100644 --- a/config/locales/en/activerecord.yml +++ b/config/locales/en/activerecord.yml @@ -216,6 +216,9 @@ en: poll/question/answer: title: "Answer" description: "Description" + poll/question/answer/video: + title: Title + url: External video errors: models: user: diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index e28c7f40b..981eca84e 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -602,7 +602,17 @@ en: video_list: Video list (%{count}) answers: new: - title: "New answer" + title: New answer + videos: + index: + title: Videos + add_video: Add video + video_title: Title + video_url: External video + new: + title: New video + edit: + title: Edit video recounts: index: title: "Recounts" diff --git a/config/locales/en/responders.yml b/config/locales/en/responders.yml index fd187c495..88f68a955 100644 --- a/config/locales/en/responders.yml +++ b/config/locales/en/responders.yml @@ -9,6 +9,7 @@ en: poll: "Poll created successfully." poll_booth: "Booth created successfully." poll_question_answer: "Answer created successfully" + poll_question_answer_video: "Video created successfully" proposal: "Proposal created successfully." proposal_notification: "Your message has been sent correctly." spending_proposal: "Spending proposal created successfully. You can access it from %{activity}" @@ -31,3 +32,4 @@ en: budget_investment: "Investment project deleted succesfully." error: "Could not delete" topic: "Topic deleted successfully." + poll_question_answer_video: "Answer video deleted successfully." diff --git a/config/locales/es/activerecord.yml b/config/locales/es/activerecord.yml index 9b83d9516..d04eb72da 100644 --- a/config/locales/es/activerecord.yml +++ b/config/locales/es/activerecord.yml @@ -210,6 +210,9 @@ es: poll/question/answer: title: "Respuesta" description: "Descripción" + poll/question/answer/video: + title: Título + url: Vídeo externo errors: models: user: diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index f025437cf..f57c4fbea 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -606,6 +606,16 @@ es: title: "Nueva respuesta" video_url: Video externo documents: Documentos (1) + videos: + index: + title: Vídeos + add_video: Añadir vídeo + video_title: Título + video_url: External video + new: + title: Nuevo video + edit: + title: Editar vídeo recounts: index: title: "Recuentos" diff --git a/config/locales/es/responders.yml b/config/locales/es/responders.yml index a35387ff3..01f19d96e 100644 --- a/config/locales/es/responders.yml +++ b/config/locales/es/responders.yml @@ -9,6 +9,7 @@ es: poll: "Votación creada correctamente." poll_booth: "Urna creada correctamente." poll_question_answer: "Respuesta creada correctamente" + poll_question_answer_video: "Vídeo creado correctamente" proposal: "Propuesta creada correctamente." proposal_notification: "Tu message ha sido enviado correctamente." spending_proposal: "Propuesta de inversión creada correctamente. Puedes acceder a ella desde %{activity}" @@ -31,3 +32,4 @@ es: budget_investment: "Propuesta de inversión eliminada." error: "No se pudo borrar" topic: "Tema eliminado." + poll_question_answer_video: "Vídeo de respuesta eliminado." diff --git a/config/locales/fr/activerecord.yml b/config/locales/fr/activerecord.yml index 5c6117d31..bd8acfd50 100644 --- a/config/locales/fr/activerecord.yml +++ b/config/locales/fr/activerecord.yml @@ -150,6 +150,9 @@ fr: poll/question/answer: title: "Réponse" description: "Description" + poll/question/answer/video: + title: Titre + url: Vidéo externe errors: models: user: diff --git a/config/locales/fr/admin.yml b/config/locales/fr/admin.yml index 0217c9217..ba29e068b 100644 --- a/config/locales/fr/admin.yml +++ b/config/locales/fr/admin.yml @@ -393,6 +393,16 @@ fr: answers: new: title: "Nouvelle réponse" + videos: + index: + title: Vidéos + add_video: Ajouter une vidéo + video_title: Titre + video_url: Vidéo externe + new: + title: Nouveau vidéo + edit: + title: Modifier la vidéo recounts: index: title: "Dépouillements" diff --git a/config/locales/fr/responders.yml b/config/locales/fr/responders.yml index 9897e3455..1d1cfae0c 100644 --- a/config/locales/fr/responders.yml +++ b/config/locales/fr/responders.yml @@ -8,6 +8,8 @@ fr: direct_message: "Votre message a été envoyé avec succès." poll: "Vote créé avec succès." poll_booth: "Urne créée avec succès." + poll_question_answer: "Réponse créée avec succès" + poll_question_answer_video: "Vidéo créée avec succès" proposal: "Proposition créée avec succès." proposal_notification: "Votre message a correctement été envoyé." spending_proposal: "Proposition de dépense créée avec succès. Vous pouvez y accéder depuis %{activity}" @@ -27,3 +29,4 @@ fr: spending_proposal: "Proposition de dépense supprimée avec succès." budget_investment: "Budget d'investissement supprimé avec succès." error: "Suppression impossible" + poll_question_answer_video: "Réponse vidéo supprimée avec succès." diff --git a/config/routes.rb b/config/routes.rb index 89691feac..1428dc4fa 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -300,8 +300,10 @@ Rails.application.routes.draw do end end - resources :questions do - resources :answers, only: [:new, :create], controller: 'questions/answers' + resources :questions, shallow: true do + resources :answers, only: [:new, :create], controller: 'questions/answers' do + resources :videos, controller: 'questions/answers/videos' + end end end diff --git a/spec/features/admin/poll/questions/answers/videos/videos_spec.rb b/spec/features/admin/poll/questions/answers/videos/videos_spec.rb new file mode 100644 index 000000000..ee04ce128 --- /dev/null +++ b/spec/features/admin/poll/questions/answers/videos/videos_spec.rb @@ -0,0 +1,33 @@ +require 'rails_helper' + +feature 'Videos' do + + background do + admin = create(:administrator) + login_as(admin.user) + end + + scenario "Create" do + question = create(:poll_question) + answer = create(:poll_question_answer, question: question) + video_title = "'Magical' by Junko Ohashi" + video_url = "https://www.youtube.com/watch?v=-JMf43st-1A" + + visit admin_question_path(question) + + within("#poll_question_answer_#{answer.id}") do + click_link "Video list (#{answer.videos.count})" + end + + click_link "Add video" + + fill_in 'poll_question_answer_video_title', with: video_title + fill_in 'poll_question_answer_video_url', with: video_url + + click_button "Save" + + expect(page).to have_content(video_title) + expect(page).to have_content(video_url) + end + +end From 0cf5299846ce095a2cae958532949019ba570009 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Fri, 6 Oct 2017 00:04:25 +0200 Subject: [PATCH 11/91] Set voting messages --- app/views/polls/questions/_answers.html.erb | 4 ++-- app/views/polls/show.html.erb | 5 +++++ config/locales/en/general.yml | 3 ++- config/locales/es/general.yml | 3 ++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/views/polls/questions/_answers.html.erb b/app/views/polls/questions/_answers.html.erb index 2bef6de72..ccc9f0322 100644 --- a/app/views/polls/questions/_answers.html.erb +++ b/app/views/polls/questions/_answers.html.erb @@ -2,8 +2,8 @@ <% if can? :answer, question %> <% question.question_answers.each do |answer| %> <% if @answers_by_question_id[question.id] == answer.title %> - "> + "> <%= answer.title %> <% else %> diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index b3a78e402..894899a72 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -38,6 +38,11 @@ <%= t("polls.show.already_voted_in_booth") %> <% else %> + <% if current_user && !@poll.votable_by?(current_user) %> +
+ <%= t("polls.show.already_voted_in_web") %> +
+ <% end %> <% @questions.each do |question| %> <%= render 'polls/questions/question', question: question %> <% end %> diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index 1796049eb..473ac7391 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -481,7 +481,8 @@ en: help_text_1: "Voting takes place when a citizen proposal supports reaches 1% of the census with voting rights. Voting can also include questions that the City Council ask to the citizens decision." help_text_2: "To participate in the next vote you have to sign up on %{org} and verify your account. All registered voters in the city over 16 years old can vote. The results of all votes are binding on the government." show: - already_voted_in_booth: "You have already participated in a booth for this poll." + already_voted_in_booth: "You have already participated in a physical booth. You can not participate again." + already_voted_in_web: "You have already participated in this poll. If you vote again it will be overwritten." back: Back to voting cant_answer_not_logged_in: "You must %{signin} or %{signup} to participate." signin: Sign in diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index d5997e746..0af33da1d 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -481,7 +481,8 @@ es: help_text_1: "Las votaciones se convocan cuando una propuesta ciudadana alcanza el 1% de apoyos del censo con derecho a voto. En las votaciones también se pueden incluir cuestiones que el Ayuntamiento somete a decisión directa de la ciudadanía." help_text_2: "Para participar en la próxima votación tienes que registrarte en %{org} y verificar tu cuenta. Pueden votar todas las personas empadronadas en la ciudad mayores de 16 años. Los resultados de todas las votaciones serán vinculantes para el gobierno." show: - already_voted_in_booth: "Ya has participado en esta votación en una urna." + already_voted_in_booth: "Ya has participado en esta votación en urnas presenciales, no puedes volver a participar." + already_voted_in_web: "Ya has participado en esta votación. Si vuelves a votar se sobreescribirá tu resultado anterior." back: Volver a votaciones cant_answer_not_logged_in: "Necesitas %{signin} o %{signup} para participar." signin: iniciar sesión From 6192ea8b780e46b1e5711bb278ef20602b7c2887 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Thu, 5 Oct 2017 15:19:09 +0200 Subject: [PATCH 12/91] Added documents to Poll::Question::Answer --- app/models/poll/question/answer.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/models/poll/question/answer.rb b/app/models/poll/question/answer.rb index 1746c480c..e1da38fe8 100644 --- a/app/models/poll/question/answer.rb +++ b/app/models/poll/question/answer.rb @@ -1,5 +1,10 @@ class Poll::Question::Answer < ActiveRecord::Base include Galleryable + include Documentable + documentable max_documents_allowed: 3, + max_file_size: 3.megabytes, + accepted_content_types: [ "application/pdf" ] + accepts_nested_attributes_for :documents, allow_destroy: true belongs_to :question, class_name: 'Poll::Question', foreign_key: 'question_id' From 590344a576fb777be429709925738ffff76ac3f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Thu, 5 Oct 2017 15:20:09 +0200 Subject: [PATCH 13/91] Added view to upload documents to poll answers --- .../poll/questions/answers_controller.rb | 21 +++++++- .../poll/questions/answers/documents.html.erb | 51 +++++++++++++++++++ config/routes.rb | 4 +- 3 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 app/views/admin/poll/questions/answers/documents.html.erb diff --git a/app/controllers/admin/poll/questions/answers_controller.rb b/app/controllers/admin/poll/questions/answers_controller.rb index 660339844..9223e65d4 100644 --- a/app/controllers/admin/poll/questions/answers_controller.rb +++ b/app/controllers/admin/poll/questions/answers_controller.rb @@ -1,5 +1,6 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController before_action :load_question + before_action :load_answer, only: [:update, :documents] load_and_authorize_resource :question, class: "::Poll::Question" @@ -18,10 +19,28 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController end end + def update + if @answer.update(answer_params) + redirect_to admin_question_path(@question), notice: t("flash.actions.save_changes.notice") + else + redirect_to :back + end + end + + def documents + @documents = @answer.documents + + render 'admin/poll/questions/answers/documents' + end + private def answer_params - params.require(:poll_question_answer).permit(:title, :description, :question_id) + params.require(:poll_question_answer).permit(:title, :description, :question_id, documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]) + end + + def load_answer + @answer = ::Poll::Question::Answer.find(params[:id] || params[:answer_id]) end def load_question diff --git a/app/views/admin/poll/questions/answers/documents.html.erb b/app/views/admin/poll/questions/answers/documents.html.erb new file mode 100644 index 000000000..17c6f52a3 --- /dev/null +++ b/app/views/admin/poll/questions/answers/documents.html.erb @@ -0,0 +1,51 @@ +

<%= link_to @question.title, admin_question_path(@question) %> > <%= @answer.title %>

+ + +

<%= t("admin.questions.show.answers.documents_list") %>

+ +
+ <%= form_for(@answer, url: admin_question_answer_path(@question, @answer)) do |f| %> + + <%= render 'shared/errors', resource: @answer %> + + <%= f.hidden_field :question_id, value: @question.id %> + +
+
+
+ <%= render 'documents/nested_documents', documentable: @answer, f: f %> +
+ +
+
+ <%= f.submit(class: "button expanded", value: t("shared.save")) %> +
+
+
+
+ <% end %> + + <% if @answer.documents.present? %> +
+ <%= t('admin.questions.show.valid_answers') %> + <%= link_to t("admin.questions.show.add_answer"), new_admin_question_answer_path(@question), class: "button hollow float-right" %> @@ -38,9 +38,9 @@
<%= t("admin.questions.show.answers.title") %><%= t("admin.questions.show.answers.description") %><%= t("admin.questions.show.answers.videos") %><%= t("admin.questions.show.answers.title") %><%= t("admin.questions.show.answers.description") %><%= t("admin.questions.show.answers.videos") %>
<%= answer.title %> <%= answer.description %><%= link_to t("admin.questions.show.answers.video_list", count: 0), "#" %><%= link_to t("admin.questions.show.answers.video_list", + count: answer.videos.count), + admin_answer_videos_path(answer) %>
+ + + + + + <% @answer.documents.each do |document| %> + + + + + <% end %> +
<%= t("admin.questions.show.answers.document_title") %><%= t("admin.questions.show.answers.description") %>
+ <%= link_to document.title, document.attachment.url %> + + <%= link_to t('documents.buttons.download_document'), + document.attachment.url, + target: "_blank", + rel: "nofollow", + class: 'button hollow' %> +
+ <% end %> + diff --git a/config/routes.rb b/config/routes.rb index 387983d4b..57f79f115 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -301,10 +301,10 @@ Rails.application.routes.draw do end resources :questions do - resources :answers, only: [:new, :create], controller: 'questions/answers', shallow: true do + resources :answers, only: [:new, :create, :update], controller: 'questions/answers', shallow: true do resources :images, controller: 'questions/answers/images' + get :documents, to: 'questions/answers#documents' end - end end From c3f778bbdde2bc5c1c115e589d69142221cde40a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Fri, 6 Oct 2017 01:18:56 +0200 Subject: [PATCH 14/91] Check if user has voted before sign in --- app/helpers/polls_helper.rb | 4 ++++ app/views/polls/questions/_answers.html.erb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index 27d33ea04..a676084cb 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -41,4 +41,8 @@ module PollsHelper booth.name + location end + def voted_before_sign_in(question) + current_user.current_sign_in_at >= question.poll.voters.find_by_user_id(current_user).updated_at + end + end diff --git a/app/views/polls/questions/_answers.html.erb b/app/views/polls/questions/_answers.html.erb index ccc9f0322..7fb4a5d71 100644 --- a/app/views/polls/questions/_answers.html.erb +++ b/app/views/polls/questions/_answers.html.erb @@ -1,7 +1,7 @@
<% if can? :answer, question %> <% question.question_answers.each do |answer| %> - <% if @answers_by_question_id[question.id] == answer.title %> + <% if @answers_by_question_id[question.id] == answer.title && !voted_before_sign_in(question) %> "> <%= answer.title %> From 284fdea2e6aed813eaf16ddfd569e0ebb0ee3f84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Thu, 5 Oct 2017 15:41:55 +0200 Subject: [PATCH 15/91] Improved answer documents and question summary views --- .../poll/questions/answers/documents.html.erb | 5 +++-- app/views/admin/poll/questions/show.html.erb | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/app/views/admin/poll/questions/answers/documents.html.erb b/app/views/admin/poll/questions/answers/documents.html.erb index 17c6f52a3..28b55a2a3 100644 --- a/app/views/admin/poll/questions/answers/documents.html.erb +++ b/app/views/admin/poll/questions/answers/documents.html.erb @@ -1,8 +1,9 @@ -

<%= link_to @question.title, admin_question_path(@question) %> > <%= @answer.title %>

- +<%= back_link_to %>

<%= t("admin.questions.show.answers.documents_list") %>

+

<%= link_to @question.poll.name, admin_poll_path(@question.poll) %> > <%= link_to @question.title, admin_question_path(@question) %> > <%= @answer.title %>

+
<%= form_for(@answer, url: admin_question_answer_path(@question, @answer)) do |f| %> diff --git a/app/views/admin/poll/questions/show.html.erb b/app/views/admin/poll/questions/show.html.erb index 64c30de1e..0a89bf915 100644 --- a/app/views/admin/poll/questions/show.html.erb +++ b/app/views/admin/poll/questions/show.html.erb @@ -31,7 +31,7 @@ - - - + + + <% @question.question_answers.each do |answer| %> @@ -50,10 +51,17 @@ + <% end %>
+ <%= t('admin.questions.show.valid_answers') %> <%= link_to t("admin.questions.show.add_answer"), new_admin_question_answer_path(@question), @@ -41,8 +41,9 @@
<%= t("admin.questions.show.answers.title") %><%= t("admin.questions.show.answers.description") %><%= t("admin.questions.show.answers.images") %><%= t("admin.questions.show.answers.description") %><%= t("admin.questions.show.answers.images") %><%= t("admin.questions.show.answers.documents") %>
<%= answer.title %> <%= answer.description %> - (<%= answer.images.count %>)
+ (<%= answer.images.count %>) +
<%= link_to t("admin.questions.show.answers.images_list"), admin_answer_images_path(answer) %>
+ (<%= answer.documents.count rescue 0 %>) +
+ <%= link_to t("admin.questions.show.answers.documents_list"), + admin_question_answer_documents_path(@question, answer) %> +
From 37c9ca09737cf0d7efae2467f0e54799b7850365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Thu, 5 Oct 2017 15:42:12 +0200 Subject: [PATCH 16/91] Fixed admin menu --- app/views/admin/_menu.html.erb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb index 81e1ae9bd..21dc7cffb 100644 --- a/app/views/admin/_menu.html.erb +++ b/app/views/admin/_menu.html.erb @@ -53,7 +53,6 @@ <% end %> - <% if feature?(:polls) %>
  • From d20a4909d61b764b304ba40a3bff3d67a46332d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Thu, 5 Oct 2017 15:42:54 +0200 Subject: [PATCH 17/91] Minor fix Removed left margin from submit button --- app/views/admin/poll/questions/answers/_form.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/poll/questions/answers/_form.html.erb b/app/views/admin/poll/questions/answers/_form.html.erb index 72ffb4771..fc16e7e36 100644 --- a/app/views/admin/poll/questions/answers/_form.html.erb +++ b/app/views/admin/poll/questions/answers/_form.html.erb @@ -15,7 +15,7 @@ label: false %>
  • -
    +
    <%= f.submit(class: "button expanded", value: t("shared.save")) %>
    From a655466dbfdab552e00e908bd3dcbb2bd008d424 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Thu, 5 Oct 2017 15:45:01 +0200 Subject: [PATCH 18/91] Added new translations --- config/locales/en/admin.yml | 5 ++++- config/locales/es/admin.yml | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 02d8bacdd..d4dc0500c 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -601,12 +601,15 @@ en: valid_answers: Valid answers add_answer: "Add answer" video_url: External video - documents: Documents (1) + documents: Documents answers: title: Answer description: Description images: Images images_list: Images list + documents: Documents + documents_list: Documents list + document_title: Title answers: new: title: "New answer" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 9e0de770e..df18830fd 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -602,13 +602,15 @@ es: add_answer: "Añadir respuesta" description: Descripción video_url: Video externo - documents: Documentos (1) - preview: Ver en la web + documents: Documentos answers: title: Respuesta description: Descripción images: Imágenes images_list: Lista de imágenes + documents: Documentos + documents_list: Lista de documentos + document_title: Título answers: new: title: "Nueva respuesta" From 1225fc90094f864c03b4cb4115f2b42a556b74ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Thu, 5 Oct 2017 16:22:45 +0200 Subject: [PATCH 19/91] Minor fix --- app/views/admin/poll/questions/answers/documents.html.erb | 2 +- config/locales/en/admin.yml | 1 + config/locales/es/admin.yml | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/views/admin/poll/questions/answers/documents.html.erb b/app/views/admin/poll/questions/answers/documents.html.erb index 28b55a2a3..4c859a78d 100644 --- a/app/views/admin/poll/questions/answers/documents.html.erb +++ b/app/views/admin/poll/questions/answers/documents.html.erb @@ -30,7 +30,7 @@ - + <% @answer.documents.each do |document| %> diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index d4dc0500c..d50e38fe8 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -610,6 +610,7 @@ en: documents: Documents documents_list: Documents list document_title: Title + document_actions: Actions answers: new: title: "New answer" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index df18830fd..40587f30d 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -611,6 +611,7 @@ es: documents: Documentos documents_list: Lista de documentos document_title: Título + document_actions: Acciones answers: new: title: "Nueva respuesta" From b8f2fd1c54e75f6792993fd3f7d89df295e60cae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Thu, 5 Oct 2017 17:34:10 +0200 Subject: [PATCH 20/91] Markup fixes --- .../admin/poll/questions/answers/documents.html.erb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/views/admin/poll/questions/answers/documents.html.erb b/app/views/admin/poll/questions/answers/documents.html.erb index 4c859a78d..d9036b163 100644 --- a/app/views/admin/poll/questions/answers/documents.html.erb +++ b/app/views/admin/poll/questions/answers/documents.html.erb @@ -2,7 +2,11 @@

    <%= t("admin.questions.show.answers.documents_list") %>

    -

    <%= link_to @question.poll.name, admin_poll_path(@question.poll) %> > <%= link_to @question.title, admin_question_path(@question) %> > <%= @answer.title %>

    +
    <%= form_for(@answer, url: admin_question_answer_path(@question, @answer)) do |f| %> @@ -30,15 +34,15 @@
    <%= t("admin.questions.show.answers.document_title") %><%= t("admin.questions.show.answers.description") %><%= t("admin.questions.show.answers.document_actions") %>
    - + <% @answer.documents.each do |document| %> - - <% end %> From 78569152034c58bf756913e78693717acd894384 Mon Sep 17 00:00:00 2001 From: decabeza Date: Fri, 6 Oct 2017 02:38:43 +0200 Subject: [PATCH 22/91] removes @question on questions answers --- .../admin/poll/questions/answers_controller.rb | 4 ---- .../admin/poll/questions/answers/documents.html.erb | 11 +++++------ 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/app/controllers/admin/poll/questions/answers_controller.rb b/app/controllers/admin/poll/questions/answers_controller.rb index 9223e65d4..e4d8869c0 100644 --- a/app/controllers/admin/poll/questions/answers_controller.rb +++ b/app/controllers/admin/poll/questions/answers_controller.rb @@ -1,5 +1,4 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController - before_action :load_question before_action :load_answer, only: [:update, :documents] load_and_authorize_resource :question, class: "::Poll::Question" @@ -43,7 +42,4 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController @answer = ::Poll::Question::Answer.find(params[:id] || params[:answer_id]) end - def load_question - @question = ::Poll::Question.find(params[:question_id]) - end end diff --git a/app/views/admin/poll/questions/answers/documents.html.erb b/app/views/admin/poll/questions/answers/documents.html.erb index d9036b163..ba2a6193b 100644 --- a/app/views/admin/poll/questions/answers/documents.html.erb +++ b/app/views/admin/poll/questions/answers/documents.html.erb @@ -3,18 +3,17 @@

    <%= t("admin.questions.show.answers.documents_list") %>

    -
    - <%= form_for(@answer, url: admin_question_answer_path(@question, @answer)) do |f| %> +
    + <%= form_for(Poll::Question::Answer.new, + url: admin_answer_documents_path(@answer), + method: :post) do |f| %> <%= render 'shared/errors', resource: @answer %> - <%= f.hidden_field :question_id, value: @question.id %> -
    From a15d1a4020c27aac1843c002c3a836af645174f1 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Fri, 6 Oct 2017 02:52:06 +0200 Subject: [PATCH 23/91] resolves conflict when uploading pdfs to answers --- app/models/direct_upload.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/direct_upload.rb b/app/models/direct_upload.rb index 192f06d04..cbd98f3d2 100644 --- a/app/models/direct_upload.rb +++ b/app/models/direct_upload.rb @@ -19,7 +19,7 @@ class DirectUpload if @resource_type.present? && @resource_relation.present? && (@attachment.present? || @cached_attachment.present?) @resource = @resource_type.constantize.find_or_initialize_by(id: @resource_id) - if @resource.respond_to?(:images) + if @resource.respond_to?(:images) && !@attachment.content_type.match(/pdf/) @relation = @resource.images.send("build", relation_attributtes) elsif @resource.class.reflections[@resource_relation].macro == :has_one @relation = @resource.send("build_#{resource_relation}", relation_attributtes) From c5c1ea7251b3cd7dacd78b3fc0aa1a17fedf029b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Fri, 6 Oct 2017 12:02:24 +0200 Subject: [PATCH 24/91] Fixed answer documents form --- app/controllers/admin/poll/questions/answers_controller.rb | 2 +- app/views/admin/poll/questions/answers/documents.html.erb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/poll/questions/answers_controller.rb b/app/controllers/admin/poll/questions/answers_controller.rb index e4d8869c0..2bc442fe5 100644 --- a/app/controllers/admin/poll/questions/answers_controller.rb +++ b/app/controllers/admin/poll/questions/answers_controller.rb @@ -20,7 +20,7 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController def update if @answer.update(answer_params) - redirect_to admin_question_path(@question), notice: t("flash.actions.save_changes.notice") + redirect_to admin_question_path(@answer.question), notice: t("flash.actions.save_changes.notice") else redirect_to :back end diff --git a/app/views/admin/poll/questions/answers/documents.html.erb b/app/views/admin/poll/questions/answers/documents.html.erb index ba2a6193b..54dd25a18 100644 --- a/app/views/admin/poll/questions/answers/documents.html.erb +++ b/app/views/admin/poll/questions/answers/documents.html.erb @@ -9,8 +9,8 @@
    <%= form_for(Poll::Question::Answer.new, - url: admin_answer_documents_path(@answer), - method: :post) do |f| %> + url: admin_answer_path(@answer), + method: :put) do |f| %> <%= render 'shared/errors', resource: @answer %> From bd1c03accf22de0a4b315a97f1319121b3db45ca Mon Sep 17 00:00:00 2001 From: rgarcia Date: Fri, 6 Oct 2017 12:15:45 +0200 Subject: [PATCH 25/91] fixes upload of answer's images --- .../admin/poll/questions/answers/images_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/poll/questions/answers/images_controller.rb b/app/controllers/admin/poll/questions/answers/images_controller.rb index 4074eb371..1bf30907d 100644 --- a/app/controllers/admin/poll/questions/answers/images_controller.rb +++ b/app/controllers/admin/poll/questions/answers/images_controller.rb @@ -23,7 +23,8 @@ class Admin::Poll::Questions::Answers::ImagesController < Admin::Poll::BaseContr private def images_params - params.permit(images_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]) + params.require(:poll_question_answer).permit(:answer_id, + images_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]) end def load_answer From 6e29b6adf5909f613752f9e6d174567163a9a91e Mon Sep 17 00:00:00 2001 From: Bertocq Date: Fri, 6 Oct 2017 12:16:59 +0200 Subject: [PATCH 26/91] Fix dev seeds rake, creating Poll Question Answers --- db/dev_seeds.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index b151a45cf..31902bad9 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -557,11 +557,14 @@ print "Creating Poll Questions" author = User.reorder("RANDOM()").first description = "

    #{Faker::Lorem.paragraphs.join('

    ')}

    " open_at = rand(2.months.ago..2.months.from_now) + answers = Faker::Lorem.words((2..4).to_a.sample).map { |answer| answer.capitalize } question = Poll::Question.create!(author: author, title: Faker::Lorem.sentence(3).truncate(60), - description: description, - valid_answers: Faker::Lorem.words((2..7).to_a.sample).join(', '), + valid_answers: answers.join(', '), poll: poll) + answers.each do |answer| + Poll::Question::Answer.create!(question: question, title: answer, description: Faker::ChuckNorris.fact) + end end puts " ✅" From 8e5cf50679b3fa4e819d4d3e857dc37a33e7f68a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Fri, 6 Oct 2017 12:52:13 +0200 Subject: [PATCH 27/91] Prevent user from seeing its votes in a poll after signing in --- app/helpers/polls_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index a676084cb..c66db216f 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -42,7 +42,7 @@ module PollsHelper end def voted_before_sign_in(question) - current_user.current_sign_in_at >= question.poll.voters.find_by_user_id(current_user).updated_at + current_user.current_sign_in_at >= question.answers.find_or_initialize_by(author: current_user).updated_at end end From b4d494ce2487a2cf85f9861cfc0a52a7869fe1c0 Mon Sep 17 00:00:00 2001 From: decabeza Date: Fri, 6 Oct 2017 12:57:21 +0200 Subject: [PATCH 28/91] fixes documents specs --- spec/shared/features/nested_documentable.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/shared/features/nested_documentable.rb b/spec/shared/features/nested_documentable.rb index 8780936a7..1ad9b55a9 100644 --- a/spec/shared/features/nested_documentable.rb +++ b/spec/shared/features/nested_documentable.rb @@ -193,7 +193,8 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na click_on submit_button documentable_redirected_to_resource_show_or_navigate_to - expect(page).to have_content "Documents (1)" + expect(page).to have_content "Documents" + expect(page).to have_link "empty.pdf" end scenario "Should show resource with new document after successful creation with maximum allowed uploaded files", :js do From 089c1fecfd1187dc3b9e09de589bd567d85af6f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Fri, 6 Oct 2017 13:37:24 +0200 Subject: [PATCH 29/91] Added tests --- spec/features/polls/voter_spec.rb | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/spec/features/polls/voter_spec.rb b/spec/features/polls/voter_spec.rb index 453924674..e558b7261 100644 --- a/spec/features/polls/voter_spec.rb +++ b/spec/features/polls/voter_spec.rb @@ -91,9 +91,32 @@ feature "Voter" do visit poll_path(poll) expect(page).to_not have_link('Yes') - expect(page).to have_content "You have already participated in a booth for this poll." + expect(page).to have_content "You have already participated in a physical booth. You can not participate again." expect(Poll::Voter.count).to eq(1) end + + scenario "Trying to vote in web again", :js do + login_as user + vote_for_poll_via_web(poll, question) + + visit poll_path(poll) + + expect(page).to have_content "You have already participated in this poll. If you vote again it will be overwritten." + within("#poll_question_#{question.id}_answers") do + expect(page).to_not have_link('Yes') + end + + click_link "Sign out" + + login_as user + visit poll_path(poll) + + within("#poll_question_#{question.id}_answers") do + expect(page).to have_link('Yes') + expect(page).to have_link('No') + end + + end end end From 9a31c97a20e4b5f44d80819014996757b04bc03f Mon Sep 17 00:00:00 2001 From: rgarcia Date: Fri, 6 Oct 2017 14:01:03 +0200 Subject: [PATCH 30/91] fixes image specs --- app/models/direct_upload.rb | 4 +++- spec/shared/features/nested_imageable.rb | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/models/direct_upload.rb b/app/models/direct_upload.rb index cbd98f3d2..85d397706 100644 --- a/app/models/direct_upload.rb +++ b/app/models/direct_upload.rb @@ -19,7 +19,9 @@ class DirectUpload if @resource_type.present? && @resource_relation.present? && (@attachment.present? || @cached_attachment.present?) @resource = @resource_type.constantize.find_or_initialize_by(id: @resource_id) - if @resource.respond_to?(:images) && !@attachment.content_type.match(/pdf/) + #Refactor + if @resource.respond_to?(:images) && + (@attachment.present? && !@attachment.content_type.match(/pdf/)) || @cached_attachment.present? @relation = @resource.images.send("build", relation_attributtes) elsif @resource.class.reflections[@resource_relation].macro == :has_one @relation = @resource.send("build_#{resource_relation}", relation_attributtes) diff --git a/spec/shared/features/nested_imageable.rb b/spec/shared/features/nested_imageable.rb index bd519a5bb..1eef9a269 100644 --- a/spec/shared/features/nested_imageable.rb +++ b/spec/shared/features/nested_imageable.rb @@ -146,7 +146,11 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p send(fill_resource_method_name) if fill_resource_method_name click_on submit_button - expect(page).to have_content imageable_success_notice + if has_many_images + skip "no need to test, there are no attributes for the parent resource" + else + expect(page).to have_content imageable_success_notice + end end scenario "Should show successful notice when resource filled correctly and after valid file uploads", :js do From 1806bd3df4444317433872d417977de94a7a8852 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Fri, 6 Oct 2017 14:28:57 +0200 Subject: [PATCH 31/91] Add token string attribute to Poll Answer --- app/models/poll/answer.rb | 3 ++- db/migrate/20171006102811_add_token_to_poll_answer.rb | 5 +++++ db/schema.rb | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20171006102811_add_token_to_poll_answer.rb diff --git a/app/models/poll/answer.rb b/app/models/poll/answer.rb index 2378de6ba..fc4f07c8b 100644 --- a/app/models/poll/answer.rb +++ b/app/models/poll/answer.rb @@ -8,6 +8,7 @@ class Poll::Answer < ActiveRecord::Base validates :question, presence: true validates :author, presence: true validates :answer, presence: true + validates :token, presence: true # temporary skipping validation, review when removing valid_answers # validates :answer, inclusion: { in: ->(a) { a.question.valid_answers }}, @@ -19,4 +20,4 @@ class Poll::Answer < ActiveRecord::Base def record_voter_participation Poll::Voter.find_or_create_by!(user: author, poll: poll, origin: "web") end -end \ No newline at end of file +end diff --git a/db/migrate/20171006102811_add_token_to_poll_answer.rb b/db/migrate/20171006102811_add_token_to_poll_answer.rb new file mode 100644 index 000000000..22fee6db9 --- /dev/null +++ b/db/migrate/20171006102811_add_token_to_poll_answer.rb @@ -0,0 +1,5 @@ +class AddTokenToPollAnswer < ActiveRecord::Migration + def change + add_column :poll_answers, :token, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index dbbd3ec46..04aab5b4d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171004151553) do +ActiveRecord::Schema.define(version: 20171006102811) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -592,6 +592,7 @@ ActiveRecord::Schema.define(version: 20171004151553) do t.string "answer" t.datetime "created_at" t.datetime "updated_at" + t.string "token" end add_index "poll_answers", ["author_id"], name: "index_poll_answers_on_author_id", using: :btree From d4408efda652383eafe94fa9756db3912698421e Mon Sep 17 00:00:00 2001 From: Bertocq Date: Fri, 6 Oct 2017 14:36:21 +0200 Subject: [PATCH 32/91] Generate a unique token for a Poll Ballot and use it on answer buttons --- app/controllers/polls/questions_controller.rb | 1 + app/controllers/polls_controller.rb | 4 +++- app/helpers/polls_helper.rb | 11 +++++++++++ app/views/polls/questions/_answers.html.erb | 4 ++-- app/views/polls/questions/_question.html.erb | 2 +- app/views/polls/questions/answer.js.erb | 3 ++- app/views/polls/show.html.erb | 2 +- config/locales/en/general.yml | 1 + config/locales/es/general.yml | 1 + 9 files changed, 23 insertions(+), 6 deletions(-) diff --git a/app/controllers/polls/questions_controller.rb b/app/controllers/polls/questions_controller.rb index 490b32fbe..32f4b8e54 100644 --- a/app/controllers/polls/questions_controller.rb +++ b/app/controllers/polls/questions_controller.rb @@ -9,6 +9,7 @@ class Polls::QuestionsController < ApplicationController answer = @question.answers.find_or_initialize_by(author: current_user) answer.answer = params[:answer] + answer.token = params[:token] answer.save! answer.record_voter_participation diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 41a038b46..18a75534c 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -1,5 +1,7 @@ class PollsController < ApplicationController + include PollsHelper + load_and_authorize_resource has_filters %w{current expired incoming} @@ -12,7 +14,7 @@ class PollsController < ApplicationController def show @questions = @poll.questions.for_render.sort_for_list - + @token = poll_answer_author_token(@poll, current_user) @answers_by_question_id = {} poll_answers = ::Poll::Answer.by_question(@poll.question_ids).by_author(current_user.try(:id)) poll_answers.each do |answer| diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index 27d33ea04..a0a4736aa 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -41,4 +41,15 @@ module PollsHelper booth.name + location end + def poll_answer_author_token(poll, author) + existing_token = Poll::Answer.where(question: poll.questions, author: author) + existing_token.present? ? existing_token.first.token : poll_answer_unique_token + end + + def poll_answer_unique_token + loop do + token = SecureRandom.hex(32) + break token unless Poll::Answer.where(token: token).exists? + end + end end diff --git a/app/views/polls/questions/_answers.html.erb b/app/views/polls/questions/_answers.html.erb index 2bef6de72..8188c4cd1 100644 --- a/app/views/polls/questions/_answers.html.erb +++ b/app/views/polls/questions/_answers.html.erb @@ -2,13 +2,13 @@ <% if can? :answer, question %> <% question.question_answers.each do |answer| %> <% if @answers_by_question_id[question.id] == answer.title %> - "> <%= answer.title %> <% else %> <%= link_to answer.title, - answer_question_path(question, answer: answer.title), + answer_question_path(question, answer: answer.title, token: token), method: :post, remote: true, title: t("poll_questions.show.vote_answer", answer: answer.title), diff --git a/app/views/polls/questions/_question.html.erb b/app/views/polls/questions/_question.html.erb index 982d0a070..b0df3fb42 100644 --- a/app/views/polls/questions/_question.html.erb +++ b/app/views/polls/questions/_question.html.erb @@ -4,6 +4,6 @@
    - <%= render 'polls/questions/answers', question: question %> + <%= render 'polls/questions/answers', question: question, token: token %>
    diff --git a/app/views/polls/questions/answer.js.erb b/app/views/polls/questions/answer.js.erb index aabbd8d89..2dcb5b0aa 100644 --- a/app/views/polls/questions/answer.js.erb +++ b/app/views/polls/questions/answer.js.erb @@ -1 +1,2 @@ -$("#<%= dom_id(@question) %>_answers").html('<%= j render("polls/questions/answers", question: @question) %>'); +<% token = poll_answer_author_token(@question.poll, current_user) %> +$("#<%= dom_id(@question) %>_answers").html('<%= j render("polls/questions/answers", question: @question, token: token) %>'); diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index b632fac55..bc9cefd2b 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -39,7 +39,7 @@
    <% else %> <% @questions.each do |question| %> - <%= render 'polls/questions/question', question: question %> + <%= render 'polls/questions/question', question: question, token: @token %> <% end %> <% end %>
    diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index 11693d20f..13ab81041 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -497,6 +497,7 @@ en: show: vote_answer: "Vote %{answer}" voted: "You have voted %{answer}" + voted_token: "You can write down this vote identifier, to check your vote on the final results." proposal_notifications: new: title: "Send message" diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index 981f85ca6..1650fb37b 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -497,6 +497,7 @@ es: show: vote_answer: "Votar %{answer}" voted: "Has votado %{answer}" + voted_token: "Puedes apuntar este identificador de voto, para comprobar tu votación en el resultado final" proposal_notifications: new: title: "Enviar mensaje" From 305b5dcf07ddfab603b81679d27fc03ac34d28e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Fri, 6 Oct 2017 14:45:44 +0200 Subject: [PATCH 33/91] Fixed test --- spec/features/polls/polls_spec.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/features/polls/polls_spec.rb b/spec/features/polls/polls_spec.rb index 22b90740a..c3211e1ab 100644 --- a/spec/features/polls/polls_spec.rb +++ b/spec/features/polls/polls_spec.rb @@ -209,8 +209,7 @@ feature 'Polls' do visit poll_path(poll) expect(page).to have_link('Han Solo') - expect(page).to_not have_link('Chewbacca') - expect(page).to have_content('Chewbacca') + expect(page).to have_link('Chewbacca') end scenario 'Level 2 users answering', :js do From 6994f6d7fedf9f964295249deba7a67da67e1a49 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Fri, 6 Oct 2017 15:28:25 +0200 Subject: [PATCH 34/91] Remove random token generation, we'll use JS on the client when its empty --- app/helpers/polls_helper.rb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index a0a4736aa..feb4c42e2 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -43,13 +43,7 @@ module PollsHelper def poll_answer_author_token(poll, author) existing_token = Poll::Answer.where(question: poll.questions, author: author) - existing_token.present? ? existing_token.first.token : poll_answer_unique_token + existing_token.present? ? existing_token.first.token : '' end - def poll_answer_unique_token - loop do - token = SecureRandom.hex(32) - break token unless Poll::Answer.where(token: token).exists? - end - end end From 63eaa0bef6f32f2de26f4868f04fbfd7b8f2a7b3 Mon Sep 17 00:00:00 2001 From: Angel Perez Date: Fri, 6 Oct 2017 09:48:17 -0400 Subject: [PATCH 35/91] Allow Poll::Question::Answer edit As requested by #1992 --- .../poll/questions/answers_controller.rb | 22 +++++++- .../poll/questions/answers/_form.html.erb | 9 ++-- .../poll/questions/answers/edit.html.erb | 14 +++++ .../poll/questions/answers/show.html.erb | 32 ++++++++++++ app/views/admin/poll/questions/show.html.erb | 4 +- config/locales/en/activerecord.yml | 6 +-- config/locales/en/admin.yml | 9 +++- config/locales/es/activerecord.yml | 6 +-- config/locales/es/admin.yml | 9 +++- config/locales/fr/activerecord.yml | 6 +-- config/locales/fr/admin.yml | 9 +++- config/routes.rb | 2 +- .../poll/questions/answers/answers_spec.rb | 51 +++++++++++++++++++ 13 files changed, 157 insertions(+), 22 deletions(-) create mode 100644 app/views/admin/poll/questions/answers/edit.html.erb create mode 100644 app/views/admin/poll/questions/answers/show.html.erb create mode 100644 spec/features/admin/poll/questions/answers/answers_spec.rb diff --git a/app/controllers/admin/poll/questions/answers_controller.rb b/app/controllers/admin/poll/questions/answers_controller.rb index 660339844..4d70b34d1 100644 --- a/app/controllers/admin/poll/questions/answers_controller.rb +++ b/app/controllers/admin/poll/questions/answers_controller.rb @@ -1,5 +1,6 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController - before_action :load_question + before_action :load_question, except: [:show, :edit, :update] + before_action :load_answer, only: [:show, :edit, :update] load_and_authorize_resource :question, class: "::Poll::Question" @@ -18,6 +19,21 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController end end + def show + end + + def edit + end + + def update + if @answer.update(answer_params) + redirect_to admin_answer_path(@answer), + notice: t("flash.actions.save_changes.notice") + else + render :edit + end + end + private def answer_params @@ -27,4 +43,8 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController def load_question @question = ::Poll::Question.find(params[:question_id]) end + + def load_answer + @answer = ::Poll::Question::Answer.find(params[:id]) + end end diff --git a/app/views/admin/poll/questions/answers/_form.html.erb b/app/views/admin/poll/questions/answers/_form.html.erb index 72ffb4771..3eae62c2f 100644 --- a/app/views/admin/poll/questions/answers/_form.html.erb +++ b/app/views/admin/poll/questions/answers/_form.html.erb @@ -2,17 +2,14 @@ <%= render 'shared/errors', resource: @answer %> - <%= f.hidden_field :question_id, value: @question.id %> + <%= f.hidden_field :question_id, value: @answer.question_id || @question.id %> - <%= f.label :title, t('admin.questions.new.form.title') %> - <%= f.text_field :title, label: false %> + <%= f.text_field :title %>
    - <%= f.label :description, t('admin.questions.new.form.description') %> <%= f.cktext_area :description, maxlength: Poll::Question.description_max_length, - ckeditor: { language: I18n.locale }, - label: false %> + ckeditor: { language: I18n.locale } %>
    diff --git a/app/views/admin/poll/questions/answers/edit.html.erb b/app/views/admin/poll/questions/answers/edit.html.erb new file mode 100644 index 000000000..48fb4ad5d --- /dev/null +++ b/app/views/admin/poll/questions/answers/edit.html.erb @@ -0,0 +1,14 @@ +<%= back_link_to %> + + + +

    + <%= t("admin.answers.edit.title") %> +

    + +
    + <%= render "form", form_url: admin_answer_path(@answer) %> +
    diff --git a/app/views/admin/poll/questions/answers/show.html.erb b/app/views/admin/poll/questions/answers/show.html.erb new file mode 100644 index 000000000..e6e0244a0 --- /dev/null +++ b/app/views/admin/poll/questions/answers/show.html.erb @@ -0,0 +1,32 @@ +<%= back_link_to %> + +<%= link_to t('shared.edit'), edit_admin_answer_path(@answer), + class: "button hollow float-right" %> + + + +
    + +
    +
    +

    + <%= t("admin.answers.show.title") %> +
    + <%= @answer.title %> +

    + +

    + <%= t("admin.answers.show.description") %> + <%= @answer.description %> +

    + +

    + <%= t("admin.answers.show.images") %> +
    + <%= link_to t("admin.answers.show.images_list"), admin_answer_images_path(@answer) %> +

    +
    +
    diff --git a/app/views/admin/poll/questions/show.html.erb b/app/views/admin/poll/questions/show.html.erb index 64c30de1e..fd405d62f 100644 --- a/app/views/admin/poll/questions/show.html.erb +++ b/app/views/admin/poll/questions/show.html.erb @@ -31,7 +31,7 @@
    <%= t("admin.questions.show.answers.document_title") %><%= t("admin.questions.show.answers.document_actions") %><%= t("admin.questions.show.answers.document_actions") %>
    + <%= link_to document.title, document.attachment.url %> + <%= link_to t('documents.buttons.download_document'), document.attachment.url, target: "_blank", From 3ce98b6cdf00038706b3949e5d3b5267e33c0ed5 Mon Sep 17 00:00:00 2001 From: decabeza Date: Fri, 6 Oct 2017 02:09:01 +0200 Subject: [PATCH 21/91] fixes answer documents path on polls questions show --- app/views/admin/poll/questions/show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/poll/questions/show.html.erb b/app/views/admin/poll/questions/show.html.erb index 0a89bf915..acb49b5e1 100644 --- a/app/views/admin/poll/questions/show.html.erb +++ b/app/views/admin/poll/questions/show.html.erb @@ -60,7 +60,7 @@ (<%= answer.documents.count rescue 0 %>)
    <%= link_to t("admin.questions.show.answers.documents_list"), - admin_question_answer_documents_path(@question, answer) %> + admin_answer_documents_path(answer) %>
    - - + <% @officer_assignments.each do |officer_assignment| %> - + <% end %> From 35148015b949f77c0fd14dba895246765bcac097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Fri, 6 Oct 2017 18:43:00 +0200 Subject: [PATCH 43/91] Added token to poll voters --- app/controllers/polls/questions_controller.rb | 4 ++-- app/controllers/polls_controller.rb | 1 - app/models/poll/answer.rb | 7 +++++-- db/migrate/20171006102811_add_token_to_poll_answer.rb | 5 ----- db/migrate/20171006145053_add_token_to_poll_voters.rb | 6 ++++++ db/schema.rb | 5 +++-- 6 files changed, 16 insertions(+), 12 deletions(-) delete mode 100644 db/migrate/20171006102811_add_token_to_poll_answer.rb create mode 100644 db/migrate/20171006145053_add_token_to_poll_voters.rb diff --git a/app/controllers/polls/questions_controller.rb b/app/controllers/polls/questions_controller.rb index 32f4b8e54..39fc18252 100644 --- a/app/controllers/polls/questions_controller.rb +++ b/app/controllers/polls/questions_controller.rb @@ -7,11 +7,11 @@ class Polls::QuestionsController < ApplicationController def answer answer = @question.answers.find_or_initialize_by(author: current_user) + token = params[:token] answer.answer = params[:answer] - answer.token = params[:token] answer.save! - answer.record_voter_participation + answer.record_voter_participation(token) @answers_by_question_id = { @question.id => params[:answer] } end diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 18a75534c..ce807eda2 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -14,7 +14,6 @@ class PollsController < ApplicationController def show @questions = @poll.questions.for_render.sort_for_list - @token = poll_answer_author_token(@poll, current_user) @answers_by_question_id = {} poll_answers = ::Poll::Answer.by_question(@poll.question_ids).by_author(current_user.try(:id)) poll_answers.each do |answer| diff --git a/app/models/poll/answer.rb b/app/models/poll/answer.rb index fc4f07c8b..48287053c 100644 --- a/app/models/poll/answer.rb +++ b/app/models/poll/answer.rb @@ -17,7 +17,10 @@ class Poll::Answer < ActiveRecord::Base scope :by_author, ->(author_id) { where(author_id: author_id) } scope :by_question, ->(question_id) { where(question_id: question_id) } - def record_voter_participation - Poll::Voter.find_or_create_by!(user: author, poll: poll, origin: "web") + def record_voter_participation(token) + Poll::Voter.find_or_create_by!(user: author, poll: poll, origin: "web") do |poll_voter| + poll_voter.token = token unless poll_voter.token.present? + poll_voter.token_seen_at = Time.now unless poll_voter.token_seen_at.present? + end end end diff --git a/db/migrate/20171006102811_add_token_to_poll_answer.rb b/db/migrate/20171006102811_add_token_to_poll_answer.rb deleted file mode 100644 index 22fee6db9..000000000 --- a/db/migrate/20171006102811_add_token_to_poll_answer.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddTokenToPollAnswer < ActiveRecord::Migration - def change - add_column :poll_answers, :token, :string - end -end diff --git a/db/migrate/20171006145053_add_token_to_poll_voters.rb b/db/migrate/20171006145053_add_token_to_poll_voters.rb new file mode 100644 index 000000000..01e68031e --- /dev/null +++ b/db/migrate/20171006145053_add_token_to_poll_voters.rb @@ -0,0 +1,6 @@ +class AddTokenToPollVoters < ActiveRecord::Migration + def change + add_column :poll_voters, :token, :string + add_column :poll_voters, :token_seen_at, :date + end +end diff --git a/db/schema.rb b/db/schema.rb index 04aab5b4d..be956a309 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171006102811) do +ActiveRecord::Schema.define(version: 20171006145053) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -592,7 +592,6 @@ ActiveRecord::Schema.define(version: 20171006102811) do t.string "answer" t.datetime "created_at" t.datetime "updated_at" - t.string "token" end add_index "poll_answers", ["author_id"], name: "index_poll_answers_on_author_id", using: :btree @@ -761,6 +760,8 @@ ActiveRecord::Schema.define(version: 20171006102811) do t.integer "user_id" t.string "origin" t.integer "officer_id" + t.string "token" + t.date "token_seen_at" end add_index "poll_voters", ["booth_assignment_id"], name: "index_poll_voters_on_booth_assignment_id", using: :btree From 165509b5259f92479a158d1864826826d53896c0 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Fri, 6 Oct 2017 18:59:47 +0200 Subject: [PATCH 44/91] Switch from Poll::Answer to Poll::Voter usage and small fixes --- app/controllers/polls_controller.rb | 1 + app/helpers/polls_helper.rb | 5 ++--- app/models/poll/answer.rb | 5 ++--- app/views/polls/questions/answer.js.erb | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index ce807eda2..064aa130f 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -14,6 +14,7 @@ class PollsController < ApplicationController def show @questions = @poll.questions.for_render.sort_for_list + @token = poll_voter_token(@poll, current_user) @answers_by_question_id = {} poll_answers = ::Poll::Answer.by_question(@poll.question_ids).by_author(current_user.try(:id)) poll_answers.each do |answer| diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index feb4c42e2..acc84b49c 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -41,9 +41,8 @@ module PollsHelper booth.name + location end - def poll_answer_author_token(poll, author) - existing_token = Poll::Answer.where(question: poll.questions, author: author) - existing_token.present? ? existing_token.first.token : '' + def poll_voter_token(poll, user) + Poll::Voter.where(poll: poll, user: user, origin: "web").first&.token || '' end end diff --git a/app/models/poll/answer.rb b/app/models/poll/answer.rb index 48287053c..ccd521294 100644 --- a/app/models/poll/answer.rb +++ b/app/models/poll/answer.rb @@ -8,7 +8,6 @@ class Poll::Answer < ActiveRecord::Base validates :question, presence: true validates :author, presence: true validates :answer, presence: true - validates :token, presence: true # temporary skipping validation, review when removing valid_answers # validates :answer, inclusion: { in: ->(a) { a.question.valid_answers }}, @@ -19,8 +18,8 @@ class Poll::Answer < ActiveRecord::Base def record_voter_participation(token) Poll::Voter.find_or_create_by!(user: author, poll: poll, origin: "web") do |poll_voter| - poll_voter.token = token unless poll_voter.token.present? - poll_voter.token_seen_at = Time.now unless poll_voter.token_seen_at.present? + poll_voter.token = token unless poll_voter.token.present? + poll_voter.token_seen_at = Time.current unless poll_voter.token_seen_at.present? end end end diff --git a/app/views/polls/questions/answer.js.erb b/app/views/polls/questions/answer.js.erb index 2dcb5b0aa..8e8c01358 100644 --- a/app/views/polls/questions/answer.js.erb +++ b/app/views/polls/questions/answer.js.erb @@ -1,2 +1,2 @@ -<% token = poll_answer_author_token(@question.poll, current_user) %> +<% token = poll_voter_token(@question.poll, current_user) %> $("#<%= dom_id(@question) %>_answers").html('<%= j render("polls/questions/answers", question: @question, token: token) %>'); From cb1542874241e115f39af6bad5abf7095b29d8f5 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Fri, 6 Oct 2017 19:57:31 +0200 Subject: [PATCH 45/91] Add scenario for re-voting after sing out the same answer --- spec/features/polls/polls_spec.rb | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/spec/features/polls/polls_spec.rb b/spec/features/polls/polls_spec.rb index c3211e1ab..91b90c23f 100644 --- a/spec/features/polls/polls_spec.rb +++ b/spec/features/polls/polls_spec.rb @@ -255,5 +255,39 @@ feature 'Polls' do expect(page).to have_link('Han Solo') end + scenario 'Level 2 votes, signs out, signs in, votes again', :js do + poll.update(geozone_restricted: true) + poll.geozones << geozone + + question = create(:poll_question, poll: poll) + answer1 = create(:poll_question_answer, question: question, title: 'Han Solo') + answer2 = create(:poll_question_answer, question: question, title: 'Chewbacca') + + user = create(:user, :level_two, geozone: geozone) + + login_as user + visit poll_path(poll) + click_link 'Han Solo' + + expect(page).to_not have_link('Han Solo') + expect(page).to have_link('Chewbacca') + + click_link "Sign out" + login_as user + visit poll_path(poll) + click_link 'Han Solo' + + expect(page).to_not have_link('Han Solo') + expect(page).to have_link('Chewbacca') + + click_link "Sign out" + login_as user + visit poll_path(poll) + click_link 'Chewbacca' + + expect(page).to_not have_link('Chewbacca') + expect(page).to have_link('Han Solo') + end + end end From 81f65f1ac97517933bf32b0c116198d631dbd105 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Fri, 6 Oct 2017 19:57:52 +0200 Subject: [PATCH 46/91] Touch answer model to force the updated_at value update --- app/controllers/polls/questions_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/polls/questions_controller.rb b/app/controllers/polls/questions_controller.rb index 490b32fbe..7fecefe98 100644 --- a/app/controllers/polls/questions_controller.rb +++ b/app/controllers/polls/questions_controller.rb @@ -9,6 +9,7 @@ class Polls::QuestionsController < ApplicationController answer = @question.answers.find_or_initialize_by(author: current_user) answer.answer = params[:answer] + answer.touch if answer.persisted? answer.save! answer.record_voter_participation From bfef00d478e399160185044390a652aedc80c3fc Mon Sep 17 00:00:00 2001 From: Bertocq Date: Fri, 6 Oct 2017 20:07:57 +0200 Subject: [PATCH 47/91] Refactor voted_before_sign_in logic to avoid no-answer scenario error --- app/helpers/polls_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index c66db216f..b6c0518bb 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -42,7 +42,7 @@ module PollsHelper end def voted_before_sign_in(question) - current_user.current_sign_in_at >= question.answers.find_or_initialize_by(author: current_user).updated_at + question.answers.where(author: current_user).any? { |vote| current_user.current_sign_in_at >= vote.updated_at } end end From d62c0d5d0531f148eaac81f5ff4cea5bde4be211 Mon Sep 17 00:00:00 2001 From: Angel Perez Date: Fri, 6 Oct 2017 11:41:31 -0400 Subject: [PATCH 48/91] Remove Poll::Question title length limit As requested by #1997 --- app/views/admin/poll/questions/_form.html.erb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/views/admin/poll/questions/_form.html.erb b/app/views/admin/poll/questions/_form.html.erb index d197112f5..17ebde59d 100644 --- a/app/views/admin/poll/questions/_form.html.erb +++ b/app/views/admin/poll/questions/_form.html.erb @@ -12,13 +12,19 @@ label: t("admin.questions.new.poll_label") %> - <%= f.text_field :title, maxlength: Poll::Question.title_max_length %> + <%= f.text_field :title %>
    <%= f.label :video_url, t("proposals.form.proposal_video_url") %> -

    <%= t("proposals.form.proposal_video_url_note") %>

    - <%= f.text_field :video_url, placeholder: t("proposals.form.proposal_video_url"), label: false, - aria: {describedby: "video-url-help-text"} %> + +

    + <%= t("proposals.form.proposal_video_url_note") %> +

    + + <%= f.text_field :video_url, + placeholder: t("proposals.form.proposal_video_url"), + label: false, + aria: {describedby: "video-url-help-text"} %>
    From 7fad60484220bb0e5a1796821a7bade726b81540 Mon Sep 17 00:00:00 2001 From: Angel Perez Date: Fri, 6 Oct 2017 13:09:33 -0400 Subject: [PATCH 49/91] Avoid show div into markup for answers' information If an answer does not contain any description or images associated, the "poll-more-info-answers" div won't be shown in the markup Change requested by #1998 --- app/views/polls/show.html.erb | 38 +++++++++++++++++------------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index 1eb128333..e3405c0a8 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -66,29 +66,29 @@
    -
    -
    + <% @poll.questions.map(&:question_answers).flatten.each do |answer| %> + <% if answer.description.present? || answer.images.any? %> +
    +
    - <% @poll.questions.map(&:question_answers).flatten.each do |answer| %> -
    +
    - <% if answer.description.present? %> -

    <%= answer.title %>

    - <% end %> + <% if answer.description.present? %> +

    <%= answer.title %>

    - <% if answer.images.any? %> - <%= render "gallery", answer: answer %> - <% end %> +
    + <%= safe_html_with_links simple_format(answer.description) %> +
    + <% end %> - <% if answer.description.present? %> -
    - <%= safe_html_with_links simple_format(answer.description) %> -
    - <% end %> + <% if answer.images.any? %> + <%= render "gallery", answer: answer %> + <% end %> +
    - <% end %> -
    -
    +
    + <% end %> + <% end %>
    From cf3a62b12688b16da5c147d9be67423d4fbce4ae Mon Sep 17 00:00:00 2001 From: rgarcia Date: Fri, 6 Oct 2017 20:32:06 +0200 Subject: [PATCH 50/91] fixes specs --- app/controllers/admin/poll/questions/answers_controller.rb | 4 ++++ config/locales/en/admin.yml | 3 --- config/locales/es/admin.yml | 3 --- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/controllers/admin/poll/questions/answers_controller.rb b/app/controllers/admin/poll/questions/answers_controller.rb index 16867398e..45f0abcd7 100644 --- a/app/controllers/admin/poll/questions/answers_controller.rb +++ b/app/controllers/admin/poll/questions/answers_controller.rb @@ -50,4 +50,8 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController @answer = ::Poll::Question::Answer.find(params[:id] || params[:answer_id]) end + def load_question + @question = ::Poll::Question.find(params[:question_id]) + end + end diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 59fad34a3..b16214a2a 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -587,9 +587,6 @@ en: new: title: "Create Question" poll_label: "Poll" - form: - title: Title - description: Description answers: images: add_image: "Add image" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 00fc4c032..75fa73dff 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -587,9 +587,6 @@ es: new: title: "Crear pregunta ciudadana" poll_label: "Votación" - form: - title: Título - description: Descripción answers: images: add_image: "Añadir imagen" From 00bb6874dbe8df40873b393bb84d234b9af14404 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Fri, 6 Oct 2017 12:16:59 +0200 Subject: [PATCH 51/91] Fix dev seeds rake, creating Poll Question Answers --- db/dev_seeds.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index 3ce1a439f..31902bad9 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -557,10 +557,14 @@ print "Creating Poll Questions" author = User.reorder("RANDOM()").first description = "

    #{Faker::Lorem.paragraphs.join('

    ')}

    " open_at = rand(2.months.ago..2.months.from_now) + answers = Faker::Lorem.words((2..4).to_a.sample).map { |answer| answer.capitalize } question = Poll::Question.create!(author: author, title: Faker::Lorem.sentence(3).truncate(60), - valid_answers: Faker::Lorem.words((2..7).to_a.sample).join(', '), + valid_answers: answers.join(', '), poll: poll) + answers.each do |answer| + Poll::Question::Answer.create!(question: question, title: answer, description: Faker::ChuckNorris.fact) + end end puts " ✅" From a1907c6f50052f758e0c9c175cd7ebe8ca44c36d Mon Sep 17 00:00:00 2001 From: Angel Perez Date: Fri, 6 Oct 2017 14:40:54 -0400 Subject: [PATCH 52/91] Show answer's associated documents on polls As requested by #2003 --- app/views/polls/show.html.erb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index e3405c0a8..8347455ae 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -67,7 +67,7 @@ <% @poll.questions.map(&:question_answers).flatten.each do |answer| %> - <% if answer.description.present? || answer.images.any? %> + <% if answer.description.present? || answer.images.any? || answer.documents.present? %>
    @@ -86,7 +86,18 @@ <%= render "gallery", answer: answer %> <% end %> + <% if answer.documents.present? %> + <% answer.documents.each do |document| %> +
    + + + <% end %> + <% end %> + <% end %> From bcfd1a844a7e874aa6db37182e43674638e956da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Fri, 6 Oct 2017 20:44:47 +0200 Subject: [PATCH 53/91] Poll voter token --- app/assets/javascripts/application.js | 2 ++ app/assets/javascripts/polls.js.coffee | 21 +++++++++++++++++++ app/models/poll/answer.rb | 5 ++--- app/views/polls/questions/_answers.html.erb | 2 +- app/views/polls/show.html.erb | 7 +++++++ config/locales/en/general.yml | 2 +- config/locales/es/general.yml | 2 +- ...20171006145053_add_token_to_poll_voters.rb | 1 - db/schema.rb | 1 - 9 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 app/assets/javascripts/polls.js.coffee diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index b73c07474..ce9861547 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -70,6 +70,7 @@ //= require polls_admin //= require leaflet //= require map +//= require polls var initialize_modules = function() { App.Comments.initialize(); @@ -108,6 +109,7 @@ var initialize_modules = function() { App.TagAutocomplete.initialize(); App.PollsAdmin.initialize(); App.Map.initialize(); + App.Polls.initialize(); }; $(function(){ diff --git a/app/assets/javascripts/polls.js.coffee b/app/assets/javascripts/polls.js.coffee new file mode 100644 index 000000000..ace7f895e --- /dev/null +++ b/app/assets/javascripts/polls.js.coffee @@ -0,0 +1,21 @@ +App.Polls = + generateToken: -> + rand = Math.random().toString(36).substr(2) # remove `0.` + token = rand + rand # to make it longer + return token + + replaceToken: -> + for link in $('.js-question-answer') + token_param = link.search.slice(-6) + if token_param == "token=" + link.href = link.href + @token + + initialize: -> + @token = App.Polls.generateToken() + App.Polls.replaceToken() + + $(".js-question-answer").on "click", (@token) -> + token_message = $(".js-token-message") + token_message.html(token_message.html() + "
    " + @token + ""); + token_message.show() + false diff --git a/app/models/poll/answer.rb b/app/models/poll/answer.rb index ccd521294..da68f2d91 100644 --- a/app/models/poll/answer.rb +++ b/app/models/poll/answer.rb @@ -17,9 +17,8 @@ class Poll::Answer < ActiveRecord::Base scope :by_question, ->(question_id) { where(question_id: question_id) } def record_voter_participation(token) - Poll::Voter.find_or_create_by!(user: author, poll: poll, origin: "web") do |poll_voter| - poll_voter.token = token unless poll_voter.token.present? - poll_voter.token_seen_at = Time.current unless poll_voter.token_seen_at.present? + Poll::Voter.find_or_create_by(user: author, poll: poll, origin: "web") do |poll_voter| + poll_voter.token = token unless poll_voter.token.present? end end end diff --git a/app/views/polls/questions/_answers.html.erb b/app/views/polls/questions/_answers.html.erb index 8188c4cd1..3801a1964 100644 --- a/app/views/polls/questions/_answers.html.erb +++ b/app/views/polls/questions/_answers.html.erb @@ -12,7 +12,7 @@ method: :post, remote: true, title: t("poll_questions.show.vote_answer", answer: answer.title), - class: "button secondary hollow" %> + class: "button secondary hollow js-question-answer" %> <% end %> <% end %> <% else %> diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index bc9cefd2b..be743f2f1 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -38,6 +38,13 @@ <%= t("polls.show.already_voted_in_booth") %> <% else %> + + <% if !@poll.voters.find_by_user_id(current_user).present? %> + + <% end %> + <% @questions.each do |question| %> <%= render 'polls/questions/question', question: question, token: @token %> <% end %> diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index 13ab81041..8f999d0ec 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -497,7 +497,7 @@ en: show: vote_answer: "Vote %{answer}" voted: "You have voted %{answer}" - voted_token: "You can write down this vote identifier, to check your vote on the final results." + voted_token: "You can write down this vote identifier, to check your vote on the final results:" proposal_notifications: new: title: "Send message" diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index 1650fb37b..677b03a4a 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -497,7 +497,7 @@ es: show: vote_answer: "Votar %{answer}" voted: "Has votado %{answer}" - voted_token: "Puedes apuntar este identificador de voto, para comprobar tu votación en el resultado final" + voted_token: "Puedes apuntar este identificador de voto, para comprobar tu votación en el resultado final:" proposal_notifications: new: title: "Enviar mensaje" diff --git a/db/migrate/20171006145053_add_token_to_poll_voters.rb b/db/migrate/20171006145053_add_token_to_poll_voters.rb index 01e68031e..5d07f5065 100644 --- a/db/migrate/20171006145053_add_token_to_poll_voters.rb +++ b/db/migrate/20171006145053_add_token_to_poll_voters.rb @@ -1,6 +1,5 @@ class AddTokenToPollVoters < ActiveRecord::Migration def change add_column :poll_voters, :token, :string - add_column :poll_voters, :token_seen_at, :date end end diff --git a/db/schema.rb b/db/schema.rb index be956a309..cafec3a82 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -761,7 +761,6 @@ ActiveRecord::Schema.define(version: 20171006145053) do t.string "origin" t.integer "officer_id" t.string "token" - t.date "token_seen_at" end add_index "poll_voters", ["booth_assignment_id"], name: "index_poll_voters_on_booth_assignment_id", using: :btree From 8b8e8aff8fa636748128e4a3ab377fb19d1cc0da Mon Sep 17 00:00:00 2001 From: Angel Perez Date: Fri, 6 Oct 2017 14:46:13 -0400 Subject: [PATCH 54/91] Show answer's title if answer has any records associated If an answer has a description and/or documents/images associated, the answer's title will be shown on the UI so the user can associate a certain answer with its related records See issue #1998, as well as commit 7fad604 --- app/views/polls/show.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index 8347455ae..5dc138f8d 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -74,9 +74,9 @@
    - <% if answer.description.present? %> -

    <%= answer.title %>

    +

    <%= answer.title %>

    + <% if answer.description.present? %>
    <%= safe_html_with_links simple_format(answer.description) %>
    From 34cd8d8b98c8260a19fcd4c8774b8baab13b55e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Fri, 6 Oct 2017 20:59:25 +0200 Subject: [PATCH 55/91] Fixed token message --- app/assets/javascripts/polls.js.coffee | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/polls.js.coffee b/app/assets/javascripts/polls.js.coffee index ace7f895e..d603f01b9 100644 --- a/app/assets/javascripts/polls.js.coffee +++ b/app/assets/javascripts/polls.js.coffee @@ -14,7 +14,8 @@ App.Polls = @token = App.Polls.generateToken() App.Polls.replaceToken() - $(".js-question-answer").on "click", (@token) -> + $(".js-question-answer").on + click: => token_message = $(".js-token-message") token_message.html(token_message.html() + "
    " + @token + ""); token_message.show() From 7e11a48f00d17fab3fe0104d93dfec68d5146319 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Fri, 6 Oct 2017 21:14:19 +0200 Subject: [PATCH 56/91] Fixed token message --- app/assets/javascripts/polls.js.coffee | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/polls.js.coffee b/app/assets/javascripts/polls.js.coffee index d603f01b9..50daff0ba 100644 --- a/app/assets/javascripts/polls.js.coffee +++ b/app/assets/javascripts/polls.js.coffee @@ -17,6 +17,7 @@ App.Polls = $(".js-question-answer").on click: => token_message = $(".js-token-message") - token_message.html(token_message.html() + "
    " + @token + ""); - token_message.show() + if !token_message.is(':visible') + token_message.html(token_message.html() + "
    " + @token + ""); + token_message.show() false From cc2da735c738852fcfaf4d60946b0e47c7eeac13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Fri, 6 Oct 2017 21:47:46 +0200 Subject: [PATCH 57/91] Set token to 64 characters --- app/assets/javascripts/polls.js.coffee | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/polls.js.coffee b/app/assets/javascripts/polls.js.coffee index 50daff0ba..650c2596a 100644 --- a/app/assets/javascripts/polls.js.coffee +++ b/app/assets/javascripts/polls.js.coffee @@ -1,7 +1,11 @@ App.Polls = generateToken: -> - rand = Math.random().toString(36).substr(2) # remove `0.` - token = rand + rand # to make it longer + token = '' + for n in [0..5] + rand = Math.random().toString(36).substr(2) # remove `0.` + token = token + rand; + + token = token.substring(0, 64) return token replaceToken: -> From 5f1485dbfa4342acfb4ca554f68c5cb0b7f8421f Mon Sep 17 00:00:00 2001 From: rgarcia Date: Fri, 6 Oct 2017 22:49:53 +0200 Subject: [PATCH 58/91] fixes specs --- app/views/polls/show.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index 5dc138f8d..ed64b20f0 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -69,10 +69,10 @@ <% @poll.questions.map(&:question_answers).flatten.each do |answer| %> <% if answer.description.present? || answer.images.any? || answer.documents.present? %>
    -
    +
    + data-toggler=".medium-6">

    <%= answer.title %>

    From 27a1584a0fd528c78c1f20848316a017fa444a11 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Fri, 6 Oct 2017 23:59:32 +0200 Subject: [PATCH 59/91] Check if user has already voted in a booth on this poll --- app/views/polls/questions/_answers.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/polls/questions/_answers.html.erb b/app/views/polls/questions/_answers.html.erb index 7fb4a5d71..7e995b21a 100644 --- a/app/views/polls/questions/_answers.html.erb +++ b/app/views/polls/questions/_answers.html.erb @@ -1,5 +1,5 @@
    - <% if can? :answer, question %> + <% if can?(:answer, question) && question.poll.voted_in_booth?(current_user) %> <% question.question_answers.each do |answer| %> <% if @answers_by_question_id[question.id] == answer.title && !voted_before_sign_in(question) %> Date: Sat, 7 Oct 2017 00:53:21 +0200 Subject: [PATCH 60/91] Add scenario for user that voted on booth can't vote on website --- spec/features/polls/polls_spec.rb | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/spec/features/polls/polls_spec.rb b/spec/features/polls/polls_spec.rb index 91b90c23f..8f7a9b2de 100644 --- a/spec/features/polls/polls_spec.rb +++ b/spec/features/polls/polls_spec.rb @@ -288,6 +288,42 @@ feature 'Polls' do expect(page).to_not have_link('Chewbacca') expect(page).to have_link('Han Solo') end + end + + context 'Booth & Website' do + + let(:poll) { create(:poll, summary: "Summary", description: "Description") } + let(:booth) { create(:poll_booth) } + let(:officer) { create(:poll_officer) } + + scenario 'Already voted on booth cannot vote on website', :js do + + create(:poll_shift, officer: officer, booth: booth, date: Date.current, task: :vote_collection) + booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth) + create(:poll_officer_assignment, officer: officer, booth_assignment: booth_assignment) + question = create(:poll_question, poll: poll) + create(:poll_question_answer, question: question, title: 'Han Solo') + create(:poll_question_answer, question: question, title: 'Chewbacca') + user = create(:user, :level_two, :in_census) + + login_as(officer.user) + visit new_officing_residence_path + officing_verify_residence + click_button "Confirm vote" + + expect(page).to have_content "Vote introduced!" + + visit new_officing_residence_path + click_link "Sign out" + login_as user + visit poll_path(poll) + + expect(page).to have_content "You have already participated in a physical booth. You can not participate again." + expect(page).to have_content('Han Solo') + expect(page).to have_content('Chewbacca') + expect(page).to_not have_link('Han Solo') + expect(page).to_not have_link('Chewbacca') + end end end From 687fbfac08feac36ccf7ceabd89e882eb76cbbff Mon Sep 17 00:00:00 2001 From: decabeza Date: Sat, 7 Oct 2017 02:05:37 +0200 Subject: [PATCH 61/91] changes zoom icon when is active --- app/views/polls/_gallery.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/polls/_gallery.html.erb b/app/views/polls/_gallery.html.erb index d3da43b88..14da0f27b 100644 --- a/app/views/polls/_gallery.html.erb +++ b/app/views/polls/_gallery.html.erb @@ -1,6 +1,6 @@
    - - + + <%= t("polls.show.zoom_plus") %> From cd495c80fe8bd35a567ba5d1e0a9cfdfe0bae2fb Mon Sep 17 00:00:00 2001 From: decabeza Date: Sat, 7 Oct 2017 02:08:01 +0200 Subject: [PATCH 62/91] changes border right to bottom when expand gallery --- app/assets/stylesheets/participation.scss | 7 +++++++ app/views/polls/show.html.erb | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index 2df8292f6..8567bde69 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -1576,6 +1576,13 @@ .column:nth-child(odd) { border-right: 1px solid #eee; } + + .answer-divider { + border-bottom: 1px solid #eee; + border-right: 0 !important; + margin-bottom: $line-height; + padding-bottom: $line-height; + } } .orbit-bullets button { diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index 1eb128333..365f6f37c 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -71,7 +71,7 @@ <% @poll.questions.map(&:question_answers).flatten.each do |answer| %>
    + data-toggler="medium-6 answer-divider"> <% if answer.description.present? %>

    <%= answer.title %>

    From 732fb70730eec1727fccd1c12ef43cd4f16f6d22 Mon Sep 17 00:00:00 2001 From: decabeza Date: Sat, 7 Oct 2017 03:03:17 +0200 Subject: [PATCH 63/91] makes answers buttons width 100% on mobile size --- app/assets/stylesheets/participation.scss | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index 8567bde69..ca9f7ab08 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -1776,6 +1776,10 @@ margin-right: $line-height / 4; min-width: rem-calc(168); + @include breakpoint(medium down) { + width: 100%; + } + &.answered { background: #f4f8ec; border: 2px solid #92ba48; From 9a396fe6343ff1282c9a4dc7208548b34dcc0d12 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Sat, 7 Oct 2017 10:48:24 +0200 Subject: [PATCH 64/91] Fix record_voter_participation and usage on specs --- app/models/poll/answer.rb | 4 +--- spec/models/poll/answer_spec.rb | 6 +++--- spec/models/poll/voter_spec.rb | 4 ++-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/app/models/poll/answer.rb b/app/models/poll/answer.rb index da68f2d91..4484060dd 100644 --- a/app/models/poll/answer.rb +++ b/app/models/poll/answer.rb @@ -17,8 +17,6 @@ class Poll::Answer < ActiveRecord::Base scope :by_question, ->(question_id) { where(question_id: question_id) } def record_voter_participation(token) - Poll::Voter.find_or_create_by(user: author, poll: poll, origin: "web") do |poll_voter| - poll_voter.token = token unless poll_voter.token.present? - end + Poll::Voter.find_or_create_by(user: author, poll: poll, origin: "web", token: token) end end diff --git a/spec/models/poll/answer_spec.rb b/spec/models/poll/answer_spec.rb index 2c27bc060..8731445cc 100644 --- a/spec/models/poll/answer_spec.rb +++ b/spec/models/poll/answer_spec.rb @@ -46,7 +46,7 @@ describe Poll::Answer do answer = create(:poll_answer, question: question, author: author, answer: "Yes") expect(answer.poll.voters).to be_blank - answer.record_voter_participation + answer.record_voter_participation('token') expect(poll.reload.voters.size).to eq(1) voter = poll.voters.first @@ -57,12 +57,12 @@ describe Poll::Answer do it "updates a poll_voter with user and poll data" do answer = create(:poll_answer, question: question, author: author, answer: "Yes") - answer.record_voter_participation + answer.record_voter_participation('token') expect(poll.reload.voters.size).to eq(1) answer = create(:poll_answer, question: question, author: author, answer: "No") - answer.record_voter_participation + answer.record_voter_participation('token') expect(poll.reload.voters.size).to eq(1) diff --git a/spec/models/poll/voter_spec.rb b/spec/models/poll/voter_spec.rb index f306248dc..bbd22011a 100644 --- a/spec/models/poll/voter_spec.rb +++ b/spec/models/poll/voter_spec.rb @@ -76,7 +76,7 @@ describe :voter do it "should not be valid if the user has voted via web" do answer = create(:poll_answer) - answer.record_voter_participation + answer.record_voter_participation('token') voter = build(:poll_voter, poll: answer.question.poll, user: answer.author) expect(voter).to_not be_valid @@ -169,4 +169,4 @@ describe :voter do expect(voter.document_type).to eq("1") end end -end \ No newline at end of file +end From e127b52225c91e6def5f5e45dcd286e97baea397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Sat, 7 Oct 2017 11:37:33 +0200 Subject: [PATCH 65/91] Minor fixes --- app/assets/javascripts/polls.js.coffee | 1 + app/views/polls/show.html.erb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/polls.js.coffee b/app/assets/javascripts/polls.js.coffee index 650c2596a..5cf792ce2 100644 --- a/app/assets/javascripts/polls.js.coffee +++ b/app/assets/javascripts/polls.js.coffee @@ -1,6 +1,7 @@ App.Polls = generateToken: -> token = '' + rand = '' for n in [0..5] rand = Math.random().toString(36).substr(2) # remove `0.` token = token + rand; diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index 1fd305e71..4a6b7b4fa 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -39,7 +39,7 @@
    <% else %> - <% if !@poll.voters.find_by_user_id(current_user).present? %> + <% if poll_voter_token(@poll, current_user).empty? %> From 3ddcb0fd218539caf425db80fae50dcb1fc31479 Mon Sep 17 00:00:00 2001 From: decabeza Date: Sat, 7 Oct 2017 11:52:50 +0200 Subject: [PATCH 66/91] changes large size to original for gallery images --- app/views/polls/_gallery.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/polls/_gallery.html.erb b/app/views/polls/_gallery.html.erb index 14da0f27b..45408c0da 100644 --- a/app/views/polls/_gallery.html.erb +++ b/app/views/polls/_gallery.html.erb @@ -19,7 +19,7 @@ <% answer.images.reverse.each_with_index do |image, index| %>
  • <%= link_to image.attachment.url(:original), target: "_blank" do %> - <%= image_tag image.attachment.url(:large), + <%= image_tag image.attachment.url(:original), class: "orbit-image", alt: image.title %> <% end %> From a5d3d5d239486d3d6ccbd5095447a3e4bc8e8325 Mon Sep 17 00:00:00 2001 From: decabeza Date: Sat, 7 Oct 2017 11:53:34 +0200 Subject: [PATCH 67/91] adds links to read more and less for answer description --- app/assets/stylesheets/participation.scss | 9 +++++++++ app/views/polls/show.html.erb | 15 ++++++++++++++- config/locales/en/general.yml | 2 ++ config/locales/es/general.yml | 2 ++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index ca9f7ab08..b41e2de2f 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -1583,6 +1583,15 @@ margin-bottom: $line-height; padding-bottom: $line-height; } + + .answer-description { + height: 100%; + + &.short { + height: $line-height * 12; + overflow: hidden; + } + } } .orbit-bullets button { diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index 365f6f37c..7686759ca 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -83,7 +83,20 @@ <% if answer.description.present? %>
    - <%= safe_html_with_links simple_format(answer.description) %> +
    + <%= safe_html_with_links simple_format(answer.description) %> +
    + + <%= t("polls.show.read_more", answer: answer.title) %> + + + <%= t("polls.show.read_less", answer: answer.title) %> +
    <% end %> diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index 82abea68b..79621ddb5 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -492,6 +492,8 @@ en: more_info_title: "More information" documents: Documents zoom_plus: Expand image + read_more: "Read more about %{answer}" + read_less: "Read less about %{answer}" poll_questions: create_question: "Create question" default_valid_answers: "Yes, No" diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index c613e6b40..334090b7b 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -492,6 +492,8 @@ es: more_info_title: "Más información" documents: Documentación zoom_plus: Ampliar imagen + read_more: "Leer más sobre %{answer}" + read_less: "Leer menos sobre %{answer}" poll_questions: create_question: "Crear pregunta para votación" default_valid_answers: "Sí, No" From e7716ca4b33e3aa99df75981f2bd3824e86f72af Mon Sep 17 00:00:00 2001 From: decabeza Date: Sat, 7 Oct 2017 11:56:34 +0200 Subject: [PATCH 68/91] makes darker border answer divider --- app/assets/stylesheets/participation.scss | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index b41e2de2f..605afaee8 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -1574,11 +1574,11 @@ border-bottom: 1px solid #eee; .column:nth-child(odd) { - border-right: 1px solid #eee; + border-right: 2px solid $text; } .answer-divider { - border-bottom: 1px solid #eee; + border-bottom: 2px solid $text; border-right: 0 !important; margin-bottom: $line-height; padding-bottom: $line-height; From e320a836e7a6383386a5d4506429291156e73eac Mon Sep 17 00:00:00 2001 From: rgarcia Date: Sat, 7 Oct 2017 13:31:54 +0200 Subject: [PATCH 69/91] fixes specs --- app/views/polls/questions/_answers.html.erb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/views/polls/questions/_answers.html.erb b/app/views/polls/questions/_answers.html.erb index 7e995b21a..5fc22fd44 100644 --- a/app/views/polls/questions/_answers.html.erb +++ b/app/views/polls/questions/_answers.html.erb @@ -1,7 +1,9 @@
    - <% if can?(:answer, question) && question.poll.voted_in_booth?(current_user) %> + <% if can?(:answer, question) %> <% question.question_answers.each do |answer| %> - <% if @answers_by_question_id[question.id] == answer.title && !voted_before_sign_in(question) %> + <% if @answers_by_question_id[question.id] == answer.title && + (!voted_before_sign_in(question) || + question.poll.voted_in_booth?(current_user)) %> "> <%= answer.title %> From 1ec245513435f609e7f88af883dbb67c95808796 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Sat, 7 Oct 2017 14:30:10 +0200 Subject: [PATCH 70/91] fixes spec this one seems unrelated, probably got pushed in another PR --- spec/features/admin/poll/questions/answers/answers_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/admin/poll/questions/answers/answers_spec.rb b/spec/features/admin/poll/questions/answers/answers_spec.rb index b3b3ad420..66918c4d8 100644 --- a/spec/features/admin/poll/questions/answers/answers_spec.rb +++ b/spec/features/admin/poll/questions/answers/answers_spec.rb @@ -26,7 +26,7 @@ feature 'Answers' do scenario 'Update' do question = create(:poll_question) - answer = create(:poll_question_answer, question: question) + answer = create(:poll_question_answer, question: question, title: "Answer title") visit admin_answer_path(answer) From 316b6720cbc574a85a3efa2a8905436409befd3e Mon Sep 17 00:00:00 2001 From: decabeza Date: Sat, 7 Oct 2017 14:31:04 +0200 Subject: [PATCH 71/91] fixes polls show indentation and adds missing <% end %> --- app/views/polls/show.html.erb | 66 +++++++++++++++++------------------ 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index a6324b985..913b58d4c 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -71,41 +71,41 @@
    - <% @poll.questions.map(&:question_answers).flatten.each do |answer| %> -
    -

    <%= answer.title %>

    + <% @poll.questions.map(&:question_answers).flatten.each do |answer| %> +
    +

    <%= answer.title %>

    - <% if answer.description.present? %> -
    - <%= safe_html_with_links simple_format(answer.description) %> -
    - <% end %> - - <% if answer.images.any? %> - <%= render "gallery", answer: answer %> - <% end %> - - <% if answer.description.present? %> -
    -
    + <% if answer.description.present? %> +
    <%= safe_html_with_links simple_format(answer.description) %>
    - - <%= t("polls.show.read_more", answer: answer.title) %> - - - <%= t("polls.show.read_less", answer: answer.title) %> - -
    - <% end %> + <% end %> - <% if answer.documents.present? %> + <% if answer.images.any? %> + <%= render "gallery", answer: answer %> + <% end %> + + <% if answer.description.present? %> + + <% end %> + + <% if answer.documents.present? %> <% answer.documents.each do |document| %> <%= link_to document.title, document.attachment.url, @@ -113,8 +113,8 @@ rel: "nofollow" %> <% end %> <% end %> -
    - +
    + <% end %>
    <% end %> From 38f100d183883cccf9aa44d7c32ac9d69f486467 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Sat, 7 Oct 2017 14:40:26 +0200 Subject: [PATCH 72/91] fixes loading of poll question --- app/controllers/admin/poll/questions/answers_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/poll/questions/answers_controller.rb b/app/controllers/admin/poll/questions/answers_controller.rb index 45f0abcd7..18b44d279 100644 --- a/app/controllers/admin/poll/questions/answers_controller.rb +++ b/app/controllers/admin/poll/questions/answers_controller.rb @@ -1,6 +1,6 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController - before_action :load_question, except: [:show, :edit, :update] before_action :load_answer, only: [:show, :edit, :update, :documents] + before_action :load_question, except: [:show, :edit, :update] load_and_authorize_resource :question, class: "::Poll::Question" @@ -51,7 +51,7 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController end def load_question - @question = ::Poll::Question.find(params[:question_id]) + @question = @answer.question end end From 12427e1ce5e57fcd2f43e04d575f21a551f81135 Mon Sep 17 00:00:00 2001 From: decabeza Date: Sat, 7 Oct 2017 14:46:55 +0200 Subject: [PATCH 73/91] adds styles to document link on polls show --- app/views/polls/show.html.erb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index 913b58d4c..e152f888c 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -106,12 +106,19 @@ <% end %> <% if answer.documents.present? %> + <% end %>
    <% end %> From 9ec57f68c2f80d3ff54204b28d5b1450dd0912f2 Mon Sep 17 00:00:00 2001 From: decabeza Date: Sat, 7 Oct 2017 14:49:36 +0200 Subject: [PATCH 74/91] changes list of videos links on polls question admin --- app/views/admin/poll/questions/show.html.erb | 5 +++-- config/locales/en/admin.yml | 2 +- config/locales/es/admin.yml | 2 +- config/locales/fr/admin.yml | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/views/admin/poll/questions/show.html.erb b/app/views/admin/poll/questions/show.html.erb index 123d2ec13..5baabeafe 100644 --- a/app/views/admin/poll/questions/show.html.erb +++ b/app/views/admin/poll/questions/show.html.erb @@ -64,8 +64,9 @@ admin_answer_documents_path(answer) %>
  • diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index b16214a2a..442c93727 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -602,7 +602,7 @@ en: title: Answer description: Description videos: Videos - video_list: Video list (%{count}) + video_list: Video list images: Images images_list: Images list documents: Documents diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 75fa73dff..5b6393b1b 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -602,7 +602,7 @@ es: title: Respuesta description: Descripción videos: Vídeos - video_list: Lista de vídeos (%{count}) + video_list: Lista de vídeos images: Imágenes images_list: Lista de imágenes documents: Documentos diff --git a/config/locales/fr/admin.yml b/config/locales/fr/admin.yml index d80e55fc9..b9cdfcfd3 100644 --- a/config/locales/fr/admin.yml +++ b/config/locales/fr/admin.yml @@ -389,7 +389,7 @@ fr: title: Réponse description: Description videos: Vidéos - video_list: Liste des vidéos (%{count}) + video_list: Liste des vidéos answers: show: title: Titre From 777237421fa5a4d777ccf17ec7add08b044d0d3e Mon Sep 17 00:00:00 2001 From: rgarcia Date: Sat, 7 Oct 2017 14:55:08 +0200 Subject: [PATCH 75/91] fixes specs --- app/controllers/admin/poll/questions/answers_controller.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/app/controllers/admin/poll/questions/answers_controller.rb b/app/controllers/admin/poll/questions/answers_controller.rb index 18b44d279..511807b10 100644 --- a/app/controllers/admin/poll/questions/answers_controller.rb +++ b/app/controllers/admin/poll/questions/answers_controller.rb @@ -1,6 +1,5 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController before_action :load_answer, only: [:show, :edit, :update, :documents] - before_action :load_question, except: [:show, :edit, :update] load_and_authorize_resource :question, class: "::Poll::Question" @@ -12,7 +11,7 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController @answer = ::Poll::Question::Answer.new(answer_params) if @answer.save - redirect_to admin_question_path(@question), + redirect_to admin_question_path(@answer.question), notice: t("flash.actions.create.poll_question_answer") else render :new @@ -50,8 +49,4 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController @answer = ::Poll::Question::Answer.find(params[:id] || params[:answer_id]) end - def load_question - @question = @answer.question - end - end From 953a6e7573321c5c4705f63b2bd84f4c1a456d92 Mon Sep 17 00:00:00 2001 From: decabeza Date: Sat, 7 Oct 2017 15:23:31 +0200 Subject: [PATCH 76/91] updates videos link spec --- .../features/admin/poll/questions/answers/videos/videos_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/admin/poll/questions/answers/videos/videos_spec.rb b/spec/features/admin/poll/questions/answers/videos/videos_spec.rb index ee04ce128..35d07f454 100644 --- a/spec/features/admin/poll/questions/answers/videos/videos_spec.rb +++ b/spec/features/admin/poll/questions/answers/videos/videos_spec.rb @@ -16,7 +16,7 @@ feature 'Videos' do visit admin_question_path(question) within("#poll_question_answer_#{answer.id}") do - click_link "Video list (#{answer.videos.count})" + click_link "Video list" end click_link "Add video" From 84e35edca7efa5a20879bd95b54d1afa2823fa85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Sat, 7 Oct 2017 16:16:39 +0200 Subject: [PATCH 77/91] Added new tests for vote token --- spec/features/polls/voter_spec.rb | 7 +++++++ spec/models/poll/voter_spec.rb | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/spec/features/polls/voter_spec.rb b/spec/features/polls/voter_spec.rb index e558b7261..256807928 100644 --- a/spec/features/polls/voter_spec.rb +++ b/spec/features/polls/voter_spec.rb @@ -32,6 +32,11 @@ feature "Voter" do expect(page).to_not have_link('Yes') end + find(:css, ".js-token-message").should be_visible + token = find(:css, ".js-question-answer")[:href].gsub(/.+?(?=token)/, '').gsub('token=', '') + + expect(page).to have_content "You can write down this vote identifier, to check your vote on the final results: #{token}" + expect(Poll::Voter.count).to eq(1) expect(Poll::Voter.first.origin).to eq("web") end @@ -101,6 +106,8 @@ feature "Voter" do visit poll_path(poll) + expect(page).to_not have_selector('.js-token-message') + expect(page).to have_content "You have already participated in this poll. If you vote again it will be overwritten." within("#poll_question_#{question.id}_answers") do expect(page).to_not have_link('Yes') diff --git a/spec/models/poll/voter_spec.rb b/spec/models/poll/voter_spec.rb index bbd22011a..ae0f84a49 100644 --- a/spec/models/poll/voter_spec.rb +++ b/spec/models/poll/voter_spec.rb @@ -162,11 +162,12 @@ describe :voter do it "sets user info" do user = create(:user, document_number: "1234A", document_type: "1") - voter = build(:poll_voter, user: user) + voter = build(:poll_voter, user: user, token: "1234abcd") voter.save expect(voter.document_number).to eq("1234A") expect(voter.document_type).to eq("1") + expect(voter.token).to eq("1234abcd") end end end From bdffab7d7248fc628f14c694a4f8b7b11366db39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Sat, 7 Oct 2017 16:56:35 +0200 Subject: [PATCH 78/91] Fixed already-answered logic Added condition to check if user is unverified to avoid showing the ui element that lets users know they already voted a poll. --- app/views/polls/_poll_group.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/polls/_poll_group.html.erb b/app/views/polls/_poll_group.html.erb index 380b35fc7..b9cbb3c95 100644 --- a/app/views/polls/_poll_group.html.erb +++ b/app/views/polls/_poll_group.html.erb @@ -1,6 +1,6 @@ <% poll_group.each do |poll| %>
    - <% if user_signed_in? && !poll.votable_by?(current_user) %> + <% if user_signed_in? && !current_user.unverified? && !poll.votable_by?(current_user) %>
    "> <%= t("polls.index.already_answer") %>
    From a08d5bdba9defd0a29192d4c1b3ae25b5c8e6e00 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Sat, 7 Oct 2017 17:00:26 +0200 Subject: [PATCH 79/91] fixes conflict in merge --- app/views/polls/show.html.erb | 106 ++++++++++++++++------------------ 1 file changed, 51 insertions(+), 55 deletions(-) diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index ad8b9b0c5..126617684 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -74,64 +74,60 @@
    - <% @poll.questions.map(&:question_answers).flatten.each do |answer| %> - <% if answer.description.present? || answer.images.any? || answer.documents.present? %> -
    -
    +
    +
    - <% @poll.questions.map(&:question_answers).flatten.each do |answer| %> -
    -

    <%= answer.title %>

    + <% @poll.questions.map(&:question_answers).flatten.each do |answer| %> +
    +

    <%= answer.title %>

    - <% if answer.description.present? %> -
    - <%= safe_html_with_links simple_format(answer.description) %> -
    - <% end %> - - <% if answer.images.any? %> - <%= render "gallery", answer: answer %> - <% end %> - - <% if answer.description.present? %> - - <% end %> - - <% if answer.documents.present? %> - - <% end %> + <% if answer.description.present? %> +
    + <%= safe_html_with_links simple_format(answer.description) %>
    <% end %> + + <% if answer.images.any? %> + <%= render "gallery", answer: answer %> + <% end %> + + <% if answer.description.present? %> + + <% end %> + + <% if answer.documents.present? %> + + <% end %>
    -
    - <% end %> - <% end %> + <% end %> +
    +
    From b19953b38f531374cb5ac1d0692c30492daba7a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Sat, 7 Oct 2017 17:06:53 +0200 Subject: [PATCH 80/91] Added tests --- spec/features/polls/polls_spec.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/features/polls/polls_spec.rb b/spec/features/polls/polls_spec.rb index 8f7a9b2de..faaadc548 100644 --- a/spec/features/polls/polls_spec.rb +++ b/spec/features/polls/polls_spec.rb @@ -94,6 +94,9 @@ feature 'Polls' do end scenario 'Level 1 users' do + visit polls_path + expect(page).to_not have_selector('.already-answer') + poll.update(geozone_restricted: true) poll.geozones << geozone From 7cfd47ad87a3d72b30d95b8d5fdd90e91322c6c0 Mon Sep 17 00:00:00 2001 From: decabeza Date: Sat, 7 Oct 2017 17:11:40 +0200 Subject: [PATCH 81/91] removes duplicated content on polls show --- app/views/polls/show.html.erb | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index 126617684..399d28651 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -80,12 +80,9 @@ <% @poll.questions.map(&:question_answers).flatten.each do |answer| %>
    -

    <%= answer.title %>

    <% if answer.description.present? %> -
    - <%= safe_html_with_links simple_format(answer.description) %> -
    +

    <%= answer.title %>

    <% end %> <% if answer.images.any? %> @@ -112,19 +109,19 @@ <% end %> <% if answer.documents.present? %> - <% end %>
    <% end %> From 8b2f6d454c302401f3a14fbbbcd916327a2d303a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Sat, 7 Oct 2017 17:33:27 +0200 Subject: [PATCH 82/91] Show poll answers in poll show view after voting on a booth If the user votes in a booth, it can see the poll and answers but can't see what he/she voted and the answers are inactive (no link, inactive ui style). --- app/views/polls/questions/_answers.html.erb | 6 +++--- app/views/polls/show.html.erb | 6 +++--- spec/features/polls/polls_spec.rb | 12 ++++++++---- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/app/views/polls/questions/_answers.html.erb b/app/views/polls/questions/_answers.html.erb index 7cdb50cfb..7d9bc4cac 100644 --- a/app/views/polls/questions/_answers.html.erb +++ b/app/views/polls/questions/_answers.html.erb @@ -1,8 +1,8 @@
    - <% if can?(:answer, question) %> + <% if can?(:answer, question) && !question.poll.voted_in_booth?(current_user) %> <% question.question_answers.each do |answer| %> - <% if @answers_by_question_id[question.id] == answer.title && - (!voted_before_sign_in(question) || + <% if @answers_by_question_id[question.id] == answer.title && + (!voted_before_sign_in(question) || question.poll.voted_in_booth?(current_user)) %> "> diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index 126617684..80d8db60e 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -50,10 +50,10 @@ <%= t("polls.show.already_voted_in_web") %>
    <% end %> + <% end %> - <% @questions.each do |question| %> - <%= render 'polls/questions/question', question: question, token: @token %> - <% end %> + <% @questions.each do |question| %> + <%= render 'polls/questions/question', question: question, token: @token %> <% end %>
    diff --git a/spec/features/polls/polls_spec.rb b/spec/features/polls/polls_spec.rb index 8f7a9b2de..d2be04447 100644 --- a/spec/features/polls/polls_spec.rb +++ b/spec/features/polls/polls_spec.rb @@ -319,10 +319,14 @@ feature 'Polls' do visit poll_path(poll) expect(page).to have_content "You have already participated in a physical booth. You can not participate again." - expect(page).to have_content('Han Solo') - expect(page).to have_content('Chewbacca') - expect(page).to_not have_link('Han Solo') - expect(page).to_not have_link('Chewbacca') + + within("#poll_question_#{question.id}_answers") do + expect(page).to have_content('Han Solo') + expect(page).to have_content('Chewbacca') + + expect(page).to_not have_link('Han Solo') + expect(page).to_not have_link('Chewbacca') + end end end From 65237db099cba57b4a928b5e23765bc053170777 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Sat, 7 Oct 2017 17:50:42 +0200 Subject: [PATCH 83/91] Fixed poll answer document upload redirect --- app/controllers/admin/poll/questions/answers_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/admin/poll/questions/answers_controller.rb b/app/controllers/admin/poll/questions/answers_controller.rb index 511807b10..51c44dd94 100644 --- a/app/controllers/admin/poll/questions/answers_controller.rb +++ b/app/controllers/admin/poll/questions/answers_controller.rb @@ -26,7 +26,7 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController def update if @answer.update(answer_params) - redirect_to admin_answer_path(@answer), + redirect_to admin_question_path(@answer.question), notice: t("flash.actions.save_changes.notice") else redirect_to :back From ca24be79e3c81a2ba36c0cf04d33a403861af148 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Sat, 7 Oct 2017 19:12:17 +0200 Subject: [PATCH 84/91] Moved token message below questions --- app/views/polls/show.html.erb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index 437328615..5ec66751c 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -39,12 +39,6 @@ <% else %> - <% if poll_voter_token(@poll, current_user).empty? %> - - <% end %> - <% if current_user && !@poll.votable_by?(current_user) %>
    <%= t("polls.show.already_voted_in_web") %> @@ -55,6 +49,12 @@ <% @questions.each do |question| %> <%= render 'polls/questions/question', question: question, token: @token %> <% end %> + + <% if poll_voter_token(@poll, current_user).empty? %> + + <% end %>
    From 728edf64a516dd2a2a95aefe1405cbeee4d977fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Sat, 7 Oct 2017 19:12:58 +0200 Subject: [PATCH 85/91] Added "participate in other polls" link in poll show --- app/views/polls/show.html.erb | 2 ++ config/locales/en/general.yml | 1 + config/locales/es/general.yml | 1 + 3 files changed, 4 insertions(+) diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index 5ec66751c..7d53fcb50 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -55,6 +55,8 @@ <%= t('poll_questions.show.voted_token') %> <% end %> + + <%= link_to t("polls.show.participate_in_other_polls"), polls_path, class: "button" %>pconfig/locales/en/general.yml diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index 297ec276a..413a6abf8 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -494,6 +494,7 @@ en: zoom_plus: Expand image read_more: "Read more about %{answer}" read_less: "Read less about %{answer}" + participate_in_other_polls: Participate in other polls poll_questions: create_question: "Create question" default_valid_answers: "Yes, No" diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index da81699d0..b8747406b 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -494,6 +494,7 @@ es: zoom_plus: Ampliar imagen read_more: "Leer más sobre %{answer}" read_less: "Leer menos sobre %{answer}" + participate_in_other_polls: Participar en otras votaciones poll_questions: create_question: "Crear pregunta para votación" default_valid_answers: "Sí, No" From 65f5c9efa94aa337af3a7a6f7f6d444207c0e402 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Sat, 7 Oct 2017 19:21:27 +0200 Subject: [PATCH 86/91] Changed token message background color --- app/assets/stylesheets/participation.scss | 6 ++++++ app/views/polls/show.html.erb | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index 605afaee8..d5af311ef 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -335,6 +335,12 @@ word-wrap: break-word; } + .callout.token-message { + background-color: #FFFFFF; + border-color: $info-border; + color: $color-info; + } + .callout.proposal-retired { font-size: $base-font-size; } diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index 7d53fcb50..44a5112b6 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -51,12 +51,12 @@ <% end %> <% if poll_voter_token(@poll, current_user).empty? %> - From b06102fb792825e422414b381b83a7a4263f61fe Mon Sep 17 00:00:00 2001 From: decabeza Date: Sat, 7 Oct 2017 19:37:51 +0200 Subject: [PATCH 87/91] adds image rendering on gallery images --- app/assets/stylesheets/participation.scss | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index 605afaee8..fc0948a28 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -1615,6 +1615,10 @@ .orbit-slide { max-height: none !important; + + img { + image-rendering: pixelated; + } } .orbit-caption { From 71d785ba788589cf6afef30f1574a85bba518e10 Mon Sep 17 00:00:00 2001 From: decabeza Date: Sat, 7 Oct 2017 19:38:17 +0200 Subject: [PATCH 88/91] improves polls index view on mobile version --- app/assets/stylesheets/participation.scss | 5 ++++- app/views/polls/_poll_group.html.erb | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index fc0948a28..9db08b7ff 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -1658,7 +1658,10 @@ .poll { &.with-image { - padding: 0 $line-height / 2 0 0; + + @include breakpoint(medium) { + padding: 0 $line-height / 2 0 0; + } img { height: 100%; diff --git a/app/views/polls/_poll_group.html.erb b/app/views/polls/_poll_group.html.erb index b9cbb3c95..529e9a99e 100644 --- a/app/views/polls/_poll_group.html.erb +++ b/app/views/polls/_poll_group.html.erb @@ -5,7 +5,7 @@ <%= t("polls.index.already_answer") %> <% end %> -
    +
    <% if poll.image.present? %> From 5b80d8893efec4b3ff9b3e25d7adc5402ca6eb33 Mon Sep 17 00:00:00 2001 From: decabeza Date: Sat, 7 Oct 2017 19:38:44 +0200 Subject: [PATCH 89/91] shows always orbit next and previous arrows --- app/assets/stylesheets/participation.scss | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index 9db08b7ff..c23ea5b6c 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -1626,6 +1626,11 @@ color: $text; } +.orbit-next, +.orbit-previous { + background: rgba(34, 34, 34, 0.25); +} + .zoom-link { background: #fff; border-radius: rem-calc(48); From 63ffb1adca2253553e87b08957117e00e327712b Mon Sep 17 00:00:00 2001 From: decabeza Date: Sat, 7 Oct 2017 19:39:04 +0200 Subject: [PATCH 90/91] hides zoom icon on mobile version --- app/views/polls/_gallery.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/polls/_gallery.html.erb b/app/views/polls/_gallery.html.erb index 45408c0da..4e234f7fc 100644 --- a/app/views/polls/_gallery.html.erb +++ b/app/views/polls/_gallery.html.erb @@ -1,5 +1,5 @@
    - + <%= t("polls.show.zoom_plus") %> From 316ba37d91c19588ed25dc68ec5b3ceab30f4512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Sat, 7 Oct 2017 20:27:44 +0200 Subject: [PATCH 91/91] Requested changes --- app/assets/stylesheets/participation.scss | 16 +++++++++------- app/views/polls/show.html.erb | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index d5af311ef..5753fb7f5 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -335,14 +335,16 @@ word-wrap: break-word; } - .callout.token-message { - background-color: #FFFFFF; - border-color: $info-border; - color: $color-info; - } + .callout { + &.token-message { + background-color: #fff; + border-color: $info-border; + color: $color-info; + } - .callout.proposal-retired { - font-size: $base-font-size; + &.proposal-retired { + font-size: $base-font-size; + } } .social-share-full .social-share-button { diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index 44a5112b6..19daf5e35 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -56,7 +56,7 @@
    <% end %> - <%= link_to t("polls.show.participate_in_other_polls"), polls_path, class: "button" %> + <%= link_to t("polls.show.participate_in_other_polls"), polls_path, class: "button hollow" %>
    + <%= t('admin.questions.show.valid_answers') %> <%= link_to t("admin.questions.show.add_answer"), new_admin_question_answer_path(@question), @@ -47,7 +47,7 @@ <% @question.question_answers.each do |answer| %>
    <%= answer.title %><%= link_to answer.title, admin_answer_path(answer) %> <%= answer.description %> (<%= answer.images.count %>)
    diff --git a/config/locales/en/activerecord.yml b/config/locales/en/activerecord.yml index 5ef1917d3..78435aa58 100644 --- a/config/locales/en/activerecord.yml +++ b/config/locales/en/activerecord.yml @@ -213,9 +213,9 @@ en: image: title: Title attachment: Attachment - poll/question_answer: - title: "Answer" - description: "Description" + poll/question/answer: + title: Answer + description: Description errors: models: user: diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 02d8bacdd..b2b6aca3a 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -609,7 +609,14 @@ en: images_list: Images list answers: new: - title: "New answer" + title: New answer + show: + title: Title + description: Description + images: Images + images_list: Images list + edit: + title: Edit answer recounts: index: title: "Recounts" diff --git a/config/locales/es/activerecord.yml b/config/locales/es/activerecord.yml index 9b3260680..03bcdfc60 100644 --- a/config/locales/es/activerecord.yml +++ b/config/locales/es/activerecord.yml @@ -207,9 +207,9 @@ es: image: title: Título attachment: Archivo adjunto - poll/question_answer: - title: "Respuesta" - description: "Descripción" + poll/question/answer: + title: Respuesta + description: Descripción errors: models: user: diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 9e0de770e..d2b405fe7 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -611,9 +611,16 @@ es: images_list: Lista de imágenes answers: new: - title: "Nueva respuesta" + title: Nueva respuesta video_url: Video externo documents: Documentos (1) + show: + title: Título + description: Descripción + images: Imágenes + images_list: Lista de imágenes + edit: + title: Editar respuesta recounts: index: title: "Recuentos" diff --git a/config/locales/fr/activerecord.yml b/config/locales/fr/activerecord.yml index d6ab5db80..59350d85d 100644 --- a/config/locales/fr/activerecord.yml +++ b/config/locales/fr/activerecord.yml @@ -147,9 +147,9 @@ fr: name: Nom locale: Langue body: Contenu - poll/question_answer: - title: "Réponse" - description: "Description" + poll/question/answer: + title: Réponse + description: Description errors: models: user: diff --git a/config/locales/fr/admin.yml b/config/locales/fr/admin.yml index e000c8a28..df288a934 100644 --- a/config/locales/fr/admin.yml +++ b/config/locales/fr/admin.yml @@ -387,8 +387,15 @@ fr: description: Description preview: Voir l'aperçu answers: + show: + title: Titre + description: Description + images: Images + images_list: Liste des images new: - title: "Nouvelle réponse" + title: Nouvelle réponse + edit: + title: Modifier réponse recounts: index: title: "Dépouillements" diff --git a/config/routes.rb b/config/routes.rb index 387983d4b..3a8f4b9cd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -301,7 +301,7 @@ Rails.application.routes.draw do end resources :questions do - resources :answers, only: [:new, :create], controller: 'questions/answers', shallow: true do + resources :answers, except: [:index, :destroy, :delete], controller: 'questions/answers', shallow: true do resources :images, controller: 'questions/answers/images' end diff --git a/spec/features/admin/poll/questions/answers/answers_spec.rb b/spec/features/admin/poll/questions/answers/answers_spec.rb new file mode 100644 index 000000000..b3b3ad420 --- /dev/null +++ b/spec/features/admin/poll/questions/answers/answers_spec.rb @@ -0,0 +1,51 @@ +require 'rails_helper' + +feature 'Answers' do + + background do + admin = create(:administrator) + login_as (admin.user) + end + + scenario 'Create' do + question = create(:poll_question) + title = 'Whatever the question may be, the answer is always 42' + description = "The Hitchhiker's Guide To The Universe" + + visit admin_question_path(question) + click_link 'Add answer' + + fill_in 'poll_question_answer_title', with: title + fill_in 'poll_question_answer_description', with: description + + click_button 'Save' + + expect(page).to have_content(title) + expect(page).to have_content(description) + end + + scenario 'Update' do + question = create(:poll_question) + answer = create(:poll_question_answer, question: question) + + visit admin_answer_path(answer) + + click_link 'Edit' + + old_title = answer.title + new_title = 'Ex Machina' + + fill_in 'poll_question_answer_title', with: new_title + + click_button 'Save' + + expect(page).to have_content('Changes saved') + expect(page).to have_content(new_title) + + visit admin_question_path(question) + + expect(page).to have_content(new_title) + expect(page).to_not have_content(old_title) + end + +end From 47ee8a2f79ca504be9df8e2b02349033378185a5 Mon Sep 17 00:00:00 2001 From: decabeza Date: Fri, 6 Oct 2017 16:19:55 +0200 Subject: [PATCH 36/91] shows answer title on polls show only if description is present --- app/views/polls/show.html.erb | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index b632fac55..914c39d85 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -60,25 +60,28 @@
    -
    +
    <% @poll.questions.map(&:question_answers).flatten.each do |answer| %>
    + data-toggler=".medium-6" data-equalizer-watch> -

    <%= answer.title %>

    + <% if answer.description.present? %> +

    <%= answer.title %>

    + <% end %> <% if answer.images.any? %> <%= render "gallery", answer: answer %> <% end %> -
    - <%= safe_html_with_links simple_format(answer.description) %> -
    + <% if answer.description.present? %> +
    + <%= safe_html_with_links simple_format(answer.description) %> +
    + <% end %>
    <% end %>
    -
    From 1933cf62faab0e057b439496fd2842aa9e3bbd31 Mon Sep 17 00:00:00 2001 From: decabeza Date: Fri, 6 Oct 2017 16:44:26 +0200 Subject: [PATCH 37/91] changes gallery order images --- app/views/polls/_gallery.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/polls/_gallery.html.erb b/app/views/polls/_gallery.html.erb index ba6cfc2e6..d71b6dcfe 100644 --- a/app/views/polls/_gallery.html.erb +++ b/app/views/polls/_gallery.html.erb @@ -16,7 +16,7 @@ - <% answer.images.each_with_index do |image, index| %> + <% answer.images.reverse.each_with_index do |image, index| %>
  • <%= link_to image.attachment.url(:original), target: "_blank" do %> <%= image_tag image.attachment.url(:medium), From 225ede4a42e5db1ea44703ae00132420182316c8 Mon Sep 17 00:00:00 2001 From: decabeza Date: Fri, 6 Oct 2017 16:58:49 +0200 Subject: [PATCH 38/91] hides temporally documents sidebar on polls show --- app/views/polls/show.html.erb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index 914c39d85..b69073cb8 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -52,10 +52,12 @@ <%= safe_html_with_links simple_format(@poll.description) %> - + <% end %> From 23682fadd87910226136c5ce2cf55fa2ab2b0981 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Fri, 6 Oct 2017 17:50:41 +0200 Subject: [PATCH 39/91] fixes document specs --- app/models/direct_upload.rb | 2 +- spec/shared/features/nested_documentable.rb | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/models/direct_upload.rb b/app/models/direct_upload.rb index 85d397706..e597f9f12 100644 --- a/app/models/direct_upload.rb +++ b/app/models/direct_upload.rb @@ -21,7 +21,7 @@ class DirectUpload #Refactor if @resource.respond_to?(:images) && - (@attachment.present? && !@attachment.content_type.match(/pdf/)) || @cached_attachment.present? + ((@attachment.present? && !@attachment.content_type.match(/pdf/)) || @cached_attachment.present?) @relation = @resource.images.send("build", relation_attributtes) elsif @resource.class.reflections[@resource_relation].macro == :has_one @relation = @resource.send("build_#{resource_relation}", relation_attributtes) diff --git a/spec/shared/features/nested_documentable.rb b/spec/shared/features/nested_documentable.rb index 3e87c4021..24d6631a8 100644 --- a/spec/shared/features/nested_documentable.rb +++ b/spec/shared/features/nested_documentable.rb @@ -191,10 +191,17 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na documentable_attach_new_file(documentable_factory_name, 0, "spec/fixtures/files/empty.pdf") click_on submit_button + documentable_redirected_to_resource_show_or_navigate_to expect(page).to have_content "Documents" - expect(page).to have_link "empty.pdf" + + find("#tab-documents-label").click + expect(page).to have_content "empty.pdf" + + #Review + #Doble check why the file is stored with a name different to empty.pdf + expect(page).to have_css("a[href$='.pdf']") end scenario "Should show resource with new document after successful creation with maximum allowed uploaded files", :js do From 5c2784794f7586bd8c2f8282a204b1da377afc6a Mon Sep 17 00:00:00 2001 From: decabeza Date: Fri, 6 Oct 2017 18:04:15 +0200 Subject: [PATCH 40/91] changes medium to large size on gallery images --- app/views/polls/_gallery.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/polls/_gallery.html.erb b/app/views/polls/_gallery.html.erb index d71b6dcfe..d3da43b88 100644 --- a/app/views/polls/_gallery.html.erb +++ b/app/views/polls/_gallery.html.erb @@ -19,7 +19,7 @@ <% answer.images.reverse.each_with_index do |image, index| %>
  • <%= link_to image.attachment.url(:original), target: "_blank" do %> - <%= image_tag image.attachment.url(:medium), + <%= image_tag image.attachment.url(:large), class: "orbit-image", alt: image.title %> <% end %> From dcc5ebf5309c70e9734dfc13e0f1220c66752cca Mon Sep 17 00:00:00 2001 From: decabeza Date: Fri, 6 Oct 2017 18:09:05 +0200 Subject: [PATCH 41/91] removes data equalizer to avoid big scrolls --- app/views/polls/show.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index 5d02aa891..1eb128333 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -67,11 +67,11 @@
    -
    +
    <% @poll.questions.map(&:question_answers).flatten.each do |answer| %>
    + data-toggler=".medium-6"> <% if answer.description.present? %>

    <%= answer.title %>

    From 59175ff0394b9dae229a548e9227ea4b423ee95b Mon Sep 17 00:00:00 2001 From: Bertocq Date: Fri, 6 Oct 2017 18:36:19 +0200 Subject: [PATCH 42/91] Add date on officer assignment list for final shifts --- app/views/admin/poll/officer_assignments/by_officer.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/poll/officer_assignments/by_officer.html.erb b/app/views/admin/poll/officer_assignments/by_officer.html.erb index c9873db96..c6738eba0 100644 --- a/app/views/admin/poll/officer_assignments/by_officer.html.erb +++ b/app/views/admin/poll/officer_assignments/by_officer.html.erb @@ -21,7 +21,7 @@
  • <%= officer_assignment.final? ? t('polls.final_date') : l(officer_assignment.date.to_date) %><%= l(officer_assignment.date.to_date)%> <%= content_tag :strong, t('polls.final_date') if officer_assignment.final %> <%= booth_name_with_location(officer_assignment.booth_assignment.booth) %>
    <%= link_to document.title, + document.attachment.url, + target: "_blank", + rel: "nofollow" %>
    - <%= link_to t("admin.questions.show.answers.video_list", - count: answer.videos.count), + (<%= answer.videos.count %>) +
    + <%= link_to t("admin.questions.show.answers.video_list"), admin_answer_videos_path(answer) %>