Class: Decidim::EndorsementsController

Inherits:
Components::BaseController show all
Includes:
EndorsableHelper
Defined in:
decidim-core/app/controllers/decidim/endorsements_controller.rb

Overview

Exposes the `Endorsements` so that users can endorse resources.

Instance Method Summary collapse

Methods included from EndorsableHelper

#current_user_can_endorse?, #endorsement_buttons_cell, #endorsements_blocked?, #endorsements_enabled?, #endorsers_list_cell, #fully_endorsed?, #path_to_create_endorsement, #path_to_destroy_endorsement, #render_endorsement_identity, #show_endorsements_card?

Methods inherited from Components::BaseController

#current_manifest, #permission_class_chain, #permission_scope, #redirect_unless_feature_private, #share_token

Methods included from RegistersPermissions

register_permissions

Methods included from UserBlockedChecker

#check_user_block_status, #check_user_not_blocked

Methods included from NeedsSnippets

#snippets

Methods included from HttpCachingDisabler

#disable_http_caching

Methods included from HasStoredPath

#skip_store_location?, #store_current_location

Methods included from NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#createObject


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'decidim-core/app/controllers/decidim/endorsements_controller.rb', line 15

def create
  enforce_permission_to :create, :endorsement, resource: resource
  user_group_id = params[:user_group_id]

  EndorseResource.call(resource, current_user, user_group_id) do
    on(:ok) do
      resource.reload
      render :update_buttons_and_counters
    end

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

#current_componentObject

should be pubic in order to be visibe in NeedsPermission#permissions_context


52
53
54
# File 'decidim-core/app/controllers/decidim/endorsements_controller.rb', line 52

def current_component
  resource.component
end

#destroyObject


31
32
33
34
35
36
37
38
39
40
41
42
# File 'decidim-core/app/controllers/decidim/endorsements_controller.rb', line 31

def destroy
  enforce_permission_to :withdraw, :endorsement, resource: resource
  user_group_id = params[:user_group_id]
  user_group = user_groups.find(user_group_id) if user_group_id

  UnendorseResource.call(resource, current_user, user_group) do
    on(:ok) do
      resource.reload
      render :update_buttons_and_counters
    end
  end
end

#identitiesObject


44
45
46
47
48
49
# File 'decidim-core/app/controllers/decidim/endorsements_controller.rb', line 44

def identities
  enforce_permission_to :create, :endorsement, resource: resource

  @user_verified_groups = Decidim::UserGroups::ManageableUserGroups.for(current_user).verified
  render :identities, layout: false
end