Sha256: 094a15c8700cdc475076fcc399d438d29b5ccc6e341202f9a9affd42d6dda86c

Contents?: true

Size: 1.12 KB

Versions: 6

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

module Decidim
  # Exposes the report resource so users can report a reportable.
  class ReportsController < Decidim::ApplicationController
    include FormFactory
    include NeedsPermission

    before_action :authenticate_user!

    def create
      enforce_permission_to :create, :moderation

      @form = form(Decidim::ReportForm).from_params(params, can_hide: reportable.try(:can_be_administered_by?, current_user))

      CreateReport.call(@form, reportable) do
        on(:ok) do
          flash[:notice] = I18n.t("decidim.reports.create.success")
          redirect_back fallback_location: root_path
        end

        on(:invalid) do
          flash[:alert] = I18n.t("decidim.reports.create.error")
          redirect_back fallback_location: root_path
        end
      end
    end

    private

    def reportable
      @reportable ||= GlobalID::Locator.locate_signed params[:sgid]
    end

    def permission_class_chain
      [
        reportable.participatory_space.manifest.permissions_class,
        Decidim::Permissions
      ]
    end

    def permission_scope
      :public
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
decidim-core-0.29.1 app/controllers/decidim/reports_controller.rb
decidim-core-0.29.0 app/controllers/decidim/reports_controller.rb
decidim-core-0.29.0.rc4 app/controllers/decidim/reports_controller.rb
decidim-core-0.29.0.rc3 app/controllers/decidim/reports_controller.rb
decidim-core-0.29.0.rc2 app/controllers/decidim/reports_controller.rb
decidim-core-0.29.0.rc1 app/controllers/decidim/reports_controller.rb