decidim-dev 0.31.8 → 0.32.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -12
  3. data/app/commands/decidim/dev/create_dummy_resource.rb +6 -6
  4. data/app/controllers/decidim/dev/dummy_resources_controller.rb +0 -2
  5. data/app/models/decidim/dev/dummy_resource.rb +4 -1
  6. data/app/models/decidim/dev/nested_dummy_resource.rb +1 -0
  7. data/app/packs/src/decidim/dev/accessibility.js +1 -1
  8. data/config/locales/ar.yml +1 -2
  9. data/config/locales/bg.yml +1 -2
  10. data/config/locales/ca-IT.yml +1 -2
  11. data/config/locales/ca.yml +1 -2
  12. data/config/locales/cs.yml +1 -2
  13. data/config/locales/de.yml +1 -2
  14. data/config/locales/el.yml +1 -2
  15. data/config/locales/es-MX.yml +1 -2
  16. data/config/locales/es-PY.yml +1 -2
  17. data/config/locales/es.yml +1 -2
  18. data/config/locales/eu.yml +7 -8
  19. data/config/locales/fi-plain.yml +1 -2
  20. data/config/locales/fi.yml +1 -2
  21. data/config/locales/fr-CA.yml +1 -2
  22. data/config/locales/fr.yml +1 -2
  23. data/config/locales/ga-IE.yml +0 -1
  24. data/config/locales/gl.yml +2 -17
  25. data/config/locales/hu.yml +1 -2
  26. data/config/locales/id-ID.yml +1 -2
  27. data/config/locales/is-IS.yml +1 -2
  28. data/config/locales/it.yml +1 -2
  29. data/config/locales/ja.yml +1 -2
  30. data/config/locales/lt.yml +1 -2
  31. data/config/locales/lv.yml +1 -2
  32. data/config/locales/nl.yml +1 -2
  33. data/config/locales/no.yml +1 -2
  34. data/config/locales/pl.yml +1 -2
  35. data/config/locales/pt-BR.yml +1 -2
  36. data/config/locales/pt.yml +1 -2
  37. data/config/locales/ro-RO.yml +1 -2
  38. data/config/locales/ru.yml +1 -2
  39. data/config/locales/sk.yml +1 -26
  40. data/config/locales/sl.yml +0 -1
  41. data/config/locales/sv.yml +1 -2
  42. data/config/locales/tr-TR.yml +1 -2
  43. data/config/locales/uk.yml +0 -1
  44. data/config/locales/zh-CN.yml +1 -2
  45. data/config/locales/zh-TW.yml +1 -2
  46. data/config/rubocop/decidim-linters/configuration.yml +4 -36
  47. data/config/rubocop/rails/disabled.yml +6 -0
  48. data/config/rubocop/rspec/configuration.yml +5 -1
  49. data/config/rubocop/ruby/configuration.yml +2 -3
  50. data/config/rubocop/ruby/disabled.yml +9 -0
  51. data/config/rubocop/yard/configuration.yml +1 -0
  52. data/decidim-dev.gemspec +21 -23
  53. data/lib/decidim/dev/assets/assemblies.json +1 -21
  54. data/lib/decidim/dev/assets/assemblies_with_null.json +1 -2
  55. data/lib/decidim/dev/assets/participatory_processes.json +1 -4
  56. data/lib/decidim/dev/assets/participatory_processes_with_null.json +1 -1
  57. data/lib/decidim/dev/dummy_translator.rb +1 -1
  58. data/lib/decidim/dev/rubocop/cop/decidim/message_antipattern.rb +76 -0
  59. data/lib/decidim/dev/test/rspec_support/active_job.rb +5 -0
  60. data/lib/decidim/dev/test/rspec_support/capybara.rb +0 -54
  61. data/lib/decidim/dev/test/rspec_support/component_context.rb +1 -1
  62. data/lib/decidim/dev/test/rspec_support/helpers.rb +10 -17
  63. data/lib/decidim/dev/test/rspec_support/tom_select.rb +7 -4
  64. data/lib/decidim/dev/version.rb +1 -1
  65. data/lib/decidim/dev.rb +1 -33
  66. data/lib/erb_lint/linters/admin_page_title_linter.rb +46 -0
  67. data/lib/erb_lint/linters/partial_path_linter.rb +101 -0
  68. data/rubocop-decidim.yml +1 -0
  69. metadata +133 -131
  70. data/lib/decidim/dev/assets/8001x4000.png +0 -0
  71. data/lib/decidim/dev/assets/empty_file.png +0 -0
  72. data/lib/decidim/dev/assets/malformed_svg_unclosed_element.svg +0 -7
  73. data/lib/decidim/dev/assets/malicious_svg_animation.svg +0 -1
  74. data/lib/decidim/dev/assets/malicious_svg_animation_attribute_names.svg +0 -1
  75. data/lib/decidim/dev/assets/malicious_svg_animation_fill.svg +0 -1
  76. data/lib/decidim/dev/assets/malicious_svg_animation_style.svg +0 -1
  77. data/lib/decidim/dev/assets/malicious_svg_animation_values.svg +0 -1
  78. data/lib/decidim/dev/assets/malicious_svg_attributename_case.svg +0 -1
  79. data/lib/decidim/dev/assets/malicious_svg_backslash_reference.svg +0 -1
  80. data/lib/decidim/dev/assets/malicious_svg_css_backslash_url.svg +0 -1
  81. data/lib/decidim/dev/assets/malicious_svg_css_comment_in_url.svg +0 -1
  82. data/lib/decidim/dev/assets/malicious_svg_css_image_set.svg +0 -1
  83. data/lib/decidim/dev/assets/malicious_svg_css_image_set_nested_parentheses.svg +0 -1
  84. data/lib/decidim/dev/assets/malicious_svg_cursor.svg +0 -1
  85. data/lib/decidim/dev/assets/malicious_svg_cursor_attribute.svg +0 -1
  86. data/lib/decidim/dev/assets/malicious_svg_data_uri_declared_encoding.svg +0 -1
  87. data/lib/decidim/dev/assets/malicious_svg_data_uri_deep_nested.svg +0 -1
  88. data/lib/decidim/dev/assets/malicious_svg_data_uri_leading_space.svg +0 -1
  89. data/lib/decidim/dev/assets/malicious_svg_data_uri_nested.svg +0 -1
  90. data/lib/decidim/dev/assets/malicious_svg_data_uri_parameter.svg +0 -1
  91. data/lib/decidim/dev/assets/malicious_svg_entity.svg +0 -5
  92. data/lib/decidim/dev/assets/malicious_svg_entity_parameter.svg +0 -7
  93. data/lib/decidim/dev/assets/malicious_svg_external_animation.svg +0 -1
  94. data/lib/decidim/dev/assets/malicious_svg_external_animation_missing_target.svg +0 -1
  95. data/lib/decidim/dev/assets/malicious_svg_external_animation_target.svg +0 -1
  96. data/lib/decidim/dev/assets/malicious_svg_external_feimage.svg +0 -1
  97. data/lib/decidim/dev/assets/malicious_svg_external_image.svg +0 -1
  98. data/lib/decidim/dev/assets/malicious_svg_external_use.svg +0 -1
  99. data/lib/decidim/dev/assets/malicious_svg_fill_external_reference.svg +0 -1
  100. data/lib/decidim/dev/assets/malicious_svg_foreign_object.svg +0 -1
  101. data/lib/decidim/dev/assets/malicious_svg_handler.svg +0 -1
  102. data/lib/decidim/dev/assets/malicious_svg_marker_external_reference.svg +0 -1
  103. data/lib/decidim/dev/assets/malicious_svg_mask_attribute.svg +0 -1
  104. data/lib/decidim/dev/assets/malicious_svg_script.svg +0 -1
  105. data/lib/decidim/dev/assets/malicious_svg_style_comment_string.svg +0 -1
  106. data/lib/decidim/dev/assets/malicious_svg_style_import.svg +0 -1
  107. data/lib/decidim/dev/assets/malicious_svg_style_import_string.svg +0 -1
  108. data/lib/decidim/dev/assets/malicious_svg_style_url_escape.svg +0 -1
  109. data/lib/decidim/dev/assets/malicious_svg_style_url_string.svg +0 -1
  110. data/lib/decidim/dev/assets/malicious_svg_stylesheet_pi.svg +0 -1
  111. data/lib/decidim/dev/assets/malicious_svg_uri.svg +0 -1
  112. data/lib/decidim/dev/assets/spoofed_image.png +0 -0
  113. data/lib/decidim/dev/assets/spoofed_image_binary.png +0 -1
  114. data/lib/decidim/dev/assets/spoofed_image_html.png +0 -5
  115. data/lib/decidim/dev/assets/spoofed_svg_xml.svg +0 -2
  116. data/lib/decidim/dev/assets/test.avif +0 -0
  117. data/lib/decidim/dev/assets/test.gif +0 -0
  118. data/lib/decidim/dev/assets/test.heic +0 -0
  119. data/lib/decidim/dev/assets/test.svg +0 -1
  120. data/lib/decidim/dev/assets/test_animation.svg +0 -1
  121. data/lib/decidim/dev/assets/test_animation_link.svg +0 -7
  122. data/lib/decidim/dev/assets/test_animation_presentation_reference.svg +0 -8
  123. data/lib/decidim/dev/assets/test_complex.svg +0 -12
  124. data/lib/decidim/dev/assets/test_css_references.svg +0 -14
  125. data/lib/decidim/dev/assets/test_data_uri_declared_encoding.svg +0 -5
  126. data/lib/decidim/dev/assets/test_entity_in_comment.svg +0 -8
  127. data/lib/decidim/dev/assets/test_entity_in_processing_instruction.svg +0 -7
  128. data/lib/decidim/dev/assets/test_percent_encoded_fragment.svg +0 -7
  129. data/lib/decidim/dev/assets/test_percent_encoded_multibyte_reference.svg +0 -7
  130. data/lib/decidim/dev/assets/test_percent_encoded_multibyte_reference_mixed.svg +0 -8
  131. data/lib/decidim/dev/assets/test_presentation_attribute_references.svg +0 -13
  132. data/lib/decidim/dev/assets/test_references.svg +0 -12
  133. data/lib/decidim/dev/assets/test_style_text.svg +0 -9
  134. data/lib/decidim/dev/assets/video.mp4 +0 -0
  135. data/lib/decidim/dev/rubocop/cop/decidim/enforce_permission_to.rb +0 -459
  136. data/lib/decidim/dev/rubocop/cop/decidim/organization_scoped_finder.rb +0 -200
  137. /data/lib/decidim/dev/assets/{import_participatory_space_private_users.csv → import_members.csv} +0 -0
  138. /data/lib/decidim/dev/assets/{import_participatory_space_private_users_invalid_col_sep.csv → import_members_invalid_col_sep.csv} +0 -0
  139. /data/lib/decidim/dev/assets/{import_participatory_space_private_users_iso8859-1.csv → import_members_iso8859-1.csv} +0 -0
  140. /data/lib/decidim/dev/assets/{import_participatory_space_private_users_nok.csv → import_members_nok.csv} +0 -0
  141. /data/lib/decidim/dev/assets/{import_participatory_space_private_users_with_bom.csv → import_members_with_bom.csv} +0 -0
@@ -9,11 +9,14 @@ module Capybara
9
9
  # a better way, we could try actually interacting with the on-screen tom-select-provided UI,
10
10
  # but we are taking the easy way out for now.
11
11
  #
12
- # @param option_id can be the `id` value of an option in the select, OR for select multiple inputs,
13
- # can be an array of such IDs.
12
+ # @param select_selector [String] The CSS selector of the select element.
13
+ # @param option_id [String, Array<String>] The `id` value of an option in the select.
14
+ # For selects with the `multiple` attribute, this can be an array of such IDs.
14
15
  #
15
- # @example tom_select("#select_id", option_id: "2")
16
- # @example tom_select("#select_id", option_id: ["2", "10"]) # `multiple` input.
16
+ # @example
17
+ # tom_select("#select_id", option_id: "2")
18
+ # @example
19
+ # tom_select("#select_id", option_id: ["2", "10"]) # For a `multiple` select input.
17
20
  def tom_select(select_selector, option_id:)
18
21
  js_str = %(document.querySelector("#{select_selector}").tomselect.setValue(#{option_id.inspect}))
19
22
  execute_script(js_str)
@@ -4,7 +4,7 @@ module Decidim
4
4
  # This holds the decidim-dev version.
5
5
  module Dev
6
6
  def self.version
7
- "0.31.8"
7
+ "0.32.0.rc1"
8
8
  end
9
9
  end
10
10
  end
data/lib/decidim/dev.rb CHANGED
@@ -22,7 +22,6 @@ module Decidim
22
22
  # create external libraries that create test apps and test themselves against
23
23
  # them.
24
24
  module Dev
25
- include ActiveSupport::Configurable
26
25
  autoload :DummyTranslator, "decidim/dev/dummy_translator"
27
26
 
28
27
  # Public: Finds an asset.
@@ -34,38 +33,7 @@ module Decidim
34
33
 
35
34
  # Public: Returns a file for testing, just like file fields expect it
36
35
  def self.test_file(filename, content_type)
37
- uploaded_file(asset(filename), content_type)
38
- end
39
-
40
- # Public: Creates a safe uploaded file for tests.
41
- #
42
- # Creating instances of Rack::Test::UploadedFile directly from file paths
43
- # may lead to 0-byte files created in the storage under specific
44
- # configurations/kernels and specifically with Docker containers. This
45
- # method creates a safe uploaded file that does not have this problem.
46
- #
47
- # See:
48
- # https://github.com/rails/rails/issues/41991
49
- # https://github.com/docker/for-mac/issues/5570
50
- # https://github.com/docker/for-linux/issues/1015
51
- #
52
- # @param path [String] The path to the original file
53
- # @param content_type [String] The MIME type for the file
54
- # @param binary [Boolean] Boolean indicating whether the uploaded file's
55
- # tempfile should be in binary mode
56
- # @return [Rack::Test::UploadedFile] A new uploaded test file instance
57
- def self.uploaded_file(path, content_type, binary: false)
58
- original_filename = File.basename(path)
59
- extension = File.extname(original_filename)
60
-
61
- tempfile = Tempfile.open([File.basename(original_filename, extension), extension])
62
- tempfile.binmode if binary
63
- tempfile.write(binary ? File.binread(path) : File.read(path))
64
- tempfile.rewind
65
-
66
- Rack::Test::UploadedFile.new(tempfile, content_type, binary, original_filename:)
67
- ensure
68
- tempfile&.close!
36
+ Rack::Test::UploadedFile.new(asset(filename), content_type)
69
37
  end
70
38
 
71
39
  # Public: add rake tasks
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "erb_lint"
4
+ require "erb_lint/linter"
5
+ require "erb_lint/linter_config"
6
+ require "erb_lint/linter_registry"
7
+ require "erb_lint/offense"
8
+
9
+ module ERBLint
10
+ module Linters
11
+ class AdminPageTitleLinter < Linter
12
+ include LinterRegistry
13
+
14
+ TITLE_SNIPPET = '<% add_decidim_page_title(t(".title")) %>'
15
+ TITLE_SNIPPET_REGEX = /\A<%\s*add_decidim_page_title\(t\(".title".*?\)\)\s*%>/
16
+
17
+ def run(processed_source)
18
+ return unless admin_view?(processed_source.filename)
19
+
20
+ first_line = processed_source.file_content.to_s.lines.first
21
+ return if first_line&.match?(TITLE_SNIPPET_REGEX)
22
+
23
+ add_offense(
24
+ processed_source.to_source_range(0...0),
25
+ "Admin views must start with: #{TITLE_SNIPPET}"
26
+ )
27
+ end
28
+
29
+ private
30
+
31
+ def admin_view?(filename)
32
+ return false unless filename.include?("/app/views/")
33
+ return false unless filename.include?("/admin/")
34
+ return false if filename.include?("/layouts/")
35
+ return false if mailer_view?(filename)
36
+ return false unless filename.end_with?(".html.erb")
37
+
38
+ File.basename(filename).start_with?("_") == false
39
+ end
40
+
41
+ def mailer_view?(filename)
42
+ filename.include?("/mailer/") || filename =~ %r{/\w+_mailer/}
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "erb_lint"
4
+ require "erb_lint/linter"
5
+ require "erb_lint/linter_config"
6
+ require "erb_lint/linter_registry"
7
+ require "erb_lint/offense"
8
+
9
+ module ERBLint
10
+ module Linters
11
+ # Lint ERB partial paths.
12
+ #
13
+ # This linter ensures that partials are rendered with their full path
14
+ # relative to the views directory. For example, in app/views/posts/index.html.erb,
15
+ # it will flag `render "post"` and suggest `render "posts/post"`.
16
+ #
17
+ # It allows configuring prefixes that are exempt from this rule via
18
+ # the `allowed_prefixes` configuration option.
19
+ class PartialPath < Linter
20
+ include LinterRegistry
21
+
22
+ # Configuration schema for the PartialPath linter.
23
+ #
24
+ # @!attribute allowed_prefixes
25
+ # @return [Array<String>] List of prefixes that are allowed to be used without full path
26
+ class ConfigSchema < LinterConfig
27
+ property :allowed_prefixes, accepts: Array
28
+ end
29
+ self.config_schema = ConfigSchema
30
+
31
+ # Runs the linter on the given processed source.
32
+ #
33
+ # This method scans the source code for ERB render calls and checks if they
34
+ # are using the full path for partials. If not, it adds an offense.
35
+ #
36
+ # @param processed_source [ERBLint::ProcessedSource] The processed source to lint
37
+ # @return [void]
38
+ def run(processed_source)
39
+ file_path = processed_source.filename
40
+
41
+ return unless file_path =~ %r{app/views/(.+?)/_?([^/]+)\.html\.erb$}
42
+ return if file_path.include?("/cells/")
43
+
44
+ current_directory = Regexp.last_match(1)
45
+ source = processed_source.file_content
46
+
47
+ source.scan(/<%=\s*render\s+"([^"]+)"[^%]*%>/) do
48
+ partial_path = Regexp.last_match(1)
49
+ start_pos = Regexp.last_match.begin(1)
50
+
51
+ next if partial_path.start_with?("layouts/")
52
+ next if partial_path.start_with?("/")
53
+ next if partial_path.include?("/")
54
+
55
+ next if allowed_prefix?(partial_path)
56
+
57
+ full_path = "#{current_directory}/#{partial_path}"
58
+ range = processed_source.to_source_range(
59
+ start_pos...(start_pos + partial_path.length)
60
+ )
61
+
62
+ add_offense(
63
+ range,
64
+ "Use the full path for partials. Replace `render \"#{partial_path}\"` with `render \"#{full_path}\"`"
65
+ )
66
+ end
67
+ end
68
+
69
+ # Checks if the given path starts with any of the allowed prefixes.
70
+ #
71
+ # @param path [String] The partial path to check
72
+ # @return [Boolean] true if the path starts with an allowed prefix, false otherwise
73
+ def allowed_prefix?(path)
74
+ return false unless @config.allowed_prefixes
75
+
76
+ @config.allowed_prefixes.any? { |prefix| path.start_with?(prefix) }
77
+ end
78
+
79
+ # Generates the autocorrection lambda for the given offense.
80
+ #
81
+ # This method creates a lambda that will replace the partial path with its
82
+ # full path when the linter's autocorrect feature is used.
83
+ #
84
+ # @param processed_source [ERBLint::ProcessedSource] The processed source containing the offense
85
+ # @param offense [ERBLint::Offense] The offense to generate a correction for
86
+ # @return [Proc, nil] A lambda that performs the correction, or nil if correction is not possible
87
+ def autocorrect(processed_source, offense)
88
+ return unless processed_source.filename =~ %r{app/views/(.+?)/_?([^/]+)\.html\.erb$}
89
+ return if processed_source.filename.include?("/cells/")
90
+
91
+ current_directory = Regexp.last_match(1)
92
+
93
+ lambda do |corrector|
94
+ partial_path = offense.source_range.source
95
+ full_path = "#{current_directory}/#{partial_path}"
96
+ corrector.replace(offense.source_range, full_path)
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
data/rubocop-decidim.yml CHANGED
@@ -25,5 +25,6 @@ inherit_from:
25
25
  - config/rubocop/graphql/disabled.yml
26
26
  - config/rubocop/factory_bot/configuration.yml
27
27
  - config/rubocop/factory_bot/disabled.yml
28
+ - config/rubocop/yard/configuration.yml
28
29
  - config/rubocop/disabled.yml
29
30
  - config/rubocop/decidim-linters/configuration.yml