diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss
index e10c0327f..3c37e9657 100644
--- a/app/assets/stylesheets/participation.scss
+++ b/app/assets/stylesheets/participation.scss
@@ -314,6 +314,7 @@
.debate-show,
.proposal-show,
+.poll-question-show,
.investment-project-show,
.budget-investment-show,
.polls-show,
diff --git a/app/controllers/admin/poll/questions_controller.rb b/app/controllers/admin/poll/questions_controller.rb
index ab7297a95..3bbe1c395 100644
--- a/app/controllers/admin/poll/questions_controller.rb
+++ b/app/controllers/admin/poll/questions_controller.rb
@@ -1,4 +1,6 @@
class Admin::Poll::QuestionsController < Admin::BaseController
+ include CommentableActions
+
load_and_authorize_resource :poll
load_and_authorize_resource :question, class: 'Poll::Question'
@@ -20,6 +22,7 @@ class Admin::Poll::QuestionsController < Admin::BaseController
def create
@question.author = @question.proposal.try(:author) || current_user
+ recover_documents_from_cache(@question)
if @question.save
redirect_to admin_question_path(@question)
@@ -29,6 +32,7 @@ class Admin::Poll::QuestionsController < Admin::BaseController
end
def show
+ @document = Document.new(documentable: @question)
end
def edit
@@ -54,7 +58,8 @@ class Admin::Poll::QuestionsController < Admin::BaseController
private
def question_params
- params.require(:poll_question).permit(:poll_id, :title, :question, :description, :proposal_id, :valid_answers)
+ params.require(:poll_question).permit(:poll_id, :title, :question, :description, :proposal_id, :valid_answers, :video_url,
+ documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id])
end
def search_params
diff --git a/app/controllers/polls/questions_controller.rb b/app/controllers/polls/questions_controller.rb
index 1849dff97..bb1560f54 100644
--- a/app/controllers/polls/questions_controller.rb
+++ b/app/controllers/polls/questions_controller.rb
@@ -10,6 +10,8 @@ class Polls::QuestionsController < ApplicationController
@comment_tree = CommentTree.new(@commentable, params[:page], @current_order)
set_comment_flags(@comment_tree.comments)
+ @document = Document.new(documentable: @question)
+
question_answer = @question.answers.where(author_id: current_user.try(:id)).first
@answers_by_question_id = {@question.id => question_answer.try(:answer)}
end
diff --git a/app/models/poll/question.rb b/app/models/poll/question.rb
index 28dd8ed4a..8e02dcfe2 100644
--- a/app/models/poll/question.rb
+++ b/app/models/poll/question.rb
@@ -1,6 +1,11 @@
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 959aa4ddf..2b32ed680 100644
--- a/app/views/admin/poll/questions/_form.html.erb
+++ b/app/views/admin/poll/questions/_form.html.erb
@@ -26,6 +26,17 @@
ckeditor: { language: I18n.locale } %>
+
+ <%= render 'documents/nested_documents', documentable: @question %>
+
+
+
+ <%= 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"} %>
+
+
<%= f.submit(class: "button expanded", value: t("shared.save")) %>
diff --git a/app/views/admin/poll/questions/show.html.erb b/app/views/admin/poll/questions/show.html.erb
index 3be660f79..3f776c5c0 100644
--- a/app/views/admin/poll/questions/show.html.erb
+++ b/app/views/admin/poll/questions/show.html.erb
@@ -40,6 +40,21 @@
<%= @question.description %>
+ <% if @question.video_url.present? %>
+
+ <%= t("admin.questions.show.video_url") %>
+
+ <%= @question.video_url %>
+
+ <% end %>
+
+ <% if @question.documents.any? %>
+
+ <%= t("admin.questions.show.documents") %>
+
+ <%= @question.documents.first.title %>
+
+ <% end %>
<%= link_to t("admin.questions.show.preview"), question_path(@question) %>
diff --git a/app/views/polls/questions/_filter_subnav.html.erb b/app/views/polls/questions/_filter_subnav.html.erb
new file mode 100644
index 000000000..738fc3700
--- /dev/null
+++ b/app/views/polls/questions/_filter_subnav.html.erb
@@ -0,0 +1,22 @@
+
+
+
+ -
+ <%= link_to "#tab-comments" do %>
+
+ <%= t("proposals.show.comments_tab") %>
+
+
+ <% end %>
+
+ -
+ <%= link_to "#tab-documents" do %>
+
+ <%= t("documents.tab") %>
+ (<%= @question.documents.count %>)
+
+ <% end %>
+
+
+
+
diff --git a/app/views/polls/questions/show.html.erb b/app/views/polls/questions/show.html.erb
index da46ebbcc..f67633129 100644
--- a/app/views/polls/questions/show.html.erb
+++ b/app/views/polls/questions/show.html.erb
@@ -55,6 +55,21 @@
+<% if @question.video_url.present? %>
+
+
+
+
+
+ <%= t('proposals.show.title_video_url') %>
+
+ <%= text_with_links @question.video_url %>
+
+
+
+
+<% end %>
+
<%= t('poll_questions.show.more_info') %>
@@ -62,4 +77,16 @@
-<%= render "comments" %>
+
+ <%= render "polls/questions/filter_subnav" %>
+
+
+
+
+ <%= render 'documents/documents',
+ documents: @question.documents,
+ max_documents_allowed: Poll::Question.max_documents_allowed %>
+
+
diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml
index 3e5cb9d31..3f1b12189 100644
--- a/config/locales/en/admin.yml
+++ b/config/locales/en/admin.yml
@@ -596,6 +596,8 @@ en:
title: Title
valid_answers: Valid answers
description: Description
+ video_url: External video
+ documents: Documents
preview: View on website
recounts:
index:
diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml
index 1b98adaf2..9872baa0d 100644
--- a/config/locales/es/admin.yml
+++ b/config/locales/es/admin.yml
@@ -596,6 +596,8 @@ es:
title: Título
valid_answers: Respuestas válidas
description: Descripción
+ video_url: Video externo
+ documents: Documentos
preview: Ver en la web
recounts:
index:
diff --git a/db/migrate/20170905111444_add_video_url_to_poll_questions.rb b/db/migrate/20170905111444_add_video_url_to_poll_questions.rb
new file mode 100644
index 000000000..800ca915e
--- /dev/null
+++ b/db/migrate/20170905111444_add_video_url_to_poll_questions.rb
@@ -0,0 +1,5 @@
+class AddVideoUrlToPollQuestions < ActiveRecord::Migration
+ def change
+ add_column :poll_questions, :video_url, :string
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index b87332817..9b4ffd97b 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: 20170822144743) do
+ActiveRecord::Schema.define(version: 20170905111444) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -669,6 +669,7 @@ ActiveRecord::Schema.define(version: 20170822144743) do
t.datetime "created_at"
t.datetime "updated_at"
t.tsvector "tsv"
+ t.string "video_url"
end
add_index "poll_questions", ["author_id"], name: "index_poll_questions_on_author_id", using: :btree
@@ -971,7 +972,7 @@ ActiveRecord::Schema.define(version: 20170822144743) do
t.boolean "email_digest", default: true
t.boolean "email_on_direct_message", default: true
t.boolean "official_position_badge", default: false
- t.datetime "password_changed_at", default: '2017-08-07 11:14:09', null: false
+ t.datetime "password_changed_at", default: '2017-09-06 18:19:39', null: false
t.boolean "created_from_signature", default: false
t.integer "failed_email_digests_count", default: 0
t.text "former_users_data_log", default: ""
diff --git a/spec/factories.rb b/spec/factories.rb
index 226723fe3..9cebfddea 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -380,6 +380,10 @@ FactoryGirl.define do
trait :budget_investment_document do
association :documentable, factory: :budget_investment
end
+
+ trait :poll_question_document do
+ association :documentable, factory: :poll_question
+ end
end
factory :comment do
diff --git a/spec/features/admin/poll/questions_spec.rb b/spec/features/admin/poll/questions_spec.rb
index e9b9f277a..392b2aabf 100644
--- a/spec/features/admin/poll/questions_spec.rb
+++ b/spec/features/admin/poll/questions_spec.rb
@@ -38,6 +38,7 @@ feature 'Admin poll questions' do
Pursued by the Empire's sinister agents, Princess Leia races home aboard her starship, custodian of the stolen plans that can save her
people and restore freedom to the galaxy....
}
+ video_url = "https://puppyvideos.com"
visit admin_questions_path
click_link "Create question"
@@ -45,11 +46,13 @@ feature 'Admin poll questions' do
select 'Movies', from: 'poll_question_poll_id'
fill_in 'poll_question_title', with: title
fill_in 'poll_question_description', with: description
+ fill_in 'poll_question_video_url', with: video_url
click_button 'Save'
expect(page).to have_content(title)
expect(page).to have_content(description)
+ expect(page).to have_content(video_url)
end
scenario 'Create from successful proposal index' do
diff --git a/spec/features/polls/questions_spec.rb b/spec/features/polls/questions_spec.rb
index 6f2225175..1563ca81a 100644
--- a/spec/features/polls/questions_spec.rb
+++ b/spec/features/polls/questions_spec.rb
@@ -25,6 +25,25 @@ feature 'Poll Questions' do
expect(page).to have_content(question_with_author_visible_name.author_visible_name)
end
+ scenario '#show view has video_url present' do
+ poll = create(:poll)
+ normal_question = create(:poll_question, poll: poll, video_url: "https://puppyvideos.com")
+
+ visit question_path(normal_question)
+
+ expect(page).to have_link(normal_question.video_url)
+ end
+
+ scenario '#show view has document present' do
+ poll = create(:poll)
+ normal_question = create(:poll_question, poll: poll)
+ document = create(:document, documentable: normal_question)
+
+ visit question_path(normal_question)
+
+ expect(page).to have_content(document.title)
+ end
+
context 'Answering' do
let(:geozone) { create(:geozone) }
let(:poll) { create(:poll, geozone_restricted: true, geozone_ids: [geozone.id]) }
diff --git a/spec/models/abilities/administrator_spec.rb b/spec/models/abilities/administrator_spec.rb
index bbec927a0..dcb099ecd 100644
--- a/spec/models/abilities/administrator_spec.rb
+++ b/spec/models/abilities/administrator_spec.rb
@@ -14,9 +14,11 @@ describe "Abilities::Administrator" do
let(:proposal) { create(:proposal) }
let(:budget_investment) { create(:budget_investment) }
let(:legislation_question) { create(:legislation_question) }
+ let(:poll_question) { create(:poll_question) }
let(:proposal_document) { build(:document, documentable: proposal) }
let(:budget_investment_document) { build(:document, documentable: budget_investment) }
+ let(:poll_question_document) { build(:document, documentable: poll_question) }
let(:hidden_debate) { create(:debate, :hidden) }
let(:hidden_comment) { create(:comment, :hidden) }
@@ -83,4 +85,8 @@ describe "Abilities::Administrator" do
it { should be_able_to(:new, budget_investment_document) }
it { should be_able_to(:create, budget_investment_document) }
it { should be_able_to(:destroy, budget_investment_document) }
+
+ it { should be_able_to(:new, poll_question_document) }
+ it { should be_able_to(:create, poll_question_document) }
+ it { should be_able_to(:destroy, poll_question_document) }
end