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-0.6.8 decidim-core/app/controllers/decidim/follows_controller.rb
decidim-core-0.6.7 app/controllers/decidim/follows_controller.rb
decidim-0.6.7 decidim-core/app/controllers/decidim/follows_controller.rb
decidim-core-0.6.6 app/controllers/decidim/follows_controller.rb
decidim-0.6.6 decidim-core/app/controllers/decidim/follows_controller.rb
decidim-core-0.6.5 app/controllers/decidim/follows_controller.rb
decidim-0.6.5 decidim-core/app/controllers/decidim/follows_controller.rb
decidim-core-0.6.4 app/controllers/decidim/follows_controller.rb
decidim-0.6.4 decidim-core/app/controllers/decidim/follows_controller.rb
decidim-core-0.6.3 app/controllers/decidim/follows_controller.rb
decidim-0.6.3 decidim-core/app/controllers/decidim/follows_controller.rb
decidim-core-0.6.2 app/controllers/decidim/follows_controller.rb
decidim-0.6.2 decidim-core/app/controllers/decidim/follows_controller.rb
decidim-core-0.6.1 app/controllers/decidim/follows_controller.rb
decidim-0.6.1 decidim-core/app/controllers/decidim/follows_controller.rb
decidim-core-0.6.0 app/controllers/decidim/follows_controller.rb
decidim-0.6.0 decidim-core/app/controllers/decidim/follows_controller.rb