decidim-comments 0.30.1 → 0.31.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 (89) hide show
  1. checksums.yaml +4 -4
  2. data/app/cells/decidim/comments/comment/deletion_data.erb +1 -1
  3. data/app/cells/decidim/comments/comment/show.erb +12 -12
  4. data/app/cells/decidim/comments/comment/votes.erb +4 -4
  5. data/app/cells/decidim/comments/comment_cell.rb +1 -3
  6. data/app/cells/decidim/comments/comment_form/comment_as.erb +5 -24
  7. data/app/cells/decidim/comments/comment_form/opinion.erb +3 -3
  8. data/app/cells/decidim/comments/comment_form/show.erb +3 -3
  9. data/app/cells/decidim/comments/comment_form_cell.rb +5 -20
  10. data/app/cells/decidim/comments/comments/order_control.erb +1 -1
  11. data/app/cells/decidim/comments/edit_comment_modal_form/show.erb +2 -2
  12. data/app/commands/decidim/comments/create_comment.rb +3 -5
  13. data/app/events/decidim/comments/comment_event.rb +3 -10
  14. data/app/forms/decidim/comments/comment_form.rb +0 -1
  15. data/app/models/decidim/comments/comment.rb +2 -2
  16. data/app/models/decidim/comments/seed.rb +4 -16
  17. data/app/packs/src/decidim/comments/comments.component.js +0 -7
  18. data/app/packs/src/decidim/comments/comments.component.test.js +4 -16
  19. data/app/packs/src/decidim/comments/comments.js +1 -1
  20. data/app/packs/src/decidim/comments/comments_mobile_modal.js +1 -1
  21. data/app/packs/stylesheets/comments.scss +2 -6
  22. data/app/queries/decidim/comments/sorted_comments.rb +1 -1
  23. data/app/services/decidim/comments/new_comment_notification_creator.rb +2 -27
  24. data/app/views/decidim/comments/admin/shared/_availability_fields.html.erb +1 -1
  25. data/app/views/decidim/comments/comments/delete.js.erb +4 -2
  26. data/app/views/decidim/comments/comments/reload.js.erb +0 -1
  27. data/app/views/decidim/comments/comments/update.js.erb +3 -1
  28. data/app/views/decidim/comments/votes/create.js.erb +26 -7
  29. data/config/assets.rb +2 -2
  30. data/config/locales/ar.yml +0 -18
  31. data/config/locales/bg.yml +0 -18
  32. data/config/locales/bs-BA.yml +0 -8
  33. data/config/locales/ca-IT.yml +6 -20
  34. data/config/locales/ca.yml +6 -20
  35. data/config/locales/cs.yml +0 -20
  36. data/config/locales/de.yml +6 -20
  37. data/config/locales/el.yml +0 -18
  38. data/config/locales/en.yml +6 -20
  39. data/config/locales/es-MX.yml +6 -20
  40. data/config/locales/es-PY.yml +6 -20
  41. data/config/locales/es.yml +6 -20
  42. data/config/locales/eu.yml +6 -20
  43. data/config/locales/fi-plain.yml +8 -20
  44. data/config/locales/fi.yml +8 -20
  45. data/config/locales/fr-CA.yml +6 -23
  46. data/config/locales/fr.yml +6 -23
  47. data/config/locales/ga-IE.yml +0 -5
  48. data/config/locales/gl.yml +0 -11
  49. data/config/locales/hu.yml +0 -18
  50. data/config/locales/id-ID.yml +0 -11
  51. data/config/locales/is-IS.yml +0 -5
  52. data/config/locales/it.yml +0 -18
  53. data/config/locales/ja.yml +4 -20
  54. data/config/locales/lb.yml +0 -18
  55. data/config/locales/lt.yml +0 -18
  56. data/config/locales/lv.yml +0 -18
  57. data/config/locales/nl.yml +0 -18
  58. data/config/locales/no.yml +0 -18
  59. data/config/locales/pl.yml +0 -18
  60. data/config/locales/pt-BR.yml +0 -18
  61. data/config/locales/pt.yml +0 -18
  62. data/config/locales/ro-RO.yml +0 -20
  63. data/config/locales/ru.yml +0 -11
  64. data/config/locales/si-LK.yml +0 -2
  65. data/config/locales/sk.yml +0 -18
  66. data/config/locales/sq-AL.yml +0 -2
  67. data/config/locales/sr-CS.yml +0 -9
  68. data/config/locales/sv.yml +0 -20
  69. data/config/locales/tr-TR.yml +0 -18
  70. data/config/locales/uk.yml +0 -6
  71. data/config/locales/zh-CN.yml +0 -18
  72. data/config/locales/zh-TW.yml +0 -18
  73. data/db/migrate/20181003080320_fix_user_groups_ids_in_comments.rb +8 -1
  74. data/lib/decidim/api/comment_type.rb +1 -4
  75. data/lib/decidim/api/commentable_interface.rb +7 -13
  76. data/lib/decidim/api/commentable_mutation_type.rb +2 -3
  77. data/lib/decidim/comments/comment_serializer.rb +0 -4
  78. data/lib/decidim/comments/comment_vote_serializer.rb +0 -4
  79. data/lib/decidim/comments/commentable.rb +4 -0
  80. data/lib/decidim/comments/engine.rb +6 -20
  81. data/lib/decidim/comments/test/factories.rb +1 -1
  82. data/lib/decidim/comments/test/shared_examples/comment_event.rb +1 -10
  83. data/lib/decidim/comments/test/shared_examples/create_comment_context.rb +0 -2
  84. data/lib/decidim/comments/version.rb +1 -1
  85. metadata +8 -12
  86. data/app/events/decidim/comments/comment_by_followed_user_group_event.rb +0 -9
  87. data/app/events/decidim/comments/user_group_mentioned_event.rb +0 -10
  88. data/app/queries/decidim/comments/metrics/comment_participants_metric_measure.rb +0 -50
  89. data/app/queries/decidim/comments/metrics/comments_metric_manage.rb +0 -97
@@ -8,12 +8,11 @@ module Decidim
8
8
  field :add_comment, Decidim::Comments::CommentType, description: "Add a new comment to a commentable", null: true do
9
9
  argument :alignment, GraphQL::Types::Int, "The comment's alignment. Can be 0 (neutral), 1 (in favor) or -1 (against)'", default_value: 0, required: false
10
10
  argument :body, GraphQL::Types::String, "The comments's body", required: true
11
- argument :user_group_id, GraphQL::Types::ID, "The comment's user group id. Replaces the author.", required: false
12
11
  end
13
12
  field :id, GraphQL::Types::ID, "The Commentable's unique ID", null: false
14
13
 
15
- def add_comment(body:, alignment: nil, user_group_id: nil)
16
- params = { "comment" => { "body" => body, "alignment" => alignment, "user_group_id" => user_group_id, "commentable" => object } }
14
+ def add_comment(body:, alignment: nil)
15
+ params = { "comment" => { "body" => body, "alignment" => alignment, "commentable" => object } }
17
16
  form = Decidim::Comments::CommentForm.from_params(params).with_context(
18
17
  current_organization: context[:current_organization],
19
18
  current_user: context[:current_user],
@@ -19,10 +19,6 @@ module Decidim
19
19
  },
20
20
  alignment: resource.alignment,
21
21
  depth: resource.depth,
22
- user_group: {
23
- id: resource.user_group.try(:id),
24
- name: resource.user_group.try(:name) || empty_translatable
25
- },
26
22
  commentable_id: resource.decidim_commentable_id,
27
23
  commentable_type: resource.decidim_commentable_type,
28
24
  root_commentable_url:
@@ -20,10 +20,6 @@ module Decidim
20
20
  },
21
21
  alignment: resource.comment.alignment,
22
22
  depth: resource.comment.depth,
23
- user_group: {
24
- id: resource.comment.user_group.try(:id),
25
- name: resource.comment.user_group.try(:name)
26
- },
27
23
  commentable_id: resource.comment.decidim_commentable_id,
28
24
  commentable_type: resource.comment.decidim_commentable_type,
29
25
  root_commentable_url:
@@ -17,6 +17,10 @@ module Decidim
17
17
  true
18
18
  end
19
19
 
20
+ def has_comments?
21
+ comment_threads.not_hidden.size.positive?
22
+ end
23
+
20
24
  # Public: Whether the object can have new comments or not.
21
25
  def accepts_new_comments?
22
26
  true
@@ -35,9 +35,12 @@ module Decidim
35
35
  end
36
36
 
37
37
  initializer "decidim_comments.stats" do
38
- Decidim.stats.register :comments_count, priority: StatsRegistry::MEDIUM_PRIORITY do |organization|
38
+ Decidim.stats.register :comments_count,
39
+ priority: StatsRegistry::HIGH_PRIORITY,
40
+ icon_name: "chat-1-line",
41
+ tooltip_key: "comments_count" do |organization|
39
42
  Decidim.component_manifests.sum do |component|
40
- component.stats.filter(tag: :comments).with_context(organization.published_components).map { |_name, value| value }.sum
43
+ component.stats.filter(tag: :comments).with_context(organization.published_components).map { |_name, value| value }.compact_blank.sum
41
44
  end
42
45
  end
43
46
  end
@@ -56,23 +59,6 @@ module Decidim
56
59
  Decidim.icons.register(name: "edit-line", icon: "edit-line", description: "Edit comment button", **common_parameters)
57
60
  end
58
61
 
59
- initializer "decidim_comments.register_metrics" do
60
- Decidim.metrics_registry.register(:comments) do |metric_registry|
61
- metric_registry.manager_class = "Decidim::Comments::Metrics::CommentsMetricManage"
62
-
63
- metric_registry.settings do |settings|
64
- settings.attribute :highlighted, type: :boolean, default: false
65
- settings.attribute :scopes, type: :array, default: %w(home participatory_process)
66
- settings.attribute :weight, type: :integer, default: 6
67
- settings.attribute :stat_block, type: :string, default: "small"
68
- end
69
- end
70
-
71
- Decidim.metrics_operation.register(:participants, :comments) do |metric_operation|
72
- metric_operation.manager_class = "Decidim::Comments::Metrics::CommentParticipantsMetricMeasure"
73
- end
74
- end
75
-
76
62
  initializer "decidim_comments.register_resources" do
77
63
  Decidim.register_resource(:comment) do |resource|
78
64
  resource.model_class_name = "Decidim::Comments::Comment"
@@ -86,7 +72,7 @@ module Decidim
86
72
  Cell::ViewModel.view_paths << File.expand_path("#{Decidim::Comments::Engine.root}/app/views") # for partials
87
73
  end
88
74
 
89
- initializer "decidim_comments.webpacker.assets_path" do
75
+ initializer "decidim_comments.shakapacker.assets_path" do
90
76
  Decidim.register_assets_path File.expand_path("app/packs", root)
91
77
  end
92
78
 
@@ -19,7 +19,7 @@ FactoryBot.define do
19
19
  else
20
20
  evaluator.body
21
21
  end
22
- comment.body = Decidim::ContentProcessor.parse_with_processor(:hashtag, comment.body, current_organization: comment.root_commentable.organization).rewrite
22
+ comment.body = Decidim::ContentProcessor.parse(comment.body, current_organization: comment.root_commentable.organization).rewrite
23
23
  end
24
24
 
25
25
  trait :deleted do
@@ -17,11 +17,6 @@ shared_context "when it is a comment event" do
17
17
 
18
18
  let(:extra) { { comment_id: comment.id } }
19
19
  let(:resource_title) { decidim_sanitize_translated(resource.title) }
20
- let(:user_group) do
21
- user_group = create(:user_group, :verified, organization:, users: [comment_author])
22
- comment.update!(user_group:)
23
- user_group
24
- end
25
20
  end
26
21
 
27
22
  shared_examples_for "a comment event" do
@@ -29,11 +24,7 @@ shared_examples_for "a comment event" do
29
24
 
30
25
  describe "author" do
31
26
  it "returns the comment author" do
32
- if defined? user_group_author
33
- expect(subject.author).to eq(user_group_author)
34
- else
35
- expect(subject.author).to eq(comment_author)
36
- end
27
+ expect(subject.author).to eq(comment_author)
37
28
  end
38
29
  end
39
30
 
@@ -11,13 +11,11 @@ RSpec.shared_context "when creating a comment" do
11
11
  let(:commentable) { dummy_resource }
12
12
  let(:body) { Faker::Lorem.paragraph }
13
13
  let(:alignment) { 1 }
14
- let(:user_group_id) { nil }
15
14
  let(:form_params) do
16
15
  {
17
16
  "comment" => {
18
17
  "body" => body,
19
18
  "alignment" => alignment,
20
- "user_group_id" => user_group_id,
21
19
  "commentable" => commentable
22
20
  }
23
21
  }
@@ -4,7 +4,7 @@ module Decidim
4
4
  # This holds the decidim-comments version.
5
5
  module Comments
6
6
  def self.version
7
- "0.30.1"
7
+ "0.31.0.rc1"
8
8
  end
9
9
  end
10
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decidim-comments
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.30.1
4
+ version: 0.31.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josep Jaume Rey Peroy
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2025-06-17 00:00:00.000000000 Z
13
+ date: 2025-09-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: decidim-core
@@ -18,14 +18,14 @@ dependencies:
18
18
  requirements:
19
19
  - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: 0.30.1
21
+ version: 0.31.0.rc1
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - '='
27
27
  - !ruby/object:Gem::Version
28
- version: 0.30.1
28
+ version: 0.31.0.rc1
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: redcarpet
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -52,28 +52,28 @@ dependencies:
52
52
  requirements:
53
53
  - - '='
54
54
  - !ruby/object:Gem::Version
55
- version: 0.30.1
55
+ version: 0.31.0.rc1
56
56
  type: :development
57
57
  prerelease: false
58
58
  version_requirements: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - '='
61
61
  - !ruby/object:Gem::Version
62
- version: 0.30.1
62
+ version: 0.31.0.rc1
63
63
  - !ruby/object:Gem::Dependency
64
64
  name: decidim-dev
65
65
  requirement: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - '='
68
68
  - !ruby/object:Gem::Version
69
- version: 0.30.1
69
+ version: 0.31.0.rc1
70
70
  type: :development
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  requirements:
74
74
  - - '='
75
75
  - !ruby/object:Gem::Version
76
- version: 0.30.1
76
+ version: 0.31.0.rc1
77
77
  description: Pluggable comments system for some components.
78
78
  email:
79
79
  - josepjaume@gmail.com
@@ -126,14 +126,12 @@ files:
126
126
  - app/controllers/decidim/comments/comments_controller.rb
127
127
  - app/controllers/decidim/comments/votes_controller.rb
128
128
  - app/events/decidim/comments/comment_by_followed_user_event.rb
129
- - app/events/decidim/comments/comment_by_followed_user_group_event.rb
130
129
  - app/events/decidim/comments/comment_created_event.rb
131
130
  - app/events/decidim/comments/comment_downvoted_event.rb
132
131
  - app/events/decidim/comments/comment_event.rb
133
132
  - app/events/decidim/comments/comment_upvoted_event.rb
134
133
  - app/events/decidim/comments/comment_voted_event.rb
135
134
  - app/events/decidim/comments/reply_created_event.rb
136
- - app/events/decidim/comments/user_group_mentioned_event.rb
137
135
  - app/events/decidim/comments/user_mentioned_event.rb
138
136
  - app/forms/decidim/comments/comment_form.rb
139
137
  - app/helpers/decidim/comments/comment_cells_helper.rb
@@ -151,8 +149,6 @@ files:
151
149
  - app/packs/src/decidim/comments/comments_mobile_modal.js
152
150
  - app/packs/stylesheets/comments.scss
153
151
  - app/permissions/decidim/comments/permissions.rb
154
- - app/queries/decidim/comments/metrics/comment_participants_metric_measure.rb
155
- - app/queries/decidim/comments/metrics/comments_metric_manage.rb
156
152
  - app/queries/decidim/comments/sorted_comments.rb
157
153
  - app/resolvers/decidim/comments/vote_comment_resolver.rb
158
154
  - app/scrubbers/decidim/comments/user_input_scrubber.rb
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Decidim
4
- module Comments
5
- class CommentByFollowedUserGroupEvent < Decidim::Events::SimpleEvent
6
- include Decidim::Comments::CommentEvent
7
- end
8
- end
9
- end
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Decidim
4
- module Comments
5
- class UserGroupMentionedEvent < Decidim::Events::SimpleEvent
6
- include Decidim::Comments::CommentEvent
7
- include Decidim::Events::UserGroupEvent
8
- end
9
- end
10
- end
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Decidim
4
- module Comments
5
- module Metrics
6
- # Searches for Participants in the following actions
7
- # - Leave a comment (Comments)
8
- class CommentParticipantsMetricMeasure < Decidim::MetricMeasure
9
- def valid?
10
- super && @resource.is_a?(Decidim::Participable)
11
- end
12
-
13
- def calculate
14
- cumulative_users = []
15
- quantity_users = []
16
-
17
- retrieve_comments_for_organization.each do |comment|
18
- related_object = comment.root_commentable
19
- next unless related_object
20
- next unless check_participatory_space(@resource, related_object)
21
-
22
- cumulative_users << comment.decidim_author_id
23
- quantity_users << comment.decidim_author_id if comment.created_at >= start_time
24
- end
25
- {
26
- cumulative_users: cumulative_users.uniq,
27
- quantity_users: quantity_users.uniq
28
- }
29
- end
30
-
31
- private
32
-
33
- def check_participatory_space(participatory_space, related_object)
34
- return related_object.participatory_space == participatory_space if related_object.respond_to?(:participatory_space)
35
- return related_object == participatory_space if related_object.is_a?(Decidim::Participable)
36
-
37
- false
38
- end
39
-
40
- def retrieve_comments_for_organization
41
- user_ids = Decidim::User.where(organization: @resource.organization).pluck(:id)
42
- Decidim::Comments::Comment.includes(:root_commentable).not_hidden.not_deleted
43
- .where(decidim_comments_comments: { created_at: ..end_time })
44
- .where(decidim_comments_comments: { decidim_author_id: user_ids })
45
- .where(decidim_comments_comments: { decidim_author_type: "Decidim::UserBaseEntity" })
46
- end
47
- end
48
- end
49
- end
50
- end
@@ -1,97 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Decidim
4
- module Comments
5
- module Metrics
6
- class CommentsMetricManage < Decidim::MetricManage
7
- def metric_name
8
- "comments"
9
- end
10
-
11
- def save
12
- query.each do |key, results|
13
- cumulative_value = results[:cumulative]
14
- next if cumulative_value.zero?
15
-
16
- quantity_value = results[:quantity] || 0
17
- space_type, space_id, taxonomy_id, related_object_type, related_object_id = key
18
- record = Decidim::Metric.find_or_initialize_by(day: @day.to_s, metric_type: @metric_name,
19
- participatory_space_type: space_type, participatory_space_id: space_id,
20
- organization: @organization, decidim_taxonomy_id: taxonomy_id,
21
- related_object_type:, related_object_id:)
22
- record.assign_attributes(cumulative: cumulative_value, quantity: quantity_value)
23
- record.save!
24
- end
25
- end
26
-
27
- private
28
-
29
- # Creates a Hashed structure with comments grouped by
30
- #
31
- # - ParticipatorySpace (type & ID)
32
- # - Taxonomy (ID)
33
- # - RelatedObject (type & ID)
34
- #
35
- def query
36
- return @query if @query
37
-
38
- @query = retrieve_comments.each_with_object({}) do |comment, grouped_comments|
39
- related_object = comment.root_commentable
40
- next grouped_comments unless related_object
41
-
42
- group_keys = generate_group_keys(related_object)
43
-
44
- next grouped_comments unless group_keys
45
-
46
- group_keys.map do |group_key|
47
- grouped_comments[group_key] ||= { cumulative: 0, quantity: 0 }
48
- grouped_comments[group_key][:cumulative] += 1
49
- grouped_comments[group_key][:quantity] += 1 if comment.created_at >= start_time
50
- end
51
- end
52
-
53
- @query
54
- end
55
-
56
- # Retrieve Comments generated within an Organization
57
- #
58
- # Uses 'author' and 'user_group' relationship
59
- #
60
- def retrieve_comments
61
- user_ids = Decidim::User.select(:id).where(organization: @organization).collect(&:id)
62
- user_group_ids = Decidim::UserGroup.select(:id).where(organization: @organization).collect(&:id)
63
- Decidim::Comments::Comment.includes(:root_commentable).not_hidden.not_deleted
64
- .where(decidim_comments_comments: { created_at: ..end_time })
65
- .where("decidim_comments_comments.decidim_author_id IN (?) OR
66
- decidim_comments_comments.decidim_user_group_id IN (?)", user_ids, user_group_ids)
67
- end
68
-
69
- # Generates a group key from the related object of a Comment
70
- def generate_group_keys(related_object)
71
- participatory_space = retrieve_participatory_space(related_object)
72
- return unless participatory_space
73
-
74
- return unless related_object.respond_to?(:taxonomies)
75
-
76
- taxonomy_ids = related_object.taxonomies.pluck(:id)
77
- taxonomy_ids.each_with_object([]) do |taxonomy_id, group_keys|
78
- group_key = []
79
- group_key += [participatory_space.class.name, participatory_space.id]
80
- group_key += [taxonomy_id]
81
- group_key += [related_object.class.name, related_object.id]
82
- group_keys << group_key
83
- end
84
- end
85
-
86
- # Gets current ParticipatorySpace of a given 'related_object'
87
- def retrieve_participatory_space(related_object)
88
- if related_object.respond_to?(:participatory_space)
89
- related_object.participatory_space
90
- elsif related_object.is_a?(Decidim::Participable)
91
- related_object
92
- end
93
- end
94
- end
95
- end
96
- end
97
- end