Module: Decidim::EndorsableHelper
- Included in:
- EndorsementButtonsCell, EndorsementsController
- Defined in:
- app/helpers/decidim/endorsable_helper.rb
Overview
A Helper for views with Endorsable resources.
Instance Method Summary collapse
-
#current_user_can_endorse? ⇒ Boolean
Public: Checks if the current user is allowed to endorse in this step.
-
#endorsement_buttons_cell(resource) ⇒ Object
Invokes the decidim/endorsement_buttons cell.
-
#endorsements_blocked? ⇒ Boolean
Public: Checks if endorsements are blocked in this step.
-
#endorsements_enabled? ⇒ Boolean
Public: Checks if endorsement are enabled in this step.
-
#endorsers_list_cell(resource) ⇒ Object
Invokes the decidim/endorsers_list cell.
-
#fully_endorsed?(resource, user) ⇒ Boolean
Public: Checks if the given resource has been endorsed by all identities of the user.
-
#path_to_create_endorsement(resource, user_group = nil) ⇒ Object
produces the path that should be POST to create an endorsement.
-
#path_to_destroy_endorsement(resource, user_group = nil) ⇒ Object
Produces the path that should be DELETE to destroy an endorsement.
-
#render_endorsement_identity(resource, user, user_group = nil) ⇒ Object
Renders an identity for endorsement.
-
#show_endorsements_card? ⇒ Boolean
Public: Checks if the card for endorsements should be rendered.
Instance Method Details
#current_user_can_endorse? ⇒ Boolean
Public: Checks if the current user is allowed to endorse in this step.
Returns true if the current user can endorse, false otherwise.
47 48 49 |
# File 'app/helpers/decidim/endorsable_helper.rb', line 47 def current_user_can_endorse? current_user && endorsements_enabled? && !endorsements_blocked? end |
#endorsement_buttons_cell(resource) ⇒ Object
Invokes the decidim/endorsement_buttons cell.
7 8 9 |
# File 'app/helpers/decidim/endorsable_helper.rb', line 7 def (resource) cell("decidim/endorsement_block", resource) end |
#endorsements_blocked? ⇒ Boolean
Public: Checks if endorsements are blocked in this step.
Returns true if blocked, false otherwise.
40 41 42 |
# File 'app/helpers/decidim/endorsable_helper.rb', line 40 def endorsements_blocked? current_settings.endorsements_blocked end |
#endorsements_enabled? ⇒ Boolean
Public: Checks if endorsement are enabled in this step.
Returns true if enabled, false otherwise.
33 34 35 |
# File 'app/helpers/decidim/endorsable_helper.rb', line 33 def endorsements_enabled? current_settings.endorsements_enabled end |
#endorsers_list_cell(resource) ⇒ Object
Invokes the decidim/endorsers_list cell.
12 13 14 |
# File 'app/helpers/decidim/endorsable_helper.rb', line 12 def endorsers_list_cell(resource) cell("decidim/endorsers_list", resource) end |
#fully_endorsed?(resource, user) ⇒ Boolean
Public: Checks if the given resource has been endorsed by all identities of the user.
22 23 24 25 26 27 28 |
# File 'app/helpers/decidim/endorsable_helper.rb', line 22 def fully_endorsed?(resource, user) return false unless user user_group_endorsements = Decidim::UserGroups::ManageableUserGroups.for(user).verified.all? { |user_group| resource.endorsed_by?(user, user_group) } user_group_endorsements && resource.endorsed_by?(user) end |
#path_to_create_endorsement(resource, user_group = nil) ⇒ Object
produces the path that should be POST to create an endorsement
59 60 61 62 63 |
# File 'app/helpers/decidim/endorsable_helper.rb', line 59 def path_to_create_endorsement(resource, user_group = nil) endorsements_path(resource_id: resource.to_gid.to_param, user_group_id: user_group&.id, authenticity_token: form_authenticity_token) end |
#path_to_destroy_endorsement(resource, user_group = nil) ⇒ Object
Produces the path that should be DELETE to destroy an endorsement.
66 67 68 69 70 |
# File 'app/helpers/decidim/endorsable_helper.rb', line 66 def path_to_destroy_endorsement(resource, user_group = nil) endorsement_path(resource.to_gid.to_param, user_group_id: user_group&.id, authenticity_token: form_authenticity_token) end |
#render_endorsement_identity(resource, user, user_group = nil) ⇒ Object
Renders an identity for endorsement.
Parameters:
resources - The endorsable resource.
user - The user that is endorsing at the end (mandatory).
user_group - The user_group on behalf of which the endorsement is being done (optional).
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/helpers/decidim/endorsable_helper.rb', line 78 def render_endorsement_identity(resource, user, user_group = nil) if user_group presenter = Decidim::UserGroupPresenter.new(user_group) selected = resource.endorsed_by?(user, user_group) else presenter = Decidim::UserPresenter.new(user) selected = resource.endorsed_by?(user) end http_method = selected ? :delete : :post render partial: "decidim/endorsements/identity", locals: { identity: presenter, selected:, http_method:, create_url: path_to_create_endorsement(resource, user_group), destroy_url: path_to_destroy_endorsement(resource, user_group) } end |
#show_endorsements_card? ⇒ Boolean
Public: Checks if the card for endorsements should be rendered.
Returns true if the endorsements card should be rendered, false otherwise.
54 55 56 |
# File 'app/helpers/decidim/endorsable_helper.rb', line 54 def show_endorsements_card? endorsements_enabled? end |