diff --git a/app/controllers/admin/poll/questions/answers/images_controller.rb b/app/controllers/admin/poll/questions/answers/images_controller.rb index f91389daa..a209b058f 100644 --- a/app/controllers/admin/poll/questions/answers/images_controller.rb +++ b/app/controllers/admin/poll/questions/answers/images_controller.rb @@ -1,7 +1,7 @@ class Admin::Poll::Questions::Answers::ImagesController < Admin::Poll::BaseController include ImageAttributes - before_action :load_answer, except: :destroy + load_and_authorize_resource :answer, class: "::Poll::Question::Answer" def index end @@ -38,8 +38,4 @@ class Admin::Poll::Questions::Answers::ImagesController < Admin::Poll::BaseContr def allowed_params [:answer_id, images_attributes: image_attributes] end - - def load_answer - @answer = ::Poll::Question::Answer.find(params[:answer_id]) - end end diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb index 57cef7552..e9a455c3c 100644 --- a/app/models/abilities/administrator.rb +++ b/app/models/abilities/administrator.rb @@ -92,6 +92,9 @@ module Abilities can :destroy, Poll::Question can :manage, Poll::Question::Answer can :manage, Poll::Question::Answer::Video + can [:create, :destroy], Image do |image| + image.imageable_type == "Poll::Question::Answer" + end can :manage, SiteCustomization::Page can :manage, SiteCustomization::Image diff --git a/app/views/admin/poll/questions/answers/images/new.html.erb b/app/views/admin/poll/questions/answers/images/new.html.erb index 0ba27107b..e4ddaa769 100644 --- a/app/views/admin/poll/questions/answers/images/new.html.erb +++ b/app/views/admin/poll/questions/answers/images/new.html.erb @@ -1,7 +1,5 @@
- <%= form_for(@answer, - url: admin_answer_images_path(@answer), - method: :post) do |f| %> + <%= form_for(@answer, url: admin_answer_images_path(@answer), method: :post) do |f| %> <%= render "shared/errors", resource: @answer %>
diff --git a/spec/models/abilities/administrator_spec.rb b/spec/models/abilities/administrator_spec.rb index 6ba8c79ff..72e1722ee 100644 --- a/spec/models/abilities/administrator_spec.rb +++ b/spec/models/abilities/administrator_spec.rb @@ -18,6 +18,8 @@ describe Abilities::Administrator do let(:legislation_question) { create(:legislation_question) } let(:poll) { create(:poll) } let(:poll_question) { create(:poll_question) } + let(:poll_question_answer) { create(:poll_question_answer) } + let(:answer_image) { build(:image, imageable: poll_question_answer) } let(:past_process) { create(:legislation_process, :past) } let(:past_draft_process) { create(:legislation_process, :past, :not_published) } @@ -118,6 +120,9 @@ describe Abilities::Administrator do it { should be_able_to(:manage, Poll::Question::Answer::Video) } + it { should be_able_to(:create, answer_image) } + it { should be_able_to(:destroy, answer_image) } + it { is_expected.to be_able_to :manage, Dashboard::AdministratorTask } it { is_expected.to be_able_to :manage, dashboard_administrator_task }