Sha256: 2eb004d5bccae4775d64477bbc98709436e1a8814f007ed7e6888460126d3ef1

Contents?: true

Size: 1.23 KB

Versions: 51

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

module Decidim
  class FollowsController < Decidim::ApplicationController
    include FormFactory
    before_action :authenticate_user!
    helper_method :resource

    def destroy
      @form = form(Decidim::FollowForm).from_params(params)
      @inline = params[:follow][:inline] == "true"
      enforce_permission_to :delete, :follow, follow: @form.follow

      DeleteFollow.call(@form, current_user) do
        on(:ok) do
          render :update_button
        end

        on(:invalid) do
          render json: { error: I18n.t("follows.destroy.error", scope: "decidim") }, status: :unprocessable_entity
        end
      end
    end

    def create
      @form = form(Decidim::FollowForm).from_params(params)
      @inline = params[:follow][:inline] == "true"
      enforce_permission_to :create, :follow

      CreateFollow.call(@form, current_user) do
        on(:ok) do
          render :update_button
        end

        on(:invalid) do
          render json: { error: I18n.t("follows.create.error", scope: "decidim") }, status: :unprocessable_entity
        end
      end
    end

    def resource
      @resource ||= GlobalID::Locator.locate_signed(
        params[:follow][:followable_gid]
      )
    end
  end
end

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
decidim-core-0.23.3 app/controllers/decidim/follows_controller.rb
decidim-core-0.23.2 app/controllers/decidim/follows_controller.rb
decidim-core-0.23.1 app/controllers/decidim/follows_controller.rb
decidim-core-0.23.1.rc1 app/controllers/decidim/follows_controller.rb
decidim-core-0.23.0 app/controllers/decidim/follows_controller.rb
decidim-core-0.22.0 app/controllers/decidim/follows_controller.rb
decidim-core-0.21.0 app/controllers/decidim/follows_controller.rb
decidim-core-0.20.1 app/controllers/decidim/follows_controller.rb
decidim-core-0.20.0 app/controllers/decidim/follows_controller.rb
decidim-core-0.19.1 app/controllers/decidim/follows_controller.rb
decidim-core-0.19.0 app/controllers/decidim/follows_controller.rb