decidim-core 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/config/decidim_core_manifest.js +2 -0
  3. data/app/assets/javascripts/decidim/map.js.es6.erb +95 -0
  4. data/app/assets/stylesheets/decidim/map.css +3 -0
  5. data/app/assets/stylesheets/decidim/modules/_layout.scss +2 -4
  6. data/app/assets/stylesheets/decidim/modules/_margins.scss +3 -2
  7. data/app/assets/stylesheets/decidim/modules/_process-header.scss +15 -2
  8. data/app/assets/stylesheets/decidim/modules/_process-phase.scss +4 -1
  9. data/app/assets/stylesheets/decidim/utils/_settings.scss +3 -3
  10. data/app/commands/decidim/create_report.rb +90 -0
  11. data/app/controllers/concerns/decidim/devise_controllers.rb +26 -0
  12. data/app/controllers/concerns/decidim/payload_info.rb +23 -0
  13. data/app/controllers/concerns/decidim/user_profile.rb +2 -1
  14. data/app/controllers/decidim/application_controller.rb +25 -1
  15. data/app/controllers/decidim/authorizations_controller.rb +10 -2
  16. data/app/controllers/decidim/cookie_policy_controller.rb +5 -0
  17. data/app/controllers/decidim/devise/confirmations_controller.rb +1 -9
  18. data/app/controllers/decidim/devise/invitations_controller.rb +1 -9
  19. data/app/controllers/decidim/devise/omniauth_registrations_controller.rb +1 -10
  20. data/app/controllers/decidim/devise/passwords_controller.rb +1 -9
  21. data/app/controllers/decidim/devise/registrations_controller.rb +2 -15
  22. data/app/controllers/decidim/devise/sessions_controller.rb +9 -15
  23. data/{lib → app/controllers}/decidim/features/base_controller.rb +5 -1
  24. data/app/controllers/decidim/participatory_process_groups_controller.rb +22 -0
  25. data/app/controllers/decidim/participatory_process_steps_controller.rb +2 -0
  26. data/app/controllers/decidim/participatory_processes_controller.rb +14 -3
  27. data/app/controllers/decidim/reports_controller.rb +33 -0
  28. data/app/controllers/decidim/static_map_controller.rb +18 -0
  29. data/app/forms/decidim/report_form.rb +12 -0
  30. data/app/helpers/decidim/application_helper.rb +0 -2
  31. data/app/helpers/decidim/feature_reference_helper.rb +22 -0
  32. data/app/helpers/decidim/map_helper.rb +41 -0
  33. data/app/helpers/decidim/organization_scopes_helper.rb +41 -0
  34. data/app/helpers/decidim/replace_buttons_helper.rb +42 -0
  35. data/app/helpers/decidim/resource_helper.rb +2 -1
  36. data/app/helpers/decidim/translations_helper.rb +1 -1
  37. data/app/mailers/decidim/reported_mailer.rb +35 -0
  38. data/app/middleware/decidim/current_organization.rb +29 -3
  39. data/app/models/decidim/abilities/everyone.rb +1 -0
  40. data/app/models/decidim/moderation.rb +13 -0
  41. data/app/models/decidim/newsletter.rb +1 -0
  42. data/app/models/decidim/organization.rb +2 -0
  43. data/app/models/decidim/participatory_process.rb +11 -0
  44. data/app/models/decidim/participatory_process_group.rb +15 -0
  45. data/app/models/decidim/participatory_process_step.rb +1 -1
  46. data/app/models/decidim/report.rb +23 -0
  47. data/app/services/decidim/public_processes.rb +42 -0
  48. data/app/services/decidim/resource_search.rb +17 -1
  49. data/app/services/decidim/static_map_generator.rb +49 -0
  50. data/app/uploaders/decidim/application_uploader.rb +4 -1
  51. data/app/uploaders/decidim/official_image_footer_uploader.rb +2 -2
  52. data/app/uploaders/decidim/official_image_header_uploader.rb +1 -1
  53. data/app/validators/geocoding_validator.rb +22 -0
  54. data/app/views/decidim/authorizations/new.html.erb +1 -1
  55. data/app/views/decidim/participatory_process_groups/_participatory_process_group.html.erb +22 -0
  56. data/app/views/decidim/participatory_process_groups/show.html.erb +11 -0
  57. data/app/views/decidim/participatory_processes/index.html.erb +1 -1
  58. data/app/views/decidim/participatory_processes/show.html.erb +18 -5
  59. data/app/views/decidim/reported_mailer/hide.html.erb +5 -0
  60. data/app/views/decidim/reported_mailer/report.html.erb +5 -0
  61. data/app/views/decidim/shared/_address_details.html.erb +9 -0
  62. data/app/views/decidim/shared/_flag_modal.html.erb +20 -0
  63. data/app/views/decidim/shared/_share_modal.html.erb +5 -5
  64. data/app/views/decidim/shared/_static_map.html.erb +17 -0
  65. data/app/views/devise/mailer/invite_collaborator.html.erb +17 -0
  66. data/app/views/devise/mailer/invite_collaborator.text.erb +15 -0
  67. data/app/views/layouts/decidim/_application.html.erb +5 -12
  68. data/app/views/layouts/decidim/{_social_meta.html.erb → _head.html.erb} +13 -0
  69. data/app/views/layouts/decidim/_head_extra.html.erb +7 -0
  70. data/app/views/layouts/decidim/_process_header.html.erb +15 -9
  71. data/app/views/layouts/decidim/_process_header_steps.html.erb +3 -3
  72. data/app/views/layouts/decidim/{_header.html.erb → _wrapper.html.erb} +47 -10
  73. data/app/views/pages/home/_highlighted_processes.html.erb +2 -2
  74. data/config/i18n-tasks.yml +3 -0
  75. data/config/locales/ca.yml +40 -1
  76. data/config/locales/en.yml +40 -1
  77. data/config/locales/es.yml +40 -1
  78. data/config/locales/eu.yml +235 -1
  79. data/config/locales/fi.yml +375 -0
  80. data/config/routes.rb +4 -0
  81. data/db/migrate/20170215115407_add_organization_custom_reference.rb +11 -0
  82. data/db/migrate/20170220110740_remove_steps_short_description.rb +21 -0
  83. data/db/migrate/20170221094835_add_scopes_to_processes.rb +6 -0
  84. data/db/migrate/20170228142440_add_participatory_process_groups.rb +15 -0
  85. data/db/migrate/20170306144354_add_secondary_hosts_to_organizations.rb +5 -0
  86. data/db/migrate/20170307084957_create_reports.rb +15 -0
  87. data/db/migrate/20170308091316_create_moderations.rb +12 -0
  88. data/db/migrate/20170313095436_add_available_authorizations_to_organization.rb +10 -0
  89. data/db/seeds.rb +20 -10
  90. data/lib/decidim/core.rb +12 -1
  91. data/lib/decidim/core/api.rb +1 -0
  92. data/lib/decidim/core/api/decidim_type.rb +12 -0
  93. data/lib/decidim/core/api/process_step_type.rb +0 -6
  94. data/lib/decidim/core/api/user_type.rb +4 -0
  95. data/lib/decidim/core/engine.rb +27 -0
  96. data/lib/decidim/core/test.rb +5 -0
  97. data/lib/decidim/core/test/factories.rb +52 -3
  98. data/lib/decidim/core/test/shared_examples/comments_examples.rb +215 -0
  99. data/lib/decidim/core/test/shared_examples/has_reference.rb +30 -0
  100. data/lib/decidim/core/test/shared_examples/manage_moderations_examples.rb +75 -0
  101. data/lib/decidim/core/test/shared_examples/reportable.rb +44 -0
  102. data/lib/decidim/core/test/shared_examples/reports_examples.rb +64 -0
  103. data/lib/decidim/core/version.rb +2 -2
  104. data/lib/decidim/has_reference.rb +50 -0
  105. data/lib/decidim/query_extensions.rb +4 -0
  106. data/lib/decidim/reportable.rb +46 -0
  107. data/vendor/assets/javascripts/leaflet-svg-icon.js +179 -0
  108. data/vendor/assets/javascripts/leaflet-tilelayer-here.js +166 -0
  109. data/vendor/assets/javascripts/leaflet.js +9 -0
  110. data/vendor/assets/javascripts/leaflet.markercluster.js +7 -0
  111. data/vendor/assets/javascripts/quill.min.js +8 -8
  112. data/vendor/assets/javascripts/quill.min.js.map +1 -1
  113. data/vendor/assets/stylesheets/MarkerCluster.Default.css +60 -0
  114. data/vendor/assets/stylesheets/MarkerCluster.css +14 -0
  115. data/vendor/assets/stylesheets/leaflet.css +624 -0
  116. data/vendor/assets/stylesheets/quill.bubble.css +75 -4
  117. data/vendor/assets/stylesheets/quill.core.css +21 -2
  118. data/vendor/assets/stylesheets/quill.snow.css +29 -3
  119. metadata +107 -27
  120. data/app/views/layouts/decidim/_footer.html.erb +0 -36
  121. data/app/views/layouts/decidim/_meta.html.erb +0 -4
@@ -10,6 +10,11 @@ module Decidim
10
10
  response.set_cookie "decidim-cc", value: "true",
11
11
  path: "/",
12
12
  expires: 1.year.from_now.utc
13
+
14
+ respond_to do |format|
15
+ format.js
16
+ format.html { redirect_back fallback_location: root_path }
17
+ end
13
18
  end
14
19
  end
15
20
  end
@@ -3,15 +3,7 @@ module Decidim
3
3
  module Devise
4
4
  # Custom Devise ConfirmationsController to avoid namespace problems.
5
5
  class ConfirmationsController < ::Devise::ConfirmationsController
6
- include Decidim::NeedsOrganization
7
- include Decidim::LocaleSwitcher
8
- helper Decidim::TranslationsHelper
9
- helper Decidim::MetaTagsHelper
10
- helper Decidim::DecidimFormHelper
11
- helper Decidim::LanguageChooserHelper
12
- helper Decidim::CookiesHelper
13
-
14
- layout "layouts/decidim/application"
6
+ include Decidim::DeviseControllers
15
7
  end
16
8
  end
17
9
  end
@@ -3,15 +3,7 @@ module Decidim
3
3
  module Devise
4
4
  # This controller customizes the behaviour of Devise::Invitiable.
5
5
  class InvitationsController < ::Devise::InvitationsController
6
- include Decidim::NeedsOrganization
7
- include Decidim::LocaleSwitcher
8
- helper Decidim::TranslationsHelper
9
- helper Decidim::MetaTagsHelper
10
- helper Decidim::DecidimFormHelper
11
- helper Decidim::LanguageChooserHelper
12
- helper Decidim::CookiesHelper
13
-
14
- layout "layouts/decidim/application"
6
+ include Decidim::DeviseControllers
15
7
 
16
8
  # We don't users to create invitations, so we just redirect them to the
17
9
  # homepage.
@@ -4,16 +4,7 @@ module Decidim
4
4
  # This controller customizes the behaviour of Devise::Omniauthable.
5
5
  class OmniauthRegistrationsController < ::Devise::OmniauthCallbacksController
6
6
  include FormFactory
7
-
8
- include Decidim::NeedsOrganization
9
- include Decidim::LocaleSwitcher
10
- helper Decidim::TranslationsHelper
11
- helper Decidim::MetaTagsHelper
12
- helper Decidim::DecidimFormHelper
13
- helper Decidim::LanguageChooserHelper
14
- helper Decidim::CookiesHelper
15
-
16
- layout "layouts/decidim/application"
7
+ include Decidim::DeviseControllers
17
8
 
18
9
  def new
19
10
  @form = form(OmniauthRegistrationForm).from_params(params[:user])
@@ -3,15 +3,7 @@ module Decidim
3
3
  module Devise
4
4
  # Custom Devise PasswordsController to avoid namespace problems.
5
5
  class PasswordsController < ::Devise::PasswordsController
6
- include Decidim::NeedsOrganization
7
- include Decidim::LocaleSwitcher
8
- helper Decidim::TranslationsHelper
9
- helper Decidim::MetaTagsHelper
10
- helper Decidim::DecidimFormHelper
11
- helper Decidim::LanguageChooserHelper
12
- helper Decidim::CookiesHelper
13
-
14
- layout "layouts/decidim/application"
6
+ include Decidim::DeviseControllers
15
7
  end
16
8
  end
17
9
  end
@@ -4,19 +4,12 @@ module Decidim
4
4
  # This controller customizes the behaviour of Devise's
5
5
  # RegistrationsController so we can specify a custom layout.
6
6
  class RegistrationsController < ::Devise::RegistrationsController
7
- include Decidim::NeedsOrganization
8
- include Decidim::LocaleSwitcher
9
7
  include FormFactory
10
- helper Decidim::TranslationsHelper
11
- helper Decidim::OmniauthHelper
12
- helper Decidim::MetaTagsHelper
13
- helper Decidim::DecidimFormHelper
14
- helper Decidim::LanguageChooserHelper
15
- helper Decidim::CookiesHelper
8
+ include Decidim::DeviseControllers
16
9
 
10
+ helper Decidim::OmniauthHelper
17
11
  helper_method :terms_and_conditions_page
18
12
 
19
- layout "layouts/decidim/application"
20
13
  before_action :configure_permitted_parameters
21
14
  helper_method :terms_and_conditions_page
22
15
 
@@ -69,12 +62,6 @@ module Decidim
69
62
  super(hash)
70
63
  resource.organization = current_organization
71
64
  end
72
-
73
- private
74
-
75
- def terms_and_conditions_page
76
- @terms_and_conditions_page ||= Decidim::StaticPage.find_by_slug("terms-and-conditions")
77
- end
78
65
  end
79
66
  end
80
67
  end
@@ -3,23 +3,13 @@ module Decidim
3
3
  module Devise
4
4
  # Custom Devise SessionsController to avoid namespace problems.
5
5
  class SessionsController < ::Devise::SessionsController
6
- include Decidim::NeedsOrganization
7
- include Decidim::LocaleSwitcher
8
- helper Decidim::TranslationsHelper
6
+ include Decidim::DeviseControllers
9
7
  helper Decidim::OmniauthHelper
10
- helper Decidim::MetaTagsHelper
11
- helper Decidim::DecidimFormHelper
12
- helper Decidim::LanguageChooserHelper
13
- helper Decidim::CookiesHelper
14
-
15
- layout "layouts/decidim/application"
16
8
 
17
9
  def after_sign_in_path_for(user)
18
- if !pending_redirect?(user) && first_login_and_not_authorized?(user)
19
- first_login_authorizations_path
20
- else
21
- super
22
- end
10
+ return first_login_authorizations_path if first_login_and_not_authorized?(user) &&
11
+ !user.roles.include?("admin")
12
+ super
23
13
  end
24
14
 
25
15
  # Calling the `stored_location_for` method removes the key, so in order
@@ -31,7 +21,11 @@ module Decidim
31
21
  end
32
22
 
33
23
  def first_login_and_not_authorized?(user)
34
- user.is_a?(User) && user.sign_in_count == 1 && Decidim.authorization_handlers.any?
24
+ user.is_a?(User) && user.sign_in_count == 1 && current_organization.available_authorizations.any?
25
+ end
26
+
27
+ def after_sign_out_path_for(user)
28
+ request.referer || super
35
29
  end
36
30
  end
37
31
  end
@@ -11,11 +11,15 @@ module Decidim
11
11
  include FeatureSettings
12
12
  include ActionAuthorization
13
13
 
14
+ helper Decidim::FiltersHelper
15
+ helper Decidim::OrdersHelper
16
+ helper Decidim::FeatureReferenceHelper
14
17
  helper Decidim::TranslationsHelper
15
18
  helper Decidim::ParticipatoryProcessHelper
16
19
  helper Decidim::ResourceHelper
20
+ helper Decidim::OrganizationScopesHelper
17
21
  helper Decidim::ActionAuthorizationHelper
18
- helper Decidim::MetaTagsHelper
22
+ helper Decidim::AttachmentsHelper
19
23
 
20
24
  helper_method :current_feature,
21
25
  :current_manifest
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+ require_dependency "decidim/application_controller"
3
+
4
+ module Decidim
5
+ class ParticipatoryProcessGroupsController < ApplicationController
6
+ helper_method :participatory_processes, :group
7
+
8
+ def show
9
+ authorize! :read, ParticipatoryProcessGroup
10
+ end
11
+
12
+ private
13
+
14
+ def participatory_processes
15
+ @participatory_processes ||= group.participatory_processes.published
16
+ end
17
+
18
+ def group
19
+ Decidim::ParticipatoryProcessGroup.find(params[:id])
20
+ end
21
+ end
22
+ end
@@ -9,6 +9,8 @@ module Decidim
9
9
  layout "layouts/decidim/participatory_process", only: [:index]
10
10
  include NeedsParticipatoryProcess
11
11
 
12
+ helper Decidim::ParticipatoryProcessHelper
13
+
12
14
  def index
13
15
  authorize! :read, ParticipatoryProcess
14
16
  end
@@ -11,10 +11,13 @@ module Decidim
11
11
 
12
12
  skip_after_action :verify_participatory_process, only: [:index]
13
13
 
14
- helper_method :participatory_processes, :promoted_participatory_processes
14
+ helper Decidim::AttachmentsHelper
15
+ helper Decidim::ParticipatoryProcessHelper
16
+ helper_method :collection, :promoted_participatory_processes, :participatory_processes
15
17
 
16
18
  def index
17
19
  authorize! :read, ParticipatoryProcess
20
+ authorize! :read, ParticipatoryProcessGroup
18
21
  end
19
22
 
20
23
  def show
@@ -23,12 +26,20 @@ module Decidim
23
26
 
24
27
  private
25
28
 
29
+ def collection
30
+ @collection ||= public_processes.collection
31
+ end
32
+
26
33
  def participatory_processes
27
- @processes ||= OrganizationParticipatoryProcesses.new(current_organization) | PublicParticipatoryProcesses.new
34
+ @participatory_processes ||= public_processes.participatory_processes
28
35
  end
29
36
 
30
37
  def promoted_participatory_processes
31
- @promoted_processes ||= participatory_processes | PromotedParticipatoryProcesses.new
38
+ @promoted_processes ||= participatory_processes.promoted
39
+ end
40
+
41
+ def public_processes
42
+ @public_processes ||= PublicProcesses.new(current_organization)
32
43
  end
33
44
  end
34
45
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ # Exposes the report resource so users can report a reportable.
5
+ class ReportsController < Decidim::ApplicationController
6
+ include FormFactory
7
+ before_action :authenticate_user!
8
+
9
+ def create
10
+ authorize! :report, reportable
11
+
12
+ @form = form(Decidim::ReportForm).from_params(params)
13
+
14
+ CreateReport.call(@form, reportable, current_user) do
15
+ on(:ok) do
16
+ flash[:notice] = I18n.t("decidim.reports.create.success")
17
+ redirect_back fallback_location: root_path
18
+ end
19
+
20
+ on(:invalid) do
21
+ flash[:alert] = I18n.t("decidim.reports.create.error")
22
+ redirect_back fallback_location: root_path
23
+ end
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def reportable
30
+ @reportable ||= GlobalID::Locator.locate_signed params[:sgid]
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+ require_dependency "decidim/application_controller"
3
+
4
+ module Decidim
5
+ class StaticMapController < ApplicationController
6
+ skip_authorization_check
7
+
8
+ def show
9
+ send_data StaticMapGenerator.new(resource).data, type: "image/jpeg", disposition: "inline"
10
+ end
11
+
12
+ private
13
+
14
+ def resource
15
+ @resource ||= GlobalID::Locator.locate_signed params[:sgid]
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ module Decidim
3
+ # A form object to be used when public users want to report a reportable.
4
+ class ReportForm < Decidim::Form
5
+ mimic :report
6
+
7
+ attribute :reason, String
8
+ attribute :details, String
9
+
10
+ validates :reason, inclusion: { in: Report::REASONS }
11
+ end
12
+ end
@@ -3,8 +3,6 @@
3
3
  module Decidim
4
4
  # Main module to add application-wide helpers.
5
5
  module ApplicationHelper
6
- include Decidim::MetaTagsHelper
7
-
8
6
  # Truncates a given text respecting its HTML tags.
9
7
  #
10
8
  # text - The String text to be truncated.
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+ module Decidim
3
+ # Helper to print Feature references.
4
+ module FeatureReferenceHelper
5
+ # Displays the localized reference for the given feature.
6
+ #
7
+ # feature - the Feature that has the reference to display.
8
+ #
9
+ # Returns a String.
10
+ def feature_reference(feature)
11
+ return unless feature.reference
12
+ @reference = feature.reference
13
+ "<div class='reference'>#{localized_reference}</div>".html_safe
14
+ end
15
+
16
+ private
17
+
18
+ def localized_reference
19
+ I18n.t("reference", reference: @reference, scope: "decidim.shared.reference")
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+ module Decidim
3
+ # This helper include some methods for rendering resources static and dynamic maps.
4
+ module MapHelper
5
+ # Renders a link to openstreetmaps with the resource latitude and longitude.
6
+ # The link's content is a static map image.
7
+ #
8
+ # resource - A geolocalizable resource
9
+ # options - An optional hash of options (default: { zoom: 17 })
10
+ # * zoom: A number to represent the zoom value of the map
11
+ def static_map_link(resource, options = {})
12
+ if resource.geocoded?
13
+ zoom = options[:zoom] || 17
14
+ latitude = resource.latitude
15
+ longitude = resource.longitude
16
+
17
+ map_url = "https://www.openstreetmap.org/?mlat=#{latitude}&mlon=#{longitude}#map=#{zoom}/#{latitude}/#{longitude}"
18
+
19
+ link_to map_url, target: "_blank" do
20
+ image_tag decidim.static_map_path(sgid: resource.to_sgid.to_s)
21
+ end
22
+ end
23
+ end
24
+
25
+ def dynamic_map_for(markers_data, &block)
26
+ if Decidim.geocoder.present?
27
+ map_html_options = {
28
+ class: "google-map",
29
+ id: "map",
30
+ "data-markers-data" => markers_data.to_json,
31
+ "data-here-app-id" => Decidim.geocoder[:here_app_id],
32
+ "data-here-app-code" => Decidim.geocoder[:here_app_code]
33
+ }
34
+ content = capture { block.call }
35
+ content_tag :div, class: "row column" do
36
+ content_tag(:div, "", map_html_options) + content
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,41 @@
1
+ # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
3
+ module Decidim
4
+ # A Helper to render scopes, including a global scope, for forms.
5
+ module OrganizationScopesHelper
6
+ # Public: Returns a collection of the given organization scopes, prepending
7
+ # a global scope. The global scope is at the beginning because it's easier
8
+ # to be found there. Use this helper in places like `select` elements in forms.
9
+ # If you need to show scopes in a search form backed by a `Searchlight::Search`
10
+ # class, see the `search_organization_scopes` helper method.
11
+ #
12
+ # organization - a Decidim::Organization. Uses the `current_organization` helper
13
+ # by default.
14
+ #
15
+ # Returns an Array.
16
+ def organization_scopes(organization = current_organization)
17
+ [Struct.new(:id, :name).new("", I18n.t("decidim.participatory_processes.scopes.global"))] + organization.scopes
18
+ end
19
+
20
+ # Public: Returns a collection of the given organization scopes, prepending
21
+ # a global scope. The global scope is at the beginning because it's easier
22
+ # to be found there. Use this helper in search forms backed by a
23
+ # `Searchlight::Search` class. The reason is, in the `organization_scopes`
24
+ # method we use an empty String as the ID for the Global Scope object, which
25
+ # works fine in normal forms, but Searchlight ignores parameters that are empty
26
+ # Arrays, empty Strings, empty Hashes or nil, so if you want to actively filter
27
+ # those elements that do not have a scope, you cannot send an empty String or
28
+ # nil because Searchlight will ignore the parameter. The only solution here is
29
+ # to use a specific String as ID (`"global"`, in our case), and then treat this
30
+ # case in the search class. This is far from ideal, but I don't know a better
31
+ # way to do this.
32
+ #
33
+ # organization - a Decidim::Organization. Uses the `current_organization` helper
34
+ # by default.
35
+ #
36
+ # Returns an Array.
37
+ def search_organization_scopes(organization = current_organization)
38
+ [Struct.new(:id, :name).new("global", I18n.t("decidim.participatory_processes.scopes.global"))] + organization.scopes
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+ module Decidim
3
+ module ReplaceButtonsHelper
4
+ # Overrides the submit tags to always be buttons instead of inputs.
5
+ # Buttons are much more stylable and less prone to bugs.
6
+ #
7
+ # value - The text of the button
8
+ # options - Options to provide to the actual tag.
9
+ #
10
+ # Returns a SafeString with the tag.
11
+ def submit_tag(text = "Save changes", options = {})
12
+ options = options.stringify_keys
13
+
14
+ content_tag :button, text, { "type" => "submit", "name" => "commit" }.update(options)
15
+ end
16
+
17
+ # Public: Overrides button_to so it always renders buttons instead of
18
+ # input tags.
19
+ #
20
+ # arguments - The same arguments that would be sent to `button_to`.
21
+ # block - An optional block to be sent.
22
+ #
23
+ # Returns a button.
24
+ def button_to(*arguments, &block)
25
+ if block_given?
26
+ body = block
27
+ url = arguments[0]
28
+ html_options = arguments[1] || {}
29
+ else
30
+ body = arguments[0]
31
+ url = arguments[1]
32
+ html_options = arguments[2] || {}
33
+ end
34
+
35
+ if block_given?
36
+ super(url, html_options, &body)
37
+ else
38
+ super(url, html_options) { body }
39
+ end
40
+ end
41
+ end
42
+ end