Class: Decidim::FollowsController

Inherits:
ApplicationController show all
Includes:
FormFactory
Defined in:
decidim-core/app/controllers/decidim/follows_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#store_share_token

Methods included from UserBlockedChecker

#check_user_block_status, #check_user_not_blocked

Methods included from NeedsSnippets

#snippets

Methods included from Headers::HttpCachingDisabler

#disable_http_caching

Methods included from HasStoredPath

#skip_store_location?, #store_current_location

Methods included from TranslatableAttributes

#default_locale?

Methods included from RegistersPermissions

register_permissions

Methods included from NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#button_cellObject



53
54
55
# File 'decidim-core/app/controllers/decidim/follows_controller.rb', line 53

def button_cell
  @button_cell ||= cell("decidim/follow_button", resource, **button_options)
end

#button_cell_mobileObject



49
50
51
# File 'decidim-core/app/controllers/decidim/follows_controller.rb', line 49

def button_cell_mobile
  @button_cell_mobile ||= cell("decidim/follow_button", resource, **button_options.merge(mobile: true))
end

#button_optionsObject



45
46
47
# File 'decidim-core/app/controllers/decidim/follows_controller.rb', line 45

def button_options
  params.require(:follow).permit(:button_classes).to_h.symbolize_keys
end

#createObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'decidim-core/app/controllers/decidim/follows_controller.rb', line 24

def create
  @form = form(Decidim::FollowForm).from_params(params)
  enforce_permission_to :create, :follow

  CreateFollow.call(@form) 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

#destroyObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'decidim-core/app/controllers/decidim/follows_controller.rb', line 9

def destroy
  @form = form(Decidim::FollowForm).from_params(params)
  enforce_permission_to :delete, :follow, follow: @form.follow

  DeleteFollow.call(@form) 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

#resourceObject



39
40
41
42
43
# File 'decidim-core/app/controllers/decidim/follows_controller.rb', line 39

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