Add load_and_authorize_resource to images controller
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
<div class="poll-question-form">
|
||||
<%= 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 %>
|
||||
|
||||
<div class="images">
|
||||
|
||||
@@ -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 }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user