Class: Decidim::ReportingProposals::Admin::ProposalsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/decidim/reporting_proposals/admin/proposals_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#permission_class_chain

Instance Method Details

#add_photosObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/decidim/reporting_proposals/admin/proposals_controller.rb', line 22

def add_photos
  enforce_permission_to(:edit_photos, :proposals, proposal:)

  @photo_form = form(Decidim::ReportingProposals::Admin::ProposalPhotoForm).from_params(params, current_component: proposal.component)

  Decidim::ReportingProposals::Admin::UpdateProposal.call(@photo_form, proposal) do
    on(:ok) do |_proposal|
      flash[:notice] = t("proposals.update.success", scope: "decidim")
    end

    on(:invalid) do
      flash[:alert] = t("proposals.update.error", scope: "decidim")
    end
  end
  redirect_to Decidim::ResourceLocatorPresenter.new(proposal).show
end

#hide_proposalObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/decidim/reporting_proposals/admin/proposals_controller.rb', line 7

def hide_proposal
  enforce_permission_to(:hide_proposal, :proposals, proposal:)

  Decidim::Admin::HideResource.call(proposal, current_user) do
    on(:ok) do
      flash[:notice] = I18n.t("reportable.hide.success", scope: "decidim.moderations.admin")
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("reportable.hide.invalid", scope: "decidim.moderations.admin")
    end
  end
  redirect_back(fallback_location: decidim_admin.root_path)
end

#remove_photoObject



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/decidim/reporting_proposals/admin/proposals_controller.rb', line 39

def remove_photo
  enforce_permission_to(:edit_photos, :proposals, proposal:)

  attachment = proposal.attachments.find_by(id: params[:photo_id])
  if attachment.try(:photo?)
    attachment.destroy!
    flash[:notice] = t("proposals.update.success", scope: "decidim")
  else
    flash[:alert] = t("proposals.update.error", scope: "decidim")
  end

  redirect_to Decidim::ResourceLocatorPresenter.new(proposal).show
end