decidim-comments 0.29.2 → 0.30.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/app/cells/decidim/comments/comment/actions.erb +0 -8
  3. data/app/cells/decidim/comments/comment/show.erb +41 -5
  4. data/app/cells/decidim/comments/comment_cell.rb +44 -0
  5. data/app/cells/decidim/comments/comment_form/comment_as.erb +24 -6
  6. data/app/cells/decidim/comments/comment_form/opinion.erb +0 -4
  7. data/app/cells/decidim/comments/comment_form/show.erb +31 -29
  8. data/app/cells/decidim/comments/comment_form_cell.rb +7 -2
  9. data/app/cells/decidim/comments/comment_thread/show.erb +1 -1
  10. data/app/cells/decidim/comments/comments/add_comment.erb +12 -14
  11. data/app/cells/decidim/comments/comments/comments_in_single_column.erb +6 -0
  12. data/app/cells/decidim/comments/comments/order_control.erb +32 -9
  13. data/app/cells/decidim/comments/comments/show.erb +7 -7
  14. data/app/cells/decidim/comments/comments_cell.rb +56 -12
  15. data/app/cells/decidim/comments/two_columns_comments/column.erb +20 -0
  16. data/app/cells/decidim/comments/two_columns_comments/show.erb +11 -0
  17. data/app/cells/decidim/comments/two_columns_comments_cell.rb +86 -0
  18. data/app/forms/decidim/comments/comment_form.rb +14 -0
  19. data/app/models/decidim/comments/comment.rb +9 -7
  20. data/app/packs/entrypoints/decidim_comments.js +1 -0
  21. data/app/packs/src/decidim/comments/comments.component.js +151 -24
  22. data/app/packs/src/decidim/comments/comments.component.test.js +2 -1
  23. data/app/packs/src/decidim/comments/comments.js +95 -12
  24. data/app/packs/src/decidim/comments/comments_dropdown.js +57 -0
  25. data/app/packs/src/decidim/comments/comments_mobile_modal.js +46 -0
  26. data/app/packs/stylesheets/comments.scss +203 -50
  27. data/app/queries/decidim/comments/metrics/comment_participants_metric_measure.rb +1 -1
  28. data/app/queries/decidim/comments/metrics/comments_metric_manage.rb +22 -17
  29. data/app/views/decidim/comments/comments/create.js.erb +9 -1
  30. data/config/locales/ar.yml +0 -1
  31. data/config/locales/bg.yml +0 -1
  32. data/config/locales/ca.yml +35 -2
  33. data/config/locales/cs.yml +37 -2
  34. data/config/locales/de.yml +35 -2
  35. data/config/locales/el.yml +0 -1
  36. data/config/locales/en.yml +35 -2
  37. data/config/locales/es-MX.yml +35 -2
  38. data/config/locales/es-PY.yml +35 -2
  39. data/config/locales/es.yml +35 -2
  40. data/config/locales/eu.yml +37 -4
  41. data/config/locales/fi-plain.yml +35 -2
  42. data/config/locales/fi.yml +35 -2
  43. data/config/locales/fr-CA.yml +8 -2
  44. data/config/locales/fr.yml +8 -2
  45. data/config/locales/gl.yml +0 -1
  46. data/config/locales/hu.yml +0 -1
  47. data/config/locales/id-ID.yml +0 -1
  48. data/config/locales/is-IS.yml +0 -1
  49. data/config/locales/it.yml +1 -1
  50. data/config/locales/ja.yml +34 -2
  51. data/config/locales/lb.yml +0 -1
  52. data/config/locales/lt.yml +0 -1
  53. data/config/locales/lv.yml +0 -1
  54. data/config/locales/nl.yml +0 -1
  55. data/config/locales/no.yml +0 -1
  56. data/config/locales/pl.yml +0 -2
  57. data/config/locales/pt-BR.yml +0 -1
  58. data/config/locales/pt.yml +0 -1
  59. data/config/locales/ro-RO.yml +1 -2
  60. data/config/locales/ru.yml +0 -1
  61. data/config/locales/sk.yml +0 -1
  62. data/config/locales/sv.yml +19 -2
  63. data/config/locales/tr-TR.yml +0 -1
  64. data/config/locales/uk.yml +0 -1
  65. data/config/locales/zh-CN.yml +0 -1
  66. data/config/locales/zh-TW.yml +0 -1
  67. data/decidim-comments.gemspec +1 -1
  68. data/lib/decidim/api/comment_mutation_type.rb +2 -2
  69. data/lib/decidim/api/comment_type.rb +12 -45
  70. data/lib/decidim/api/commentable_interface.rb +4 -16
  71. data/lib/decidim/api/commentable_mutation_type.rb +2 -3
  72. data/lib/decidim/comments/commentable.rb +11 -0
  73. data/lib/decidim/comments/engine.rb +7 -1
  74. data/lib/decidim/comments/test/factories.rb +8 -0
  75. data/lib/decidim/comments/test/shared_examples/comment_event.rb +1 -1
  76. data/lib/decidim/comments/test/shared_examples/comment_voted_event.rb +2 -2
  77. data/lib/decidim/comments/test/shared_examples/create_comment_context.rb +1 -1
  78. data/lib/decidim/comments/test/shared_examples/translatable_comment.rb +2 -2
  79. data/lib/decidim/comments/version.rb +1 -1
  80. metadata +16 -10
@@ -4,37 +4,24 @@ module Decidim
4
4
  module Comments
5
5
  # This type represents a comment on a commentable object.
6
6
  class CommentType < Decidim::Api::Types::BaseObject
7
- description "A comment"
8
-
7
+ implements Decidim::Core::TimestampsInterface
9
8
  implements Decidim::Comments::CommentableInterface
10
- field :author, Decidim::Core::AuthorInterface, "The resource author", null: false
11
-
12
- field :id, GraphQL::Types::ID, "The Comment's unique ID", null: false
13
-
14
- field :sgid, GraphQL::Types::String, "The Comment's signed global id", null: false
15
-
16
- field :body, GraphQL::Types::String, "The comment message", null: false
17
-
18
- field :formatted_body, GraphQL::Types::String, "The comment message ready to display (it is expected to include HTML)", null: false
19
9
 
20
- field :created_at, GraphQL::Types::String, "The creation date of the comment", null: false
21
-
22
- field :formatted_created_at, GraphQL::Types::String, "The creation date of the comment in relative format", null: false
10
+ description "A comment"
23
11
 
24
12
  field :alignment, GraphQL::Types::Int, "The comment's alignment. Can be 0 (neutral), 1 (in favor) or -1 (against)'", null: true
25
-
26
- field :up_votes, GraphQL::Types::Int, "The number of comment's upVotes", null: false
27
-
28
- field :up_voted, GraphQL::Types::Boolean, "Check if the current user has upvoted the comment", null: false
29
-
30
- field :down_votes, GraphQL::Types::Int, "The number of comment's downVotes", null: false
31
-
13
+ field :already_reported, GraphQL::Types::Boolean, "Check if the current user has reported the comment", null: false
14
+ field :author, Decidim::Core::AuthorInterface, "The resource author", null: false
15
+ field :body, GraphQL::Types::String, "The comment message", null: false, method: :translated_body
32
16
  field :down_voted, GraphQL::Types::Boolean, "Check if the current user has downvoted the comment", null: false
33
-
17
+ field :down_votes, GraphQL::Types::Int, "The number of comment's downVotes", null: false, method: :down_votes_count
18
+ field :formatted_body, GraphQL::Types::String, "The comment message ready to display (it is expected to include HTML)", null: false
19
+ field :formatted_created_at, GraphQL::Types::String, "The creation date of the comment in relative format", null: false, method: :friendly_created_at
34
20
  field :has_comments, GraphQL::Types::Boolean, "Check if the commentable has comments", method: :has_comments?, null: false
35
-
36
- field :already_reported, GraphQL::Types::Boolean, "Check if the current user has reported the comment", null: false
37
-
21
+ field :id, GraphQL::Types::ID, "The Comment's unique ID", null: false
22
+ field :sgid, GraphQL::Types::String, "The Comment's signed global id", null: false
23
+ field :up_voted, GraphQL::Types::Boolean, "Check if the current user has upvoted the comment", null: false
24
+ field :up_votes, GraphQL::Types::Int, "The number of comment's upVotes", null: false, method: :up_votes_count
38
25
  field :user_allowed_to_comment, GraphQL::Types::Boolean, "Check if the current user can comment", null: false
39
26
 
40
27
  def author
@@ -45,30 +32,10 @@ module Decidim
45
32
  object.to_sgid.to_s
46
33
  end
47
34
 
48
- def body
49
- object.translated_body
50
- end
51
-
52
- def created_at
53
- object.created_at.iso8601
54
- end
55
-
56
- def formatted_created_at
57
- object.friendly_created_at
58
- end
59
-
60
- def up_votes
61
- object.up_votes_count
62
- end
63
-
64
35
  def up_voted
65
36
  object.up_voted_by?(context[:current_user])
66
37
  end
67
38
 
68
- def down_votes
69
- object.down_votes_count
70
- end
71
-
72
39
  def down_voted
73
40
  object.down_voted_by?(context[:current_user])
74
41
  end
@@ -8,40 +8,28 @@ module Decidim
8
8
  description "A commentable interface"
9
9
 
10
10
  field :id, GraphQL::Types::ID, "The commentable's ID", null: false
11
-
12
11
  field :type, GraphQL::Types::String, "The commentable's class name. i.e. `Decidim::ParticipatoryProcess`", method: :commentable_type, null: false
13
-
14
12
  field :accepts_new_comments, GraphQL::Types::Boolean, "Whether the object can have new comments or not", method: :accepts_new_comments?, null: false
15
-
16
13
  field :comments_have_alignment, GraphQL::Types::Boolean, "Whether the object comments have alignment or not", method: :comments_have_alignment?, null: false
17
-
18
14
  field :comments_have_votes, GraphQL::Types::Boolean, "Whether the object comments have votes or not", method: :comments_have_votes?, null: false
19
-
20
- field :comments, [Decidim::Comments::CommentType, { null: false }], null: false do
15
+ field :total_comments_count, GraphQL::Types::Int, description: "The number of comments in all levels this resource holds", method: :comments_count, null: false
16
+ field :has_comments, GraphQL::Types::Boolean, "Check if the commentable has comments", null: false
17
+ field :user_allowed_to_comment, GraphQL::Types::Boolean, "Check if the current user can comment", null: false
18
+ field :comments, [Decidim::Comments::CommentType, { null: false }], "The list of replies in this comment", null: false do
21
19
  argument :order_by, GraphQL::Types::String, "Order the comments", required: false
22
20
  argument :single_comment_id, GraphQL::Types::String, "ID of the single comment to look at", required: false
23
21
  end
24
22
 
25
- field :total_comments_count, GraphQL::Types::Int, description: "The number of comments in all levels this resource holds", null: false
26
-
27
23
  def comments(order_by: nil, single_comment_id: nil)
28
24
  SortedComments.for(object, order_by:, id: single_comment_id).not_hidden
29
25
  end
30
26
 
31
- def total_comments_count
32
- object.comments_count
33
- end
34
-
35
- field :has_comments, GraphQL::Types::Boolean, "Check if the commentable has comments", null: false
36
-
37
27
  # rubocop:disable Naming/PredicateName
38
28
  def has_comments
39
29
  object.comment_threads.not_hidden.size.positive?
40
30
  end
41
31
  # rubocop:enable Naming/PredicateName
42
32
 
43
- field :user_allowed_to_comment, GraphQL::Types::Boolean, "Check if the current user can comment", null: false
44
-
45
33
  def user_allowed_to_comment
46
34
  object.commentable? && object.user_allowed_to_comment?(context[:current_user])
47
35
  end
@@ -5,13 +5,12 @@ module Decidim
5
5
  class CommentableMutationType < Decidim::Api::Types::BaseObject
6
6
  description "A commentable which includes its available mutations"
7
7
 
8
- field :id, GraphQL::Types::ID, "The Commentable's unique ID", null: false
9
-
10
8
  field :add_comment, Decidim::Comments::CommentType, description: "Add a new comment to a commentable", null: true do
11
- argument :body, GraphQL::Types::String, "The comments's body", required: true
12
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
+ argument :body, GraphQL::Types::String, "The comments's body", required: true
13
11
  argument :user_group_id, GraphQL::Types::ID, "The comment's user group id. Replaces the author.", required: false
14
12
  end
13
+ field :id, GraphQL::Types::ID, "The Commentable's unique ID", null: false
15
14
 
16
15
  def add_comment(body:, alignment: nil, user_group_id: nil)
17
16
  params = { "comment" => { "body" => body, "alignment" => alignment, "user_group_id" => user_group_id, "commentable" => object } }
@@ -67,6 +67,17 @@ module Decidim
67
67
  update_columns(comments_count:, updated_at: Time.current)
68
68
  end
69
69
  # rubocop:enable Rails/SkipsModelValidations
70
+
71
+ # Public: Returns an array with extra actions available for a comment and a user.
72
+ # Returns an array of hashes with the following keys:
73
+ # - label: The label to be displayed in the UI.
74
+ # - url: The action to be performed when the user clicks the label.
75
+ # - method: The HTTP method to be used when performing the action (optional).
76
+ # - icon: The icon to be displayed next to the label (optional).
77
+ # - data: Any "data-*" attributes to be included in the link (optional).
78
+ def actions_for_comment(_comment, _current_user)
79
+ []
80
+ end
70
81
  end
71
82
  end
72
83
  end
@@ -4,7 +4,6 @@ require "rails"
4
4
  require "active_support/all"
5
5
 
6
6
  require "decidim/core"
7
- require "foundation_rails_helper"
8
7
 
9
8
  require "decidim/comments/query_extensions"
10
9
  require "decidim/comments/mutation_extensions"
@@ -21,6 +20,12 @@ module Decidim
21
20
  end
22
21
  end
23
22
 
23
+ initializer "decidim_comments.mount_routes" do
24
+ Decidim::Core::Engine.routes do
25
+ mount Decidim::Comments::Engine, at: "/", as: "decidim_comments"
26
+ end
27
+ end
28
+
24
29
  initializer "decidim_comments.query_extensions" do
25
30
  Decidim::Api::QueryType.include QueryExtensions
26
31
  end
@@ -42,6 +47,7 @@ module Decidim
42
47
 
43
48
  Decidim.icons.register(name: "Decidim::Comments::Comment", icon: "chat-1-line", description: "Comment", category: "activity", engine: :comments)
44
49
  Decidim.icons.register(name: "comments_count", icon: "wechat-line", description: "Comments Count", category: "activity", engine: :comments)
50
+ Decidim.icons.register(name: "star-s-line", icon: "star-s-line", description: "Most upvoted comment", category: "activity", engine: :comments)
45
51
 
46
52
  Decidim.icons.register(name: "thumb-up-line", icon: "thumb-up-line", description: "Upvote comment button", **common_parameters)
47
53
  Decidim.icons.register(name: "thumb-up-fill", icon: "thumb-up-fill", description: "User upvoted comment", **common_parameters)
@@ -46,6 +46,14 @@ FactoryBot.define do
46
46
  create(:moderation, reportable: comment, hidden_at: 2.days.ago, skip_injection: evaluator.skip_injection)
47
47
  end
48
48
  end
49
+
50
+ trait :in_favor do
51
+ alignment { 1 }
52
+ end
53
+
54
+ trait :against do
55
+ alignment { -1 }
56
+ end
49
57
  end
50
58
 
51
59
  factory :comment_vote, class: "Decidim::Comments::CommentVote" do
@@ -10,7 +10,7 @@ shared_context "when it is a comment event" do
10
10
 
11
11
  let(:resource) { comment.commentable }
12
12
 
13
- let(:comment) { create :comment }
13
+ let(:comment) { create(:comment) }
14
14
  let(:comment_author) { comment.author }
15
15
  let(:normalized_comment_author) { comment.author }
16
16
  let(:comment_author_name) { decidim_html_escape comment.author.name }
@@ -7,8 +7,8 @@ shared_examples_for "a comment voted event" do
7
7
 
8
8
  let(:resource) { comment.commentable }
9
9
 
10
- let(:comment) { create :comment }
11
- let(:comment_vote) { create :comment_vote, comment: }
10
+ let(:comment) { create(:comment) }
11
+ let(:comment_vote) { create(:comment_vote, comment:) }
12
12
  let(:comment_vote_author) { comment_vote.author }
13
13
 
14
14
  let(:extra) { { comment_id: comment.id, author_id: comment_vote_author.id, weight:, downvotes: 100, upvotes: 999 } }
@@ -7,7 +7,7 @@ RSpec.shared_context "when creating a comment" do
7
7
  let(:user) { create(:user, organization:) }
8
8
  let(:author) { create(:user, organization:) }
9
9
  let(:current_user) { author }
10
- let(:dummy_resource) { create :dummy_resource, component: }
10
+ let(:dummy_resource) { create(:dummy_resource, component:) }
11
11
  let(:commentable) { dummy_resource }
12
12
  let(:body) { Faker::Lorem.paragraph }
13
13
  let(:alignment) { 1 }
@@ -6,10 +6,10 @@ shared_examples_for "a translated comment event" do
6
6
  describe "translated notifications" do
7
7
  let(:en_body) { "This is Sparta!" }
8
8
  let(:body) { { en: en_body, machine_translations: { ca: "C'est Sparta!" } } }
9
- let(:participatory_process) { create :participatory_process, organization: }
9
+ let(:participatory_process) { create(:participatory_process, organization:) }
10
10
  let(:component) { create(:component, participatory_space: participatory_process) }
11
11
  let(:commentable) { create(:dummy_resource, component:) }
12
- let(:comment) { create :comment, body:, commentable: }
12
+ let(:comment) { create(:comment, body:, commentable:) }
13
13
  let(:en_version) { "<div><p>#{comment.body["en"]}</p></div>" }
14
14
  let(:machine_translated) { "<div><p>#{comment.body["machine_translations"]["ca"]}</p></div>" }
15
15
 
@@ -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.29.2"
7
+ "0.30.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.29.2
4
+ version: 0.30.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-02-12 00:00:00.000000000 Z
13
+ date: 2025-02-18 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.29.2
21
+ version: 0.30.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.29.2
28
+ version: 0.30.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.29.2
55
+ version: 0.30.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.29.2
62
+ version: 0.30.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.29.2
69
+ version: 0.30.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.29.2
76
+ version: 0.30.0.rc1
77
77
  description: Pluggable comments system for some components.
78
78
  email:
79
79
  - josepjaume@gmail.com
@@ -105,6 +105,7 @@ files:
105
105
  - app/cells/decidim/comments/comment_thread_cell.rb
106
106
  - app/cells/decidim/comments/comments/add_comment.erb
107
107
  - app/cells/decidim/comments/comments/blocked_comments_warning.erb
108
+ - app/cells/decidim/comments/comments/comments_in_single_column.erb
108
109
  - app/cells/decidim/comments/comments/comments_loading.erb
109
110
  - app/cells/decidim/comments/comments/order_control.erb
110
111
  - app/cells/decidim/comments/comments/show.erb
@@ -113,6 +114,9 @@ files:
113
114
  - app/cells/decidim/comments/comments_cell.rb
114
115
  - app/cells/decidim/comments/edit_comment_modal_form/show.erb
115
116
  - app/cells/decidim/comments/edit_comment_modal_form_cell.rb
117
+ - app/cells/decidim/comments/two_columns_comments/column.erb
118
+ - app/cells/decidim/comments/two_columns_comments/show.erb
119
+ - app/cells/decidim/comments/two_columns_comments_cell.rb
116
120
  - app/commands/decidim/comments/create_comment.rb
117
121
  - app/commands/decidim/comments/delete_comment.rb
118
122
  - app/commands/decidim/comments/update_comment.rb
@@ -142,6 +146,8 @@ files:
142
146
  - app/packs/src/decidim/comments/comments.component.test.js
143
147
  - app/packs/src/decidim/comments/comments.component_for_testing.js
144
148
  - app/packs/src/decidim/comments/comments.js
149
+ - app/packs/src/decidim/comments/comments_dropdown.js
150
+ - app/packs/src/decidim/comments/comments_mobile_modal.js
145
151
  - app/packs/stylesheets/comments.scss
146
152
  - app/permissions/decidim/comments/permissions.rb
147
153
  - app/queries/decidim/comments/metrics/comment_participants_metric_measure.rb
@@ -316,14 +322,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
316
322
  requirements:
317
323
  - - "~>"
318
324
  - !ruby/object:Gem::Version
319
- version: 3.2.0
325
+ version: 3.3.0
320
326
  required_rubygems_version: !ruby/object:Gem::Requirement
321
327
  requirements:
322
328
  - - ">="
323
329
  - !ruby/object:Gem::Version
324
330
  version: '0'
325
331
  requirements: []
326
- rubygems_version: 3.4.10
332
+ rubygems_version: 3.5.11
327
333
  signing_key:
328
334
  specification_version: 4
329
335
  summary: Decidim comments module