Module: Decidim::ActionAuthorizationHelper
- Defined in:
- app/helpers/decidim/action_authorization_helper.rb
Instance Method Summary collapse
-
#action_authorization_modal(action) ⇒ Object
Public: Renders a modal that explains why she can’t perform an action, if that’s the case.
-
#action_authorized_button_to(action, *arguments, &block) ⇒ Object
Public: Emulates a ‘button_to` but conditionally renders a popup modal blocking the action in case the user isn’t allowed to perform it.
-
#action_authorized_link_to(action, *arguments, &block) ⇒ Object
Public: Emulates a ‘link_to` but conditionally renders a popup modal blocking the action in case the user isn’t allowed to perform it.
Instance Method Details
#action_authorization_modal(action) ⇒ Object
Public: Renders a modal that explains why she can’t perform an action, if that’s the case. The modal isn’t shown by default, and it’s usually triggered by ‘action_authorized_link_to` or `action_authorized_button_to`.
action - The action to authenticate against.
Returns a String with the modal.
12 13 14 15 |
# File 'app/helpers/decidim/action_authorization_helper.rb', line 12 def (action) render partial: "decidim/shared/action_authorization_modal", locals: { action: action.to_s } end |
#action_authorized_button_to(action, *arguments, &block) ⇒ Object
Public: Emulates a ‘button_to` but conditionally renders a popup modal blocking the action in case the user isn’t allowed to perform it.
action - The name of the action to authorize against. *arguments - A regular set of arguments that would be provided to
`button_to`.
Returns a String with the button.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/helpers/decidim/action_authorization_helper.rb', line 58 def (action, *arguments, &block) if block_given? body = block url = arguments[0] = arguments[1] || {} else body = arguments[0] url = arguments[1] = arguments[2] || {} end unless (action) ["onclick"] = "event.preventDefault();" ["data-toggle"] = current_user ? "#{action.to_s.underscore}AuthorizationModal" : "loginModal" url = "" end if block_given? (url, , &body) else (body, url, ) end end |
#action_authorized_link_to(action, *arguments, &block) ⇒ Object
Public: Emulates a ‘link_to` but conditionally renders a popup modal blocking the action in case the user isn’t allowed to perform it.
action - The name of the action to authorize against. *arguments - A regular set of arguments that would be provided to
`link_to`.
Returns a String with the link.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/helpers/decidim/action_authorization_helper.rb', line 25 def (action, *arguments, &block) if block_given? body = block url = arguments[0] = arguments[1] else body = arguments[0] url = arguments[1] = arguments[2] end unless (action) ||= {} ["onclick"] = "event.preventDefault();" ["data-toggle"] = current_user ? "#{action.to_s.underscore}AuthorizationModal" : "loginModal" url = "" end if block_given? link_to(url, , &body) else link_to(body, url, ) end end |