Sha256: db8b0fa23b8c4300f0404513a7e0e74576535f0e07d6deb02ffb1f467bc913a1

Contents?: true

Size: 1.06 KB

Versions: 37

Compression:

Stored size: 1.06 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)
      authorize! :delete, @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: 422
        end
      end
    end

    def create
      @form = form(Decidim::FollowForm).from_params(params)
      authorize! :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: 422
        end
      end
    end

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

Version data entries

37 entries across 37 versions & 2 rubygems

Version Path
decidim-core-0.11.2 app/controllers/decidim/follows_controller.rb
decidim-core-0.11.1 app/controllers/decidim/follows_controller.rb
decidim-core-0.11.0.pre1 app/controllers/decidim/follows_controller.rb
decidim-core-0.10.1 app/controllers/decidim/follows_controller.rb
decidim-core-0.10.0 app/controllers/decidim/follows_controller.rb
decidim-core-0.9.3 app/controllers/decidim/follows_controller.rb
decidim-core-0.9.2 app/controllers/decidim/follows_controller.rb
decidim-core-0.9.1 app/controllers/decidim/follows_controller.rb
decidim-core-0.9.0 app/controllers/decidim/follows_controller.rb
decidim-core-0.8.4 app/controllers/decidim/follows_controller.rb
decidim-core-0.8.3 app/controllers/decidim/follows_controller.rb
decidim-core-0.8.2 app/controllers/decidim/follows_controller.rb
decidim-core-0.8.1 app/controllers/decidim/follows_controller.rb
decidim-core-0.8.0 app/controllers/decidim/follows_controller.rb
decidim-core-0.7.4 app/controllers/decidim/follows_controller.rb
decidim-core-0.7.3 app/controllers/decidim/follows_controller.rb
decidim-core-0.7.2 app/controllers/decidim/follows_controller.rb
decidim-core-0.7.1 app/controllers/decidim/follows_controller.rb
decidim-core-0.7.0 app/controllers/decidim/follows_controller.rb
decidim-core-0.6.8 app/controllers/decidim/follows_controller.rb