decidim-comments 0.27.6 → 0.28.0.rc4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/app/cells/decidim/comments/comment/actions.erb +13 -7
  3. data/app/cells/decidim/comments/comment/alignment_badge.erb +1 -4
  4. data/app/cells/decidim/comments/comment/deletion_data.erb +9 -1
  5. data/app/cells/decidim/comments/comment/moderation_data.erb +1 -1
  6. data/app/cells/decidim/comments/comment/replies.erb +3 -0
  7. data/app/cells/decidim/comments/comment/show.erb +72 -35
  8. data/app/cells/decidim/comments/comment/votes.erb +14 -14
  9. data/app/cells/decidim/comments/comment_activity_cell.rb +11 -7
  10. data/app/cells/decidim/comments/comment_card_cell.rb +2 -2
  11. data/app/cells/decidim/comments/comment_cell.rb +9 -21
  12. data/app/cells/decidim/comments/comment_form/comment_as.erb +3 -3
  13. data/app/cells/decidim/comments/comment_form/opinion.erb +18 -0
  14. data/app/cells/decidim/comments/comment_form/show.erb +33 -16
  15. data/app/cells/decidim/comments/comment_form_cell.rb +9 -1
  16. data/app/cells/decidim/comments/comment_metadata_cell.rb +27 -0
  17. data/app/cells/decidim/comments/comment_s_cell.rb +27 -0
  18. data/app/cells/decidim/comments/comment_thread/show.erb +2 -5
  19. data/app/cells/decidim/comments/comment_thread_cell.rb +0 -6
  20. data/app/cells/decidim/comments/comments/add_comment.erb +1 -20
  21. data/app/cells/decidim/comments/comments/blocked_comments_warning.erb +1 -3
  22. data/app/cells/decidim/comments/comments/comments_loading.erb +1 -3
  23. data/app/cells/decidim/comments/comments/order_control.erb +11 -35
  24. data/app/cells/decidim/comments/comments/show.erb +8 -9
  25. data/app/cells/decidim/comments/comments/single_comment_warning.erb +6 -9
  26. data/app/cells/decidim/comments/comments/user_comments_blocked_warning.erb +9 -6
  27. data/app/cells/decidim/comments/comments_cell.rb +1 -1
  28. data/app/cells/decidim/comments/edit_comment_modal_form/show.erb +20 -15
  29. data/app/commands/decidim/comments/create_comment.rb +17 -5
  30. data/app/commands/decidim/comments/delete_comment.rb +1 -1
  31. data/app/commands/decidim/comments/update_comment.rb +14 -2
  32. data/app/commands/decidim/comments/vote_comment.rb +1 -1
  33. data/app/controllers/decidim/comments/comments_controller.rb +14 -9
  34. data/app/controllers/decidim/comments/votes_controller.rb +1 -1
  35. data/app/events/decidim/comments/comment_by_followed_user_event.rb +1 -1
  36. data/app/events/decidim/comments/comment_by_followed_user_group_event.rb +1 -1
  37. data/app/events/decidim/comments/comment_event.rb +2 -3
  38. data/app/events/decidim/comments/reply_created_event.rb +1 -1
  39. data/app/events/decidim/comments/user_group_mentioned_event.rb +1 -1
  40. data/app/events/decidim/comments/user_mentioned_event.rb +1 -1
  41. data/app/helpers/decidim/comments/comment_cells_helper.rb +1 -1
  42. data/app/jobs/decidim/comments/hide_all_created_by_author_job.rb +13 -0
  43. data/app/models/decidim/comments/comment.rb +9 -7
  44. data/app/models/decidim/comments/comment_vote.rb +0 -10
  45. data/app/models/decidim/comments/seed.rb +30 -14
  46. data/app/packs/entrypoints/decidim_comments.js +5 -0
  47. data/app/packs/src/decidim/comments/comments.component.js +27 -36
  48. data/app/packs/src/decidim/comments/comments.component.test.js +218 -240
  49. data/app/packs/src/decidim/comments/comments.component_for_testing.js +1 -1
  50. data/app/packs/src/decidim/comments/comments.js +20 -1
  51. data/app/packs/stylesheets/comments.scss +327 -0
  52. data/app/queries/decidim/comments/metrics/comments_metric_manage.rb +1 -1
  53. data/app/queries/decidim/comments/sorted_comments.rb +10 -10
  54. data/app/services/decidim/comments/comment_creation.rb +1 -1
  55. data/app/services/decidim/comments/new_comment_notification_creator.rb +8 -8
  56. data/app/views/decidim/comments/admin/shared/_availability_fields.html.erb +4 -9
  57. data/app/views/decidim/comments/comments/_comment.html.erb +1 -1
  58. data/app/views/decidim/comments/comments/_comments.html.erb +1 -1
  59. data/app/views/decidim/comments/comments/_delete.html.erb +2 -4
  60. data/app/views/decidim/comments/comments/_moderated.html.erb +2 -4
  61. data/app/views/decidim/comments/comments/create.js.erb +5 -3
  62. data/app/views/decidim/comments/comments/delete.js.erb +4 -1
  63. data/app/views/decidim/comments/comments/index.js.erb +8 -1
  64. data/app/views/decidim/comments/comments/reload.js.erb +1 -2
  65. data/app/views/decidim/comments/comments/update.js.erb +5 -4
  66. data/app/views/decidim/comments/votes/create.js.erb +5 -5
  67. data/config/assets.rb +3 -0
  68. data/config/locales/ar.yml +0 -16
  69. data/config/locales/bg.yml +0 -23
  70. data/config/locales/ca.yml +15 -17
  71. data/config/locales/cs.yml +8 -10
  72. data/config/locales/de.yml +7 -9
  73. data/config/locales/el.yml +3 -11
  74. data/config/locales/en.yml +10 -12
  75. data/config/locales/es-MX.yml +10 -12
  76. data/config/locales/es-PY.yml +10 -12
  77. data/config/locales/es.yml +16 -18
  78. data/config/locales/eu.yml +6 -8
  79. data/config/locales/fi-plain.yml +7 -9
  80. data/config/locales/fi.yml +7 -9
  81. data/config/locales/fr-CA.yml +9 -11
  82. data/config/locales/fr.yml +9 -11
  83. data/config/locales/ga-IE.yml +0 -4
  84. data/config/locales/gl.yml +0 -16
  85. data/config/locales/hu.yml +3 -11
  86. data/config/locales/id-ID.yml +0 -11
  87. data/config/locales/is-IS.yml +0 -8
  88. data/config/locales/it.yml +0 -16
  89. data/config/locales/ja.yml +6 -8
  90. data/config/locales/lb.yml +0 -16
  91. data/config/locales/lt.yml +7 -10
  92. data/config/locales/lv.yml +0 -11
  93. data/config/locales/nl.yml +0 -16
  94. data/config/locales/no.yml +0 -16
  95. data/config/locales/pl.yml +7 -11
  96. data/config/locales/pt-BR.yml +0 -18
  97. data/config/locales/pt.yml +0 -16
  98. data/config/locales/ro-RO.yml +6 -14
  99. data/config/locales/ru.yml +0 -11
  100. data/config/locales/sk.yml +0 -11
  101. data/config/locales/sq-AL.yml +0 -38
  102. data/config/locales/sv.yml +2 -16
  103. data/config/locales/tr-TR.yml +1 -13
  104. data/config/locales/uk.yml +0 -8
  105. data/config/locales/zh-CN.yml +0 -13
  106. data/config/locales/zh-TW.yml +1 -9
  107. data/lib/decidim/api/comment_type.rb +2 -2
  108. data/lib/decidim/api/commentable_interface.rb +1 -1
  109. data/lib/decidim/comments/comment_serializer.rb +1 -1
  110. data/lib/decidim/comments/comment_vote_serializer.rb +1 -1
  111. data/lib/decidim/comments/commentable.rb +1 -1
  112. data/lib/decidim/comments/comments_helper.rb +6 -3
  113. data/lib/decidim/comments/engine.rb +31 -1
  114. data/lib/decidim/comments/export.rb +1 -1
  115. data/lib/decidim/comments/test/factories.rb +9 -16
  116. data/lib/decidim/comments/test/shared_examples/comment_event.rb +4 -4
  117. data/lib/decidim/comments/test/shared_examples/comment_voted_event.rb +4 -4
  118. data/lib/decidim/comments/test/shared_examples/create_comment_context.rb +5 -5
  119. data/lib/decidim/comments/test/shared_examples/has_comments_availability_attributes.rb +2 -2
  120. data/lib/decidim/comments/test/shared_examples/translatable_comment.rb +3 -3
  121. data/lib/decidim/comments/version.rb +1 -1
  122. metadata +30 -27
  123. data/app/cells/decidim/comments/comment/author.erb +0 -1
  124. data/app/cells/decidim/comments/comment/utilities.erb +0 -41
  125. data/app/cells/decidim/comments/comment_m/footer.erb +0 -5
  126. data/app/cells/decidim/comments/comment_m/top.erb +0 -7
  127. data/app/cells/decidim/comments/comment_m_cell.rb +0 -29
  128. data/app/cells/decidim/comments/comment_thread/title.erb +0 -3
  129. data/config/locales/he-IL.yml +0 -1
  130. data/db/migrate/20240304092558_add_comment_vote_counter_cache_to_comments.rb +0 -21
  131. data/decidim-comments.gemspec +0 -33
@@ -1,36 +1,12 @@
1
- <div class="order-by__dropdown order-by__dropdown--right">
2
- <span class="order-by__text"><%= t("decidim.components.comment_order_selector.title") %></span>
3
- <ul id="comments-order-menu"
4
- class="dropdown menu"
5
- data-dropdown-menu="data-dropdown-menu"
6
- data-autoclose="false"
7
- data-disable-hover="true"
8
- data-click-open="true"
9
- data-close-on-click="true"
10
- role="menubar">
11
- <li class="is-dropdown-submenu-parent opens-right" role="presentation">
12
- <a href="#" id="comments-order-menu-control"
13
- aria-label="<%= t("decidim.components.comment_order_selector.title") %>"
14
- aria-controls="comments-order-menu"
15
- aria-haspopup="menu"
16
- role="menuitem"><%= t("decidim.components.comment_order_selector.order.#{order}") %></a>
17
- <ul class="menu is-dropdown-submenu submenu first-sub vertical"
18
- id="comments-order-chooser-menu"
19
- role="menu"
20
- aria-labelledby="comments-order-menu-control"
21
- data-submenu="">
22
- <% available_orders.each do |order_value| %>
23
- <li role="presentation" class="is-submenu-item is-dropdown-submenu-item">
24
- <%= link_to(
25
- t("decidim.components.comment_order_selector.order.#{order_value}"),
26
- decidim_comments.comments_path(commentable_gid: model.to_signed_global_id.to_s, order: order_value, reload: 1),
27
- tabindex: -1,
28
- role: "menuitem",
29
- remote: true
30
- ) %>
31
- </li>
32
- <% end %>
33
- </ul>
34
- </li>
35
- </ul>
1
+ <div class="comment-order-by">
2
+ <% available_orders.each do | order_value| %>
3
+ <div class="text-center">
4
+ <%= link_to(
5
+ t("decidim.components.comment_order_selector.order.#{order_value}"),
6
+ decidim_comments.comments_path(commentable_gid: model.to_signed_global_id.to_s, order: order_value, reload: 1),
7
+ class: "button button__sm button__text-secondary only:m-auto comment-order-by__item inline-block #{order_value == order ? "underline font-bold" : ""}",
8
+ remote: true
9
+ ) %>
10
+ </div>
11
+ <% end %>
36
12
  </div>
@@ -1,16 +1,17 @@
1
1
  <%= content_tag :div, id: node_id, data: { decidim_comments: comments_data } do %>
2
- <div class="columns large-9 comments-container" id="comments">
2
+ <div id="comments">
3
3
  <div class="comments">
4
- <div class="row collapse order-by">
5
- <h3 class="order-by__text section-heading">
4
+ <div class="comments__header">
5
+ <h2 class="h4">
6
6
  <% if single_comment? %>
7
7
  <%= t("decidim.components.comments.comment_details_title") %>
8
8
  <% else %>
9
- <span class="comments-count">
9
+ <%= icon "chat-1-line", class: "fill-tertiary w-6 h-6 inline-block align-middle" %>
10
+ <span class="comments-count inline-block align-middle">
10
11
  <%= t("decidim.components.comments.title", count: comments_count) %>
11
12
  </span>
12
13
  <% end %>
13
- </h3>
14
+ </h2>
14
15
  <%= render :order_control %>
15
16
  </div>
16
17
  <%= single_comment_warning %>
@@ -18,14 +19,12 @@
18
19
  <div class="comment-threads">
19
20
  <%= comments_loading %>
20
21
  <% comments.each do |comment| %>
21
- <%= cell("decidim/comments/comment_thread", comment, order: order) %>
22
+ <%= cell("decidim/comments/comment_thread", comment, order:) %>
22
23
  <% end %>
23
24
  </div>
24
25
  <%= add_comment %>
25
26
  <%= user_comments_blocked_warning %>
26
27
  </div>
27
- <div class="callout primary loading-comments hide">
28
- <p><%= t("decidim.components.comments.loading") %></p>
29
- </div>
28
+ <%= cell("decidim/announcement", t("decidim.components.comments.loading"), callout_class: "primary loading-comments hidden") %>
30
29
  </div>
31
30
  <% end %>
@@ -1,9 +1,6 @@
1
- <div class="callout secondary">
2
- <h5><%= t("decidim.components.comments.single_comment_warning_title") %></h5>
3
- <p>
4
- <%== t(
5
- "decidim.components.comments.single_comment_warning",
6
- url: "#{commentable_path}##{node_id}"
7
- ) %>
8
- </p>
9
- </div>
1
+ <%= cell("decidim/announcement", {
2
+ title: t("decidim.components.comments.single_comment_warning_title"),
3
+ body: t("decidim.components.comments.single_comment_warning", url: "#{commentable_path}##{node_id}")
4
+ },
5
+ callout_class: "secondary"
6
+ ) %>
@@ -1,7 +1,10 @@
1
- <div class="callout warning">
2
- <% if comment_permissions? %>
3
- <p><%= blocked_comments_for_unauthorized_user_warning_link %></p>
4
- <% else %>
5
- <p><%= t("decidim.components.comments.blocked_comments_for_user_warning") %></p>
6
- <% end %>
1
+ <%# We cannot use the AnnouncementCell directly here as the link is escaped and it would not work %>
2
+ <div class="flash warning" data-announcement="">
3
+ <span class="flash__message">
4
+ <% if comment_permissions? %>
5
+ <p><%= blocked_comments_for_unauthorized_user_warning_link %></p>
6
+ <% else %>
7
+ <p><%= t("decidim.components.comments.blocked_comments_for_user_warning") %></p>
8
+ <% end %>
9
+ </span>
7
10
  </div>
@@ -99,7 +99,7 @@ module Decidim
99
99
  commentableGid: model.to_signed_global_id.to_s,
100
100
  commentsUrl: decidim_comments.comments_path,
101
101
  rootDepth: root_depth,
102
- order: order
102
+ order:
103
103
  }
104
104
  end
105
105
 
@@ -1,16 +1,15 @@
1
- <div class="reveal edit-comment-modal" id="<%= "editCommentModal#{model.id}" %>" data-reveal role="dialog" aria-modal="true" aria-labelledby="<%= "editCommentModal#{model.id}" %>-label">
2
- <div class="reveal__header">
3
- <h3 id="<%= "editCommentModal#{model.id}" %>-label" class="reveal__title"><%= t("decidim.components.edit_comment_modal_form.title") %></h3>
4
- <button class="close-button" data-close aria-label="<%= t("decidim.components.edit_comment_modal_form.close") %>" type="button">
5
- <span aria-hidden="true">&times;</span>
6
- </button>
7
- </div>
8
- <%= form_for(form_object, url: decidim_comments.comment_path(comment), method: :put, remote: true, html: { id: form_id }) do |form| %>
9
- <div class="field">
10
- <label class="show-for-sr" for="<%= form_id %>">
11
- <%= t("decidim.components.edit_comment_modal_form.form.body.label") %>
12
- </label>
13
- <div class="hashtags__container">
1
+ <%= decidim_modal id: "editCommentModal#{model.id}" do %>
2
+ <%= form_for(form_object, url: decidim_comments.comment_path(comment), method: :put, remote: true, html: { id: nil }) do |form| %>
3
+ <div data-dialog-container>
4
+ <%= icon "edit-line" %>
5
+ <h2 class="h2" id="dialog-title-budget-confirm" data-dialog-title>
6
+ <%= t("decidim.components.edit_comment_modal_form.title") %>
7
+ </h2>
8
+
9
+ <div class="form__wrapper gap-2">
10
+ <label class="text-gray-2" for="<%= form_id %>">
11
+ <%= t("decidim.components.edit_comment_modal_form.form.body.label") %>
12
+ </label>
14
13
  <%= form.text_area(
15
14
  :body,
16
15
  id: form_id,
@@ -19,11 +18,17 @@
19
18
  required: true,
20
19
  placeholder: t("decidim.components.edit_comment_modal_form.form.body.placeholder"),
21
20
  label: false,
21
+ class: "w-full rounded border min-h-[160px] border-text-gray-2",
22
22
  data: { remaining_characters: "##{form_id}-remaining-characters", input_emoji: true }
23
23
  ) %>
24
24
  </div>
25
- <button type="submit" data-close class="button button--sc"><%= t("decidim.components.edit_comment_modal_form.form.submit") %></button>
25
+ </div>
26
+ <div data-dialog-actions>
27
+ <button type="submit" data-dialog-close="editCommentModal<%= model.id %>" class="button button__sm md:button__lg button__secondary">
28
+ <%= t("decidim.components.edit_comment_modal_form.form.submit") %>
29
+ </button>
30
+
26
31
  <span id="<%= form_id %>-remaining-characters" class="remaining-character-count"></span>
27
32
  </div>
28
33
  <% end %>
29
- </div>
34
+ <% end %>
@@ -15,26 +15,38 @@ module Decidim
15
15
  # Executes the command. Broadcasts these events:
16
16
  #
17
17
  # - :ok when everything is valid.
18
- # - :invalid if the form wasn't valid and we couldn't proceed.
18
+ # - :invalid if the form was not valid and we could not proceed.
19
19
  #
20
20
  # Returns nothing.
21
21
  def call
22
22
  return broadcast(:invalid) if form.invalid?
23
23
 
24
- create_comment
24
+ with_events do
25
+ create_comment
26
+ end
25
27
 
26
28
  broadcast(:ok, comment)
27
29
  end
28
30
 
29
31
  private
30
32
 
31
- attr_reader :form, :comment
33
+ attr_reader :form, :comment, :author
34
+
35
+ def event_arguments
36
+ {
37
+ resource: comment,
38
+ extra: {
39
+ event_author: form.current_user,
40
+ locale:
41
+ }
42
+ }
43
+ end
32
44
 
33
45
  def create_comment
34
46
  parsed = Decidim::ContentProcessor.parse(form.body, current_organization: form.current_organization)
35
47
 
36
48
  params = {
37
- author: @author,
49
+ author:,
38
50
  commentable: form.commentable,
39
51
  root_commentable: root_commentable(form.commentable),
40
52
  body: { I18n.locale => parsed.rewrite },
@@ -45,7 +57,7 @@ module Decidim
45
57
 
46
58
  @comment = Decidim.traceability.create!(
47
59
  Comment,
48
- @author,
60
+ author,
49
61
  params,
50
62
  visibility: "public-only"
51
63
  )
@@ -16,7 +16,7 @@ module Decidim
16
16
  # Executes the command. Broadcasts these events:
17
17
  #
18
18
  # - :ok when everything is valid.
19
- # - :invalid if comment isn't authored by current_user.
19
+ # - :invalid if comment is not authored by current_user.
20
20
  #
21
21
  # Returns nothing.
22
22
  def call
@@ -18,13 +18,15 @@ module Decidim
18
18
  # Executes the command. Broadcasts these events:
19
19
  #
20
20
  # - :ok when everything is valid.
21
- # - :invalid if the form wasn't valid and we couldn't proceed.
21
+ # - :invalid if the form was not valid and we could not proceed.
22
22
  #
23
23
  # Returns nothing.
24
24
  def call
25
25
  return broadcast(:invalid) if form.invalid? || !comment.authored_by?(current_user)
26
26
 
27
- update_comment
27
+ with_events do
28
+ update_comment
29
+ end
28
30
 
29
31
  broadcast(:ok)
30
32
  end
@@ -33,6 +35,16 @@ module Decidim
33
35
 
34
36
  attr_reader :form, :comment, :current_user
35
37
 
38
+ def event_arguments
39
+ {
40
+ resource: comment,
41
+ extra: {
42
+ event_author: form.current_user,
43
+ locale:
44
+ }
45
+ }
46
+ end
47
+
36
48
  def update_comment
37
49
  parsed = Decidim::ContentProcessor.parse(form.body, current_organization: form.current_organization)
38
50
 
@@ -19,7 +19,7 @@ module Decidim
19
19
  # Executes the command. Broadcasts these events:
20
20
  #
21
21
  # - :ok when everything is valid.
22
- # - :invalid if the vote wasn't create
22
+ # - :invalid if the vote was not create
23
23
  #
24
24
  # Returns nothing.
25
25
  def call
@@ -16,7 +16,7 @@ module Decidim
16
16
  helper_method :root_depth, :commentable, :order, :reply?, :reload?, :root_comment
17
17
 
18
18
  def index
19
- enforce_permission_to :read, :comment, commentable: commentable
19
+ enforce_permission_to(:read, :comment, commentable:)
20
20
 
21
21
  @comments = SortedComments.for(
22
22
  commentable,
@@ -47,12 +47,13 @@ module Decidim
47
47
 
48
48
  def update
49
49
  set_comment
50
- enforce_permission_to :update, :comment, comment: comment
50
+ set_commentable
51
+ enforce_permission_to(:update, :comment, comment:)
51
52
 
52
53
  form = Decidim::Comments::CommentForm.from_params(
53
54
  params.merge(commentable: comment.commentable)
54
55
  ).with_context(
55
- current_organization: current_organization
56
+ current_organization:
56
57
  )
57
58
 
58
59
  Decidim::Comments::UpdateComment.call(comment, current_user, form) do
@@ -71,13 +72,13 @@ module Decidim
71
72
  end
72
73
 
73
74
  def create
74
- enforce_permission_to :create, :comment, commentable: commentable
75
+ enforce_permission_to(:create, :comment, commentable:)
75
76
 
76
77
  form = Decidim::Comments::CommentForm.from_params(
77
- params.merge(commentable: commentable)
78
+ params.merge(commentable:)
78
79
  ).with_context(
79
- current_organization: current_organization,
80
- current_component: current_component
80
+ current_organization:,
81
+ current_component:
81
82
  )
82
83
  Decidim::Comments::CreateComment.call(form, current_user) do
83
84
  on(:ok) do |comment|
@@ -106,7 +107,7 @@ module Decidim
106
107
  set_comment
107
108
  @commentable = @comment.commentable
108
109
 
109
- enforce_permission_to :destroy, :comment, comment: comment
110
+ enforce_permission_to(:destroy, :comment, comment:)
110
111
 
111
112
  Decidim::Comments::DeleteComment.call(comment, current_user) do
112
113
  on(:ok) do
@@ -129,7 +130,11 @@ module Decidim
129
130
  attr_reader :commentable, :comment
130
131
 
131
132
  def set_commentable
132
- @commentable = GlobalID::Locator.locate_signed(commentable_gid)
133
+ @commentable ||= if commentable_gid
134
+ GlobalID::Locator.locate_signed(commentable_gid)
135
+ elsif comment
136
+ comment.root_commentable
137
+ end
133
138
  end
134
139
 
135
140
  def set_comment
@@ -13,7 +13,7 @@ module Decidim
13
13
  def create
14
14
  raise ActionController::RoutingError, "Not Found" unless comment
15
15
 
16
- enforce_permission_to :vote, :comment, comment: comment
16
+ enforce_permission_to(:vote, :comment, comment:)
17
17
 
18
18
  Decidim::Comments::VoteComment.call(comment, current_user, weight: params[:weight].to_i) do
19
19
  on(:ok) do
@@ -1,4 +1,4 @@
1
- # frozen-string_literal: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Decidim
4
4
  module Comments
@@ -1,4 +1,4 @@
1
- # frozen-string_literal: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Decidim
4
4
  module Comments
@@ -1,4 +1,4 @@
1
- # frozen-string_literal: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Decidim
4
4
  module Comments
@@ -11,8 +11,7 @@ module Decidim
11
11
 
12
12
  included do
13
13
  def resource_text(override_translation = nil)
14
- translated_body = translated_attribute(comment.body, comment.organization, override_translation)
15
- Decidim::ContentProcessor.render(sanitize_content(render_markdown(translated_body)), "div")
14
+ comment.formatted_body(override_translation)
16
15
  end
17
16
 
18
17
  def author
@@ -1,4 +1,4 @@
1
- # frozen-string_literal: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Decidim
4
4
  module Comments
@@ -1,4 +1,4 @@
1
- # frozen-string_literal: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Decidim
4
4
  module Comments
@@ -1,4 +1,4 @@
1
- # frozen-string_literal: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Decidim
4
4
  module Comments
@@ -26,7 +26,7 @@ module Decidim
26
26
  end
27
27
 
28
28
  def url_params
29
- { commentId: comment.id }
29
+ { commentId: comment.id, anchor: "comment_#{comment.id}" }
30
30
  end
31
31
  end
32
32
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Comments
5
+ class HideAllCreatedByAuthorJob < ::Decidim::HideAllCreatedByAuthorJob
6
+ protected
7
+
8
+ def base_query
9
+ Decidim::Comments::Comment.not_hidden.where(author:)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -29,7 +29,6 @@ module Decidim
29
29
  translatable_fields :body
30
30
 
31
31
  parent_item_foreign_key :decidim_commentable_id
32
- parent_item_polymorphic_type_key :decidim_commentable_type
33
32
 
34
33
  belongs_to :commentable, foreign_key: "decidim_commentable_id", foreign_type: "decidim_commentable_type", polymorphic: true
35
34
  belongs_to :root_commentable, foreign_key: "decidim_root_commentable_id", foreign_type: "decidim_root_commentable_type", polymorphic: true, touch: true
@@ -122,14 +121,14 @@ module Decidim
122
121
  #
123
122
  # Returns a bool value to indicate if the condition is truthy or not
124
123
  def up_voted_by?(user)
125
- up_votes.exists?(author: user)
124
+ up_votes.any? { |vote| vote.author == user }
126
125
  end
127
126
 
128
127
  # Public: Check if the user has downvoted the comment
129
128
  #
130
129
  # Returns a bool value to indicate if the condition is truthy or not
131
130
  def down_voted_by?(user)
132
- down_votes.exists?(author: user)
131
+ down_votes.any? { |vote| vote.author == user }
133
132
  end
134
133
 
135
134
  # Public: Overrides the `reported_content_url` Reportable concern method.
@@ -180,12 +179,15 @@ module Decidim
180
179
  root_commentable.can_participate?(user)
181
180
  end
182
181
 
183
- def formatted_body
184
- Decidim::ContentProcessor.render(sanitize_content_for_comment(render_markdown(translated_body)), "div")
182
+ # The override_translation argument has been added to be able to use this
183
+ # method from comment event in the resource_text method which requires
184
+ # the use of this argument in translated_attribute of body
185
+ def formatted_body(override_translation = nil)
186
+ Decidim::ContentProcessor.render(sanitize_content_for_comment(render_markdown(translated_body(override_translation))), "div")
185
187
  end
186
188
 
187
- def translated_body
188
- translated_attribute(body, organization)
189
+ def translated_body(override_translation = nil)
190
+ translated_attribute(body, organization, override_translation)
189
191
  end
190
192
 
191
193
  def delete!
@@ -14,22 +14,12 @@ module Decidim
14
14
  validates :weight, inclusion: { in: [-1, 1] }
15
15
  validate :author_and_comment_same_organization
16
16
 
17
- after_create :update_comment_votes_count
18
- after_destroy :update_comment_votes_count
19
-
20
17
  def self.export_serializer
21
18
  Decidim::Comments::CommentVoteSerializer
22
19
  end
23
20
 
24
21
  private
25
22
 
26
- def update_comment_votes_count
27
- up_votes_count = self.class.where(decidim_comment_id: comment.id, weight: 1).count
28
- down_votes_count = self.class.where(decidim_comment_id: comment.id, weight: -1).count
29
-
30
- comment.update(up_votes_count: up_votes_count, down_votes_count: down_votes_count)
31
- end
32
-
33
23
  # Private: check if the comment and the author have the same organization
34
24
  def author_and_comment_same_organization
35
25
  return unless author.present? && comment.present?
@@ -6,28 +6,44 @@ module Decidim
6
6
  # to Seed those models in order to be able to use them in the development
7
7
  # app.
8
8
  class Seed
9
- # Public: adds a random amount of comments for a given resource.
10
- #
11
- # resource - the resource to add the coments to.
12
- #
13
- # Returns nothing.
14
- def self.comments_for(resource)
15
- return unless resource.accepts_new_comments?
9
+ class << self
10
+ # Adds a random amount of comments for a given resource.
11
+ #
12
+ # @param resource [Object] - the Decidim resource to add the coments to.
13
+ # examples: Decidim::Proposals::CollaborativeDraft, Decidim::Proposals::Proposal,
14
+ #
15
+ # @return nil
16
+ def comments_for(resource)
17
+ return unless resource.accepts_new_comments?
16
18
 
17
- Decidim::Comments::Comment.reset_column_information
19
+ Decidim::Comments::Comment.reset_column_information
18
20
 
19
- organization = resource.organization
21
+ rand(0..6).times do
22
+ comment = create_comment(resource)
23
+ create_comment(comment, resource) if [true, false].sample
24
+ end
25
+ end
26
+
27
+ private
20
28
 
21
- 2.times do
22
- author = Decidim::User.where(organization: organization).all.sample
29
+ # Creates a comment for a given resource.
30
+ #
31
+ # @private
32
+ #
33
+ # @param resource [Object] - the Decidim resource to add the comments to.
34
+ # @param root_commentable - the root commentable resource. It is optional, used for making nested comments.
35
+ #
36
+ # @return [Decidim::Comments::Comment]
37
+ def create_comment(resource, root_commentable = nil)
38
+ author = Decidim::User.where(organization: resource.organization).all.sample
23
39
  user_group = [true, false].sample ? Decidim::UserGroups::ManageableUserGroups.for(author).verified.sample : nil
24
40
 
25
41
  params = {
26
42
  commentable: resource,
27
- root_commentable: resource,
43
+ root_commentable: root_commentable || resource,
28
44
  body: { en: ::Faker::Lorem.sentence(word_count: 50) },
29
- author: author,
30
- user_group: user_group
45
+ author:,
46
+ user_group:
31
47
  }
32
48
 
33
49
  Decidim.traceability.create!(
@@ -0,0 +1,5 @@
1
+ // CSS
2
+ import "stylesheets/comments.scss"
3
+
4
+ // Javacript
5
+ import "src/decidim/comments/comments"