Module: Decidim::DecidimAwesome::AwesomeHelpers
- Includes:
- RequestMemoizer
- Defined in:
- lib/decidim/decidim_awesome/awesome_helpers.rb
Instance Method Summary collapse
- #awesome_authorization_groups ⇒ Object
-
#awesome_authorizations_for(user) ⇒ Object
Retrieves all the "admins_available_authorizations" for the user along with other possible authorizations returns an instance of Decidim::DecidimAwesome::Authorizer.
- #awesome_config ⇒ Object
-
#awesome_config_instance ⇒ Object
Returns the normalized config for an Organization and the current url.
-
#awesome_force_authorizations ⇒ Object
Collects all the force authorizations that is applied in the current URL context.
-
#awesome_proposal_custom_fields ⇒ Object
Collects all proposal custom fields that is applied in the current URL context.
- #awesome_proposal_private_custom_fields ⇒ Object
-
#awesome_scoped_admin_styles ⇒ Object
Collects all CSS that is applied in the current URL context.
-
#awesome_scoped_admins ⇒ Object
Collects all proposal custom fields that is applied in the current URL context.
-
#awesome_scoped_styles ⇒ Object
Collects all CSS that is applied in the current URL context.
- #awesome_version ⇒ Object
-
#awesome_voting_manifest_for(component) ⇒ Object
this will check if the current component has been configured to use a custom voting manifest.
-
#awesome_voting_restricted_by_status?(proposal) ⇒ Boolean
True when voting is restricted for this proposal because its state is not in the allowed list.
- #javascript_config_vars ⇒ Object
- #organization_awesome_config ⇒ Object
- #show_public_intergram? ⇒ Boolean
- #unfiltered_awesome_config ⇒ Object
- #version_prefix ⇒ Object
Methods included from RequestMemoizer
Instance Method Details
#awesome_authorization_groups ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/decidim/decidim_awesome/awesome_helpers.rb', line 34 def return unless Decidim::DecidimAwesome.enabled?(:awesome_authorization_handler) memoize("awesome_authorization_groups") do awesome_config_instance.organization..map do |group| { value: group.id, text: translated_attribute(group.name) } end.to_json.html_safe end end |
#awesome_authorizations_for(user) ⇒ Object
Retrieves all the "admins_available_authorizations" for the user along with other possible authorizations returns an instance of Decidim::DecidimAwesome::Authorizer
132 133 134 135 136 |
# File 'lib/decidim/decidim_awesome/awesome_helpers.rb', line 132 def (user) memoize("awesome_authorizations_for_#{user.id}") do Authorizer.new(user, awesome_config[:admins_available_authorizations]) end end |
#awesome_config ⇒ Object
22 23 24 25 26 |
# File 'lib/decidim/decidim_awesome/awesome_helpers.rb', line 22 def awesome_config memoize("awesome_config") do awesome_config_instance.config end end |
#awesome_config_instance ⇒ Object
Returns the normalized config for an Organization and the current url
12 13 14 15 16 17 18 19 20 |
# File 'lib/decidim/decidim_awesome/awesome_helpers.rb', line 12 def awesome_config_instance @awesome_config_instance ||= memoize("current_config") do config = Config.new(request.env["decidim.current_organization"]) config.context_from_request!(request) config end @awesome_config_instance.application_context!(current_user:) if respond_to?(:current_user) @awesome_config_instance end |
#awesome_force_authorizations ⇒ Object
Collects all the force authorizations that is applied in the current URL context
105 106 107 108 109 |
# File 'lib/decidim/decidim_awesome/awesome_helpers.rb', line 105 def memoize("awesome_force_authorizations") do awesome_config_instance.collect_sub_configs_values("force_authorization") end end |
#awesome_proposal_custom_fields ⇒ Object
Collects all proposal custom fields that is applied in the current URL context
92 93 94 95 96 |
# File 'lib/decidim/decidim_awesome/awesome_helpers.rb', line 92 def awesome_proposal_custom_fields memoize("awesome_proposal_custom_fields") do awesome_config_instance.collect_sub_configs_values("proposal_custom_field") end end |
#awesome_proposal_private_custom_fields ⇒ Object
98 99 100 101 102 |
# File 'lib/decidim/decidim_awesome/awesome_helpers.rb', line 98 def awesome_proposal_private_custom_fields memoize("awesome_proposal_private_custom_fields") do awesome_config_instance.collect_sub_configs_values("proposal_private_custom_field") end end |
#awesome_scoped_admin_styles ⇒ Object
Collects all CSS that is applied in the current URL context
78 79 80 81 82 |
# File 'lib/decidim/decidim_awesome/awesome_helpers.rb', line 78 def awesome_scoped_admin_styles memoize("awesome_scoped_admin_styles") do awesome_config_instance.collect_sub_configs_values("scoped_admin_style") end end |
#awesome_scoped_admins ⇒ Object
Collects all proposal custom fields that is applied in the current URL context
85 86 87 88 89 |
# File 'lib/decidim/decidim_awesome/awesome_helpers.rb', line 85 def awesome_scoped_admins memoize("awesome_scoped_admins") do awesome_config_instance.collect_sub_configs_values("scoped_admin") end end |
#awesome_scoped_styles ⇒ Object
Collects all CSS that is applied in the current URL context
71 72 73 74 75 |
# File 'lib/decidim/decidim_awesome/awesome_helpers.rb', line 71 def awesome_scoped_styles memoize("awesome_scoped_styles") do awesome_config_instance.collect_sub_configs_values("scoped_style") end end |
#awesome_version ⇒ Object
66 67 68 |
# File 'lib/decidim/decidim_awesome/awesome_helpers.rb', line 66 def awesome_version ::Decidim::DecidimAwesome::VERSION end |
#awesome_voting_manifest_for(component) ⇒ Object
this will check if the current component has been configured to use a custom voting manifest
112 113 114 115 116 |
# File 'lib/decidim/decidim_awesome/awesome_helpers.rb', line 112 def awesome_voting_manifest_for(component) memoize("awesome_voting_manifest_for_#{component.id}") do DecidimAwesome.voting_registry.find(component.settings.try(:awesome_voting_manifest)) end end |
#awesome_voting_restricted_by_status?(proposal) ⇒ Boolean
True when voting is restricted for this proposal because its state is not in the allowed list. Returns false if the filter is inactive or if Decidim already blocks voting via votes_blocked.
120 121 122 123 124 125 126 127 128 |
# File 'lib/decidim/decidim_awesome/awesome_helpers.rb', line 120 def awesome_voting_restricted_by_status?(proposal) settings = proposal.component.current_settings return false if settings.try(:votes_blocked) filter = Decidim::DecidimAwesome::Proposals::VotesByProposalStatus.new(settings) return false unless filter.active? !filter.allowed?(proposal) end |
#javascript_config_vars ⇒ Object
28 29 30 31 32 |
# File 'lib/decidim/decidim_awesome/awesome_helpers.rb', line 28 def javascript_config_vars memoize("javascript_config_vars") do awesome_config.slice(:allow_images_in_proposals, :allow_images_in_editors, :allow_videos_in_editors, :auto_save_forms).to_json.html_safe end end |
#organization_awesome_config ⇒ Object
60 61 62 63 64 |
# File 'lib/decidim/decidim_awesome/awesome_helpers.rb', line 60 def organization_awesome_config memoize("organization_awesome_config") do awesome_config_instance.organization_config end end |
#show_public_intergram? ⇒ Boolean
47 48 49 50 51 52 |
# File 'lib/decidim/decidim_awesome/awesome_helpers.rb', line 47 def show_public_intergram? return false unless awesome_config[:intergram_for_public] return true unless awesome_config[:intergram_for_public_settings][:require_login] user_signed_in? end |
#unfiltered_awesome_config ⇒ Object
54 55 56 57 58 |
# File 'lib/decidim/decidim_awesome/awesome_helpers.rb', line 54 def unfiltered_awesome_config memoize("unfiltered_awesome_config") do awesome_config_instance.unfiltered_config end end |
#version_prefix ⇒ Object
138 139 140 |
# File 'lib/decidim/decidim_awesome/awesome_helpers.rb', line 138 def version_prefix "v#{Decidim.version[0..3]}" end |