decidim-comments 0.28.2 → 0.29.0.rc2

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 (47) hide show
  1. checksums.yaml +4 -4
  2. data/app/cells/decidim/comments/comment/actions.erb +4 -3
  3. data/app/cells/decidim/comments/comment/deletion_data.erb +1 -1
  4. data/app/cells/decidim/comments/comment/show.erb +2 -2
  5. data/app/cells/decidim/comments/comment_cell.rb +0 -2
  6. data/app/cells/decidim/comments/comment_form/opinion.erb +4 -4
  7. data/app/cells/decidim/comments/comment_form_cell.rb +0 -2
  8. data/app/cells/decidim/comments/comment_metadata_cell.rb +1 -1
  9. data/app/cells/decidim/comments/comments_cell.rb +0 -3
  10. data/app/cells/decidim/comments/edit_comment_modal_form_cell.rb +0 -1
  11. data/app/commands/decidim/comments/create_comment.rb +6 -6
  12. data/app/commands/decidim/comments/update_comment.rb +3 -4
  13. data/app/controllers/decidim/comments/comments_controller.rb +5 -3
  14. data/app/helpers/decidim/comments/comment_cells_helper.rb +1 -1
  15. data/app/models/decidim/comments/seed.rb +55 -5
  16. data/app/packs/entrypoints/decidim_comments.js +1 -1
  17. data/app/packs/src/decidim/comments/comments.component.js +8 -8
  18. data/app/packs/src/decidim/comments/comments.component.test.js +14 -14
  19. data/app/views/decidim/comments/comments/create.js.erb +2 -2
  20. data/app/views/decidim/comments/comments/delete.js.erb +5 -2
  21. data/app/views/decidim/comments/votes/create.js.erb +1 -1
  22. data/config/locales/bg.yml +0 -1
  23. data/config/locales/ca.yml +1 -1
  24. data/config/locales/cs.yml +0 -1
  25. data/config/locales/de.yml +1 -1
  26. data/config/locales/en.yml +1 -1
  27. data/config/locales/es-MX.yml +1 -1
  28. data/config/locales/es-PY.yml +1 -1
  29. data/config/locales/es.yml +1 -1
  30. data/config/locales/eu.yml +1 -1
  31. data/config/locales/fi-plain.yml +1 -1
  32. data/config/locales/fi.yml +1 -1
  33. data/config/locales/fr-CA.yml +1 -1
  34. data/config/locales/fr.yml +1 -1
  35. data/config/locales/ja.yml +1 -1
  36. data/config/locales/pl.yml +1 -1
  37. data/config/locales/ro-RO.yml +0 -1
  38. data/config/locales/tr-TR.yml +0 -1
  39. data/db/seeds.rb +1 -0
  40. data/decidim-comments.gemspec +1 -1
  41. data/lib/decidim/api/commentable_mutation_type.rb +2 -1
  42. data/lib/decidim/comments/commentable.rb +2 -2
  43. data/lib/decidim/comments/test/shared_examples/create_comment_context.rb +3 -2
  44. data/lib/decidim/comments/version.rb +1 -1
  45. data/lib/tasks/upgrade/decidim_comments.rake +28 -0
  46. metadata +12 -12
  47. data/lib/tasks/decidim_comments.rake +0 -26
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 24cf379816e56d8d02c96af8dfd596b8946c7098f2c672f305a97fb563861248
4
- data.tar.gz: 361246cb66e6171732029b68e1a51edabf47bd1d605d26f698144fb148006eb3
3
+ metadata.gz: e9477ff3a7a4e7dd6176adb162064bb773e20e576a1098862d67a4d9e05c12fe
4
+ data.tar.gz: 7c7ea403b09d4b07749117c1c09af7250a928cd24928133aed71c1181719a8d7
5
5
  SHA512:
6
- metadata.gz: b649d92b1c7cff28097d16eaee1ab6e3d08b5600c72a180e9e83cf4556730f0a5b62223a23051d61fa160fea8b2925d9161da05e7b600e4439c973ea1fcb9a58
7
- data.tar.gz: fef878987f09ba7d4156bc86b573d59db4c030d67f69cabca6f271ea66b1fe44288bef6e615cbf1cd423fb2e363dfa7d87a273b98fee46d7990209235b5d6467
6
+ metadata.gz: 74211886a8bae87f91c5bc2cce830780b2e78e2354cfbc7a0ff24c609fa9872450726dd2906ee48b7f44255e0fda78a6fa6e58af076884cd0bd7e4ac57c2d9ec
7
+ data.tar.gz: 3c6709c7755b014f3726d449a1c5b11596d069e9bff75f03213f93fb8d414329a32dc24c62163c99f773f864be9df03a8535c7b99095fd83c8539c91aad32d7a
@@ -1,9 +1,10 @@
1
1
  <div class="comment__actions">
2
2
  <% if depth.zero? && has_replies_in_children? %>
3
- <button class="button button__sm button__text-secondary comment__hide" data-controls="comment-<%= model.id %>-replies" data-open="true" id="comment-<%= model.id %>-replies-trigger">
4
- <span class="show-comment-replies font-normal"><%= t("decidim.components.comment.show_replies", count: replies.size) %></span>
3
+ <button class="button button__sm button__text-secondary" data-comment-hide data-controls="comment-<%= model.id %>-replies" data-open="true" id="comment-<%= model.id %>-replies-trigger">
4
+ <%= icon "arrow-down-s-line" %>
5
+ <span data-show-comment-reply class="font-normal"><%= t("decidim.components.comment.show_replies", count: replies.size) %></span>
5
6
  <%= icon "arrow-up-s-line" %>
6
- <span class="hide-comment-replies font-normal"><%= t("decidim.components.comment.hide_replies", count: replies.size) %></span>
7
+ <span data-hide-comment-reply class="font-normal"><%= t("decidim.components.comment.hide_replies", count: replies.size) %></span>
7
8
  </button>
8
9
  <% end %>
9
10
  <% if can_reply? %>
@@ -1,6 +1,6 @@
1
1
  <%= render partial: "decidim/comments/comments/delete", formats: [:html], locals: { comment: model } %>
2
2
 
3
- <div class="comment__footer" data-component="accordion" id="accordion-<%= model.id %>">
3
+ <div data-comment-footer data-component="accordion" id="accordion-<%= model.id %>">
4
4
  <div id="comment-<%= model.id %>-replies" class="<%= "comment-reply" if has_replies_in_children? %>">
5
5
  <% if has_replies_in_children? %>
6
6
  <%= render :replies %>
@@ -63,13 +63,13 @@
63
63
  </div>
64
64
  </div>
65
65
 
66
- <div class="comment__footer" data-component="accordion" id="accordion-<%= model.id %>">
66
+ <div data-comment-footer data-component="accordion" id="accordion-<%= model.id %>">
67
67
  <div class="comment__footer-grid">
68
68
  <%= render :actions %>
69
69
  <%= votes %>
70
70
  </div>
71
71
  <% if can_reply? %>
72
- <div id="panel-<%= reply_id %>" class="add-comment comment__additionalreply">
72
+ <div id="panel-<%= reply_id %>" class="add-comment" data-additional-reply>
73
73
  <%== cell("decidim/comments/comment_form", model, root_depth:, order:) %>
74
74
  </div>
75
75
  <% end %>
@@ -4,8 +4,6 @@ module Decidim
4
4
  module Comments
5
5
  # A cell to display a single comment.
6
6
  class CommentCell < Decidim::ViewModel
7
- include ActionView::Helpers::DateHelper
8
- include Decidim::IconHelper
9
7
  include Decidim::ResourceHelper
10
8
  include Cell::ViewModel::Partial
11
9
 
@@ -1,15 +1,15 @@
1
1
  <div>
2
2
  <span class="comment__opinion-label"><%= t("decidim.components.add_comment_form.opinion.label") %></span>
3
- <div class="opinion-toggle comment__opinion-container">
4
- <button type="button" aria-pressed="false" class="opinion-toggle--ok" data-selected-label="<%= t("decidim.components.add_comment_form.opinion.positive_selected") %>">
3
+ <div data-opinion-toggle class="comment__opinion-container">
4
+ <button type="button" aria-pressed="false" data-toggle-ok="true" data-selected-label="<%= t("decidim.components.add_comment_form.opinion.positive_selected") %>">
5
5
  <span><%= t("decidim.components.comment.alignment.in_favor") %></span>
6
6
  <%= icon "thumb-up-line" %>
7
7
  </button>
8
- <button type="button" aria-pressed="true" class="opinion-toggle--meh is-active" data-selected-label="<%= t("decidim.components.add_comment_form.opinion.neutral_selected") %>">
8
+ <button type="button" aria-pressed="true" class="is-active" data-toggle-meh="true" data-selected-label="<%= t("decidim.components.add_comment_form.opinion.neutral_selected") %>">
9
9
  <span><%= t("decidim.components.add_comment_form.opinion.neutral") %></span>
10
10
  <%= icon "loader-3-line" %>
11
11
  </button>
12
- <button type="button" aria-pressed="false" class="opinion-toggle--ko" data-selected-label="<%= t("decidim.components.add_comment_form.opinion.negative_selected") %>">
12
+ <button type="button" aria-pressed="false" data-toggle-ko="true" data-selected-label="<%= t("decidim.components.add_comment_form.opinion.negative_selected") %>">
13
13
  <span><%= t("decidim.components.comment.alignment.against") %></span>
14
14
  <%= icon "thumb-down-line" %>
15
15
  </button>
@@ -4,8 +4,6 @@ module Decidim
4
4
  module Comments
5
5
  # A cell to display a form for adding a new comment.
6
6
  class CommentFormCell < Decidim::ViewModel
7
- delegate :current_user, :user_signed_in?, to: :controller
8
-
9
7
  def comment_as_for(form)
10
8
  return if verified_user_groups.blank?
11
9
 
@@ -14,7 +14,7 @@ module Decidim
14
14
 
15
15
  def commentable_item
16
16
  {
17
- text: decidim_html_escape(translated_attribute(root_commentable.title)),
17
+ text: decidim_escape_translated(root_commentable.title),
18
18
  icon: resource_type_icon_key(root_commentable.class)
19
19
  }
20
20
  end
@@ -4,10 +4,7 @@ module Decidim
4
4
  module Comments
5
5
  # A cell to display a comments section for a commentable object.
6
6
  class CommentsCell < Decidim::ViewModel
7
- include Decidim::IconHelper
8
-
9
7
  delegate :user_signed_in?, to: :controller
10
-
11
8
  def add_comment
12
9
  return if single_comment?
13
10
  return if comments_blocked?
@@ -4,7 +4,6 @@ module Decidim
4
4
  module Comments
5
5
  # A cell to display a form for editing a comment.
6
6
  class EditCommentModalFormCell < Decidim::ViewModel
7
- delegate :current_user, :user_signed_in?, to: :controller
8
7
  alias comment model
9
8
 
10
9
  private
@@ -4,12 +4,12 @@ module Decidim
4
4
  module Comments
5
5
  # A command with all the business logic to create a new comment
6
6
  class CreateComment < Decidim::Command
7
+ delegate :current_user, to: :form
7
8
  # Public: Initializes the command.
8
9
  #
9
10
  # form - A form object with the params.
10
- def initialize(form, author)
11
+ def initialize(form)
11
12
  @form = form
12
- @author = author
13
13
  end
14
14
 
15
15
  # Executes the command. Broadcasts these events:
@@ -30,13 +30,13 @@ module Decidim
30
30
 
31
31
  private
32
32
 
33
- attr_reader :form, :comment, :author
33
+ attr_reader :form, :comment
34
34
 
35
35
  def event_arguments
36
36
  {
37
37
  resource: comment,
38
38
  extra: {
39
- event_author: form.current_user,
39
+ event_author: current_user,
40
40
  locale:
41
41
  }
42
42
  }
@@ -46,7 +46,7 @@ module Decidim
46
46
  parsed = Decidim::ContentProcessor.parse(form.body, current_organization: form.current_organization)
47
47
 
48
48
  params = {
49
- author:,
49
+ author: current_user,
50
50
  commentable: form.commentable,
51
51
  root_commentable: root_commentable(form.commentable),
52
52
  body: { I18n.locale => parsed.rewrite },
@@ -57,7 +57,7 @@ module Decidim
57
57
 
58
58
  @comment = Decidim.traceability.create!(
59
59
  Comment,
60
- author,
60
+ current_user,
61
61
  params,
62
62
  visibility: "public-only"
63
63
  )
@@ -4,14 +4,13 @@ module Decidim
4
4
  module Comments
5
5
  # A command with all the business logic to update an existing comment
6
6
  class UpdateComment < Decidim::Command
7
+ delegate :current_user, to: :form
7
8
  # Public: Initializes the command.
8
9
  #
9
10
  # comment - Decidim::Comments::Comment
10
- # current_user - Decidim::User
11
11
  # form - A form object with the params.
12
- def initialize(comment, current_user, form)
12
+ def initialize(comment, form)
13
13
  @comment = comment
14
- @current_user = current_user
15
14
  @form = form
16
15
  end
17
16
 
@@ -33,7 +32,7 @@ module Decidim
33
32
 
34
33
  private
35
34
 
36
- attr_reader :form, :comment, :current_user
35
+ attr_reader :form, :comment
37
36
 
38
37
  def event_arguments
39
38
  {
@@ -53,10 +53,11 @@ module Decidim
53
53
  form = Decidim::Comments::CommentForm.from_params(
54
54
  params.merge(commentable: comment.commentable)
55
55
  ).with_context(
56
+ current_user:,
56
57
  current_organization:
57
58
  )
58
59
 
59
- Decidim::Comments::UpdateComment.call(comment, current_user, form) do
60
+ Decidim::Comments::UpdateComment.call(comment, form) do
60
61
  on(:ok) do
61
62
  respond_to do |format|
62
63
  format.js { render :update }
@@ -78,9 +79,10 @@ module Decidim
78
79
  params.merge(commentable:)
79
80
  ).with_context(
80
81
  current_organization:,
81
- current_component:
82
+ current_component:,
83
+ current_user:
82
84
  )
83
- Decidim::Comments::CreateComment.call(form, current_user) do
85
+ Decidim::Comments::CreateComment.call(form) do
84
86
  on(:ok) do |comment|
85
87
  handle_success(comment)
86
88
  respond_to do |format|
@@ -22,7 +22,7 @@ module Decidim
22
22
  delegate :root_commentable, to: :comment
23
23
 
24
24
  def root_commentable_title
25
- decidim_html_escape(translated_attribute(root_commentable.title))
25
+ decidim_escape_translated(root_commentable.title)
26
26
  end
27
27
 
28
28
  def url_params
@@ -9,7 +9,7 @@ module Decidim
9
9
  class << self
10
10
  # Adds a random amount of comments for a given resource.
11
11
  #
12
- # @param resource [Object] - the Decidim resource to add the coments to.
12
+ # @param resource [Object] - the Decidim resource to add the comments to.
13
13
  # examples: Decidim::Proposals::CollaborativeDraft, Decidim::Proposals::Proposal,
14
14
  #
15
15
  # @return nil
@@ -18,14 +18,28 @@ module Decidim
18
18
 
19
19
  Decidim::Comments::Comment.reset_column_information
20
20
 
21
+ @organization = resource.organization
22
+
21
23
  rand(0..6).times do
22
- comment = create_comment(resource)
23
- create_comment(comment, resource) if [true, false].sample
24
+ comment1 = create_comment(resource)
25
+ NewCommentNotificationCreator.new(comment1, [], []).create
26
+
27
+ if [true, false].sample
28
+ comment2 = create_comment(comment1, resource)
29
+ NewCommentNotificationCreator.new(comment2, [], []).create
30
+ end
31
+
32
+ next if [true, false].sample
33
+
34
+ create_votes(comment1) if comment1
35
+ create_votes(comment2) if comment2
24
36
  end
25
37
  end
26
38
 
27
39
  private
28
40
 
41
+ attr_reader :organization
42
+
29
43
  # Creates a comment for a given resource.
30
44
  #
31
45
  # @private
@@ -35,8 +49,8 @@ module Decidim
35
49
  #
36
50
  # @return [Decidim::Comments::Comment]
37
51
  def create_comment(resource, root_commentable = nil)
38
- author = Decidim::User.where(organization: resource.organization).all.sample
39
- user_group = [true, false].sample ? Decidim::UserGroups::ManageableUserGroups.for(author).verified.sample : nil
52
+ author = random_user
53
+ user_group = random_user_group(author)
40
54
 
41
55
  params = {
42
56
  commentable: resource,
@@ -53,6 +67,42 @@ module Decidim
53
67
  visibility: "public-only"
54
68
  )
55
69
  end
70
+
71
+ # Creates a random amount of votes for a given comment.
72
+ # The votes can be from a user or a user group.
73
+ #
74
+ # @private
75
+ #
76
+ # @param [Decidim::Comments::Comment]
77
+ #
78
+ # @return nil
79
+ def create_votes(comment)
80
+ rand(0..12).times do
81
+ user = random_user
82
+ user_group = random_user_group(user)
83
+ author = [user, user_group].compact.sample
84
+ next if CommentVote.where(comment:, author:).any?
85
+
86
+ CommentVote.create!(comment:, author:, weight: [1, -1].sample)
87
+ end
88
+
89
+ nil
90
+ rescue ActiveRecord::AssociationTypeMismatch
91
+ nil # in case there is a mismatch, we ignore the error as it is not important for the seeding
92
+ end
93
+
94
+ def random_user
95
+ user = Decidim::User.where(organization:).not_deleted.not_blocked.confirmed.sample
96
+
97
+ user.valid? ? user : random_user
98
+ end
99
+
100
+ def random_user_group(user)
101
+ user_group = Decidim::UserGroups::ManageableUserGroups.for(user).verified.sample
102
+ return nil unless user_group&.valid?
103
+
104
+ [true, false].sample ? user_group : nil
105
+ end
56
106
  end
57
107
  end
58
108
  end
@@ -1,5 +1,5 @@
1
1
  // CSS
2
2
  import "stylesheets/comments.scss"
3
3
 
4
- // Javacript
4
+ // JavaScript
5
5
  import "src/decidim/comments/comments"
@@ -2,7 +2,7 @@
2
2
  /* eslint max-lines: ["error", {"max": 350, "skipBlankLines": true}] */
3
3
 
4
4
  /**
5
- * A plain Javascript component that handles the comments.
5
+ * A plain JavaScript component that handles the comments.
6
6
  *
7
7
  * @class
8
8
  * @augments Component
@@ -56,7 +56,7 @@ export default class CommentsComponent {
56
56
  this.mounted = false;
57
57
  this._stopPolling();
58
58
 
59
- $(".add-comment .opinion-toggle button", this.$element).off("click.decidim-comments");
59
+ $(".add-comment [data-opinion-toggle] button", this.$element).off("click.decidim-comments");
60
60
  $(".add-comment textarea", this.$element).off("input.decidim-comments");
61
61
  $(".add-comment form", this.$element).off("submit.decidim-comments");
62
62
  $(".add-comment textarea", this.$element).each((_i, el) => el.removeEventListener("emoji.added", this._onTextInput));
@@ -117,7 +117,7 @@ export default class CommentsComponent {
117
117
  $(".add-comment", $parent).each((_i, el) => {
118
118
  const $add = $(el);
119
119
  const $form = $("form", $add);
120
- const $opinionButtons = $(".opinion-toggle button", $add);
120
+ const $opinionButtons = $("[data-opinion-toggle] button", $add);
121
121
  const $text = $("textarea", $form);
122
122
 
123
123
  $opinionButtons.on("click.decidim-comments", this._onToggleOpinion);
@@ -280,18 +280,18 @@ export default class CommentsComponent {
280
280
 
281
281
  const $add = $btn.closest(".add-comment");
282
282
  const $form = $("form", $add);
283
- const $opinionButtons = $(".opinion-toggle button", $add);
284
- const $selectedState = $(".opinion-toggle .selected-state", $add);
283
+ const $opinionButtons = $("[data-opinion-toggle] button", $add);
284
+ const $selectedState = $("[data-opinion-toggle] .selected-state", $add);
285
285
  const $alignment = $(".alignment-input", $form);
286
286
 
287
287
  $opinionButtons.removeClass("is-active").attr("aria-pressed", "false");
288
288
  $btn.addClass("is-active").attr("aria-pressed", "true");
289
289
 
290
- if ($btn.is(".opinion-toggle--ok")) {
290
+ if ($btn.data("toggleOk")) {
291
291
  $alignment.val(1);
292
- } else if ($btn.is(".opinion-toggle--meh")) {
292
+ } else if ($btn.data("toggleMeh")) {
293
293
  $alignment.val(0);
294
- } else if ($btn.is(".opinion-toggle--ko")) {
294
+ } else if ($btn.data("toggleKo")) {
295
295
  $alignment.val(-1);
296
296
  }
297
297
 
@@ -45,7 +45,7 @@ describe("CommentsComponent", () => {
45
45
  const spyOnAddComment = (methodToSpy) => {
46
46
  addComment.each((i) => {
47
47
  addComment[i].$ = $(addComment[i]);
48
- addComment[i].opinionToggles = $(".opinion-toggle button", addComment[i].$);
48
+ addComment[i].opinionToggles = $("[data-opinion-toggle] button", addComment[i].$);
49
49
  addComment[i].commentForm = $("form", addComment[i].$);
50
50
  addComment[i].commentTextarea = $("textarea", addComment[i].commentForm);
51
51
 
@@ -66,7 +66,7 @@ describe("CommentsComponent", () => {
66
66
  return orderLinks;
67
67
  } else if (jqSelector === ".add-comment" && parent.is(subject.$element)) {
68
68
  return addComment;
69
- } else if (jqSelector === ".add-comment .opinion-toggle button" && parent.is(subject.$element)) {
69
+ } else if (jqSelector === ".add-comment [data-opinion-toggle] button" && parent.is(subject.$element)) {
70
70
  return allToggles;
71
71
  } else if (jqSelector === ".add-comment textarea" && parent.is(subject.$element)) {
72
72
  return allTextareas;
@@ -75,7 +75,7 @@ describe("CommentsComponent", () => {
75
75
  }
76
76
  const addCommentsArray = addComment.toArray();
77
77
  for (let i = 0; i < addCommentsArray.length; i += 1) {
78
- if (jqSelector === ".opinion-toggle button" && parent.is(addCommentsArray[i].$)) {
78
+ if (jqSelector === "[data-opinion-toggle] button" && parent.is(addCommentsArray[i].$)) {
79
79
  return addCommentsArray[i].opinionToggles;
80
80
  } else if (jqSelector === "form" && parent.is(addCommentsArray[i].$)) {
81
81
  return addCommentsArray[i].commentForm;
@@ -102,7 +102,7 @@ describe("CommentsComponent", () => {
102
102
  </div>
103
103
 
104
104
  <div class="form__wrapper gap-2">
105
- <label class="show-for-sr" for="add-comment-${modelName}-${modelId}">
105
+ <label for="add-comment-${modelName}-${modelId}">
106
106
  Comment
107
107
  </label>
108
108
  <span class="emoji__container">
@@ -233,7 +233,7 @@ describe("CommentsComponent", () => {
233
233
  <div class="comment__content">
234
234
  <div><p>${content}</p></div>
235
235
  </div>
236
- <div class="comment__footer" data-component="accordion" role="presentation">
236
+ <div data-comment-footer data-component="accordion" role="presentation">
237
237
  <div class="comment__footer-grid">
238
238
  <div class="comment__actions">
239
239
  <button class="button button__sm button__text-secondary" data-controls="panel-comment${commentId}-reply" role="button" tabindex="0" aria-controls="panel-comment${commentId}-reply" aria-expanded="false" aria-disabled="false">
@@ -323,21 +323,21 @@ describe("CommentsComponent", () => {
323
323
  ${secondThread}
324
324
  </div>
325
325
  <div class="add-comment">
326
- <div class="opinion-toggle button-group comment__opinion-container">
327
- <span class="show-for-sr py-1.5">Your opinion about this topic</span>
328
- <button aria-pressed="false" class="button button__sm button__text-secondary opinion-toggle--ok" data-selected-label="Your opinion about this topic is positive">
326
+ <div data-opinion-toggle class="button-group comment__opinion-container">
327
+ <span class="py-1.5">Your opinion about this topic</span>
328
+ <button aria-pressed="false" class="button button__sm button__text-secondary" data-toggle-ok="true" data-selected-label="Your opinion about this topic is positive">
329
329
  <svg width="1em" height="1em" role="img" aria-hidden="true"><use href="/decidim-packs/media/images/remixicon.symbol-5540ed538fb6bd400d2a.svg#ri-thumb-up-line" tabindex="-1"></use></svg>
330
330
  <svg width="1em" height="1em" role="img" aria-hidden="true"><use href="/decidim-packs/media/images/remixicon.symbol-5540ed538fb6bd400d2a.svg#ri-thumb-up-fill" tabindex="-1"></use></svg>
331
- <span class="show-for-sr">Positive</span>
331
+ <span>Positive</span>
332
332
  </button>
333
- <button aria-pressed="true" class="button button__sm button__text-secondary opinion-toggle--meh is-active" data-selected-label="Your opinion about this topic is neutral">
334
- <span class="show-for-sr">Neutral
333
+ <button aria-pressed="true" class="button button__sm button__text-secondary is-active" data-toggle-meh="true" data-selected-label="Your opinion about this topic is neutral">
334
+ <span>Neutral
335
335
  </span>
336
336
  </button>
337
- <button aria-pressed="false" class="button button__sm button__text-secondary opinion-toggle--ko" data-selected-label="Your opinion about this topic is negative">
337
+ <button aria-pressed="false" class="button button__sm button__text-secondary" data-toggle-ko="true" data-selected-label="Your opinion about this topic is negative">
338
338
  <svg width="1em" height="1em" role="img" aria-hidden="true"><use href="/decidim-packs/media/images/remixicon.symbol-5540ed538fb6bd400d2a.svg#ri-thumb-down-line" tabindex="-1"></use></svg>
339
339
  <svg width="1em" height="1em" role="img" aria-hidden="true"><use href="/decidim-packs/media/images/remixicon.symbol-5540ed538fb6bd400d2a.svg#ri-thumb-down-fill" tabindex="-1"></use></svg>
340
- <span class="show-for-sr">Negative</span>
340
+ <span>Negative</span>
341
341
  </button>
342
342
  <div role="alert" aria-live="assertive" aria-atomic="true" class="selected-state sr-only"></div>
343
343
  </div>
@@ -371,7 +371,7 @@ describe("CommentsComponent", () => {
371
371
  addComment = $(".add-comment", subject.$element);
372
372
  orderLinks = $(".comment-order-by a.comment-order-by__item", subject.$element);
373
373
 
374
- allToggles = $(".add-comment .opinion-toggle .button", subject.$element);
374
+ allToggles = $(".add-comment [data-opinion-toggle] .button", subject.$element);
375
375
  allTextareas = $(".add-comment textarea", subject.$element);
376
376
  allForms = $(".add-comment form", subject.$element);
377
377
  });
@@ -8,8 +8,8 @@
8
8
  if (inReplyTo) {
9
9
  component.addReply(inReplyTo, commentHtml, true);
10
10
 
11
- var hideButton = $("#comment_" + <%= root_comment.id %>).find(".comment__hide").first();
12
- hideButton.find(".show-comment-replies").first().html('<%= t("decidim.components.comment.show_replies", count: Decidim::Comments::SortedComments.for(root_comment.reload).size) %>');
11
+ var hideButton = $("#comment_" + <%= root_comment.id %>).find("[data-comment-hide]").first();
12
+ hideButton.find("[data-show-comment-reply]").first().html('<%= t("decidim.components.comment.show_replies", count: Decidim::Comments::SortedComments.for(root_comment.reload).size) %>');
13
13
 
14
14
  } else {
15
15
  component.addThread(commentHtml, true);
@@ -5,11 +5,14 @@ $(() => {
5
5
  const $comment = $(`#comment_${commentId}`);
6
6
  const $commentReply = $(`#comment${commentId}-reply`);
7
7
  const $content = $("> .comment__content", $comment);
8
- const sectionsToDelete = ["header", "footer-grid", "reply", "additionalreply"];
8
+ const sectionsToDelete = ["footer-grid", "reply"];
9
9
 
10
10
  sectionsToDelete.forEach((section) => {
11
- $(`> .comment__${section}`, $comment).remove();
11
+ $(`#comment_${commentId} > [data-comment-footer] > .comment__${section}`).remove();
12
12
  });
13
+ $(`#comment_${commentId} > .comment__header`).remove();
14
+ $(`#comment_${commentId} > [data-additional-reply]`).remove();
15
+
13
16
  $commentReply.remove();
14
17
  $content.replaceWith(deleteDataHtml);
15
18
  Rails.fire(document, "comments:loaded", {
@@ -3,7 +3,7 @@
3
3
  var upVotes = <%= comment.up_votes.count.to_json %>;
4
4
  var downVotes = <%= comment.down_votes.count.to_json %>;
5
5
  var $comment = $("#comment_" + commentId);
6
- var $votes = $("> .comment__footer > .comment__footer-grid .comment__votes", $comment);
6
+ var $votes = $("> [data-comment-footer] > .comment__footer-grid .comment__votes", $comment);
7
7
  var $upVote = $(".js-comment__votes--up", $votes);
8
8
  var $downVote = $(".js-comment__votes--down", $votes);
9
9
 
@@ -39,7 +39,6 @@ bg:
39
39
  error: Възникна проблем с гласуването за коментара.
40
40
  components:
41
41
  add_comment_form:
42
- account_message: <a href="%{sign_in_url}">Влезте в профила си</a> или <a href="%{sign_up_url}">се регистрирайте</a>, за да добавите Вашия коментар.
43
42
  form:
44
43
  body:
45
44
  label: Коментар
@@ -39,7 +39,7 @@ ca:
39
39
  error: S'ha produït un error en votar el comentari.
40
40
  components:
41
41
  add_comment_form:
42
- account_message: Per afegir un comentari, <a href="%{sign_in_url}">inicia la teva sessió</a> o <a href="%{sign_up_url}">registra't</a>.
42
+ account_message: <a href="%{sign_in_url}">Inicia sessió</a> o <a href="%{sign_up_url}">crea un compte</a>per afegir el teu comentari.
43
43
  form:
44
44
  body:
45
45
  label: Comentari
@@ -43,7 +43,6 @@ cs:
43
43
  error: Při hlasování o komentáři došlo k chybě.
44
44
  components:
45
45
  add_comment_form:
46
- account_message: <a href="%{sign_in_url}">Přihlaste se pomocí svého účtu</a> nebo se <a href="%{sign_up_url}">zaregistrujte</a> a přidejte svůj komentář.
47
46
  form:
48
47
  body:
49
48
  label: Komentář
@@ -39,7 +39,7 @@ de:
39
39
  error: Beim Abstimmen des Kommentars sind Fehler aufgetreten.
40
40
  components:
41
41
  add_comment_form:
42
- account_message: <a href="%{sign_in_url}">Melden Sie sich mit Ihrem Konto an</a> oder <a href="%{sign_up_url}">registrieren Sie sich</a>, um Ihren Kommentar hinzuzufügen.
42
+ account_message: Sie müssen sich <a href="%{sign_in_url}">mit einem bestehendem Konto anmelden</a> oder <a href="%{sign_up_url}"> ein neues Konto registrieren</a>, um Ihren Kommentar hinzufügen.
43
43
  form:
44
44
  body:
45
45
  label: Kommentar
@@ -39,7 +39,7 @@ en:
39
39
  error: There was a problem voting the comment.
40
40
  components:
41
41
  add_comment_form:
42
- account_message: <a href="%{sign_in_url}">Log in with your account</a> or <a href="%{sign_up_url}">sign up</a> to add your comment.
42
+ account_message: <a href="%{sign_in_url}">Log in</a> or <a href="%{sign_up_url}">create an account</a> to add your comment.
43
43
  form:
44
44
  body:
45
45
  label: Comment
@@ -39,7 +39,7 @@ es-MX:
39
39
  error: Ha habido errores al votar el comentario.
40
40
  components:
41
41
  add_comment_form:
42
- account_message: Para añadir un comentario, <a href="%{sign_in_url}">inicia tu sesión </a> o <a href="%{sign_up_url}">regístrate</a>.
42
+ account_message: <a href="%{sign_in_url}">Inicia sesión</a> o <a href="%{sign_up_url}">crea una cuenta</a> para añadir tu comentario.
43
43
  form:
44
44
  body:
45
45
  label: Comentario
@@ -39,7 +39,7 @@ es-PY:
39
39
  error: Ha habido errores al votar el comentario.
40
40
  components:
41
41
  add_comment_form:
42
- account_message: Para añadir un comentario, <a href="%{sign_in_url}">inicia tu sesión </a> o <a href="%{sign_up_url}">regístrate</a>.
42
+ account_message: <a href="%{sign_in_url}">Inicia sesión</a> o <a href="%{sign_up_url}">crea una cuenta</a> para añadir tu comentario.
43
43
  form:
44
44
  body:
45
45
  label: Comentario
@@ -39,7 +39,7 @@ es:
39
39
  error: Se ha producido un error al votar el comentario.
40
40
  components:
41
41
  add_comment_form:
42
- account_message: Para añadir un comentario, <a href="%{sign_in_url}">inicia tu sesión </a> o <a href="%{sign_up_url}">regístrate</a>.
42
+ account_message: <a href="%{sign_in_url}">Inicia sesión</a> o <a href="%{sign_up_url}">crea una cuenta</a> para añadir tu comentario.
43
43
  form:
44
44
  body:
45
45
  label: Comentario
@@ -39,7 +39,7 @@ eu:
39
39
  error: Arazo bat egon da iruzkina bozkatzean.
40
40
  components:
41
41
  add_comment_form:
42
- account_message: <a href="%{sign_in_url}">Sartu zure kontuarekin</a> edo <a href="%{sign_up_url}">erregistratu</a> zure iruzkina gehitzeko.
42
+ account_message: Sortu kontu bat <a href="%{sign_in_url}">Log in</a> edo <a href="%{sign_up_url}"> </a> zure iruzkina gehitzeko.
43
43
  form:
44
44
  body:
45
45
  label: Iruzkina
@@ -39,7 +39,7 @@ fi-pl:
39
39
  error: Äänestettäessä kommenttia tapahtui virhe.
40
40
  components:
41
41
  add_comment_form:
42
- account_message: <a href="%{sign_in_url}">Kirjaudu tilillesi</a> tai <a href="%{sign_up_url}">rekisteröidy</a> kommentoidaksesi.
42
+ account_message: <a href="%{sign_in_url}">Kirjaudu sisään</a> tai <a href="%{sign_up_url}">luo tili</a> kommentoidaksesi.
43
43
  form:
44
44
  body:
45
45
  label: Kommentti
@@ -39,7 +39,7 @@ fi:
39
39
  error: Kommentin äänestys epäonnistui.
40
40
  components:
41
41
  add_comment_form:
42
- account_message: <a href="%{sign_in_url}">Kirjaudu tilillesi</a> tai <a href="%{sign_up_url}">rekisteröidy</a> kommentoidaksesi.
42
+ account_message: <a href="%{sign_in_url}">Kirjaudu sisään</a> tai <a href="%{sign_up_url}">luo tili</a> kommentoidaksesi.
43
43
  form:
44
44
  body:
45
45
  label: Kommentti
@@ -39,7 +39,7 @@ fr-CA:
39
39
  error: Une erreur s'est produite lors du vote sur le commentaire.
40
40
  components:
41
41
  add_comment_form:
42
- account_message: <a href="%{sign_in_url}">Connectez-vous avec votre compte</a> ou <a href="%{sign_up_url}"> inscrivez-vous </a> pour ajouter votre commentaire.
42
+ account_message: <a href="%{sign_in_url}">Connectez-vous</a> ou <a href="%{sign_up_url}">créez un compte</a> pour ajouter votre commentaire.
43
43
  form:
44
44
  body:
45
45
  label: Commentaire
@@ -39,7 +39,7 @@ fr:
39
39
  error: Une erreur s'est produite lors du vote sur le commentaire.
40
40
  components:
41
41
  add_comment_form:
42
- account_message: <a href="%{sign_in_url}">Connectez-vous avec votre compte</a> ou <a href="%{sign_up_url}"> inscrivez-vous </a> pour ajouter votre commentaire.
42
+ account_message: <a href="%{sign_in_url}">Connectez-vous</a> ou <a href="%{sign_up_url}">créez un compte</a> pour ajouter votre commentaire.
43
43
  form:
44
44
  body:
45
45
  label: Commentaire
@@ -37,7 +37,7 @@ ja:
37
37
  error: コメントに投票中に問題がありました。
38
38
  components:
39
39
  add_comment_form:
40
- account_message: <a href="%{sign_in_url}">ログイン</a> または <a href="%{sign_up_url}">サインアップ</a> してコメントできます。
40
+ account_message: コメントを追加するには<a href="%{sign_in_url}">ログインする</a> <a href="%{sign_up_url}">アカウントを作成</a>してください
41
41
  form:
42
42
  body:
43
43
  label: コメント
@@ -43,7 +43,7 @@ pl:
43
43
  error: Podczas dodawania komentarza wystąpił błąd.
44
44
  components:
45
45
  add_comment_form:
46
- account_message: <a href="%{sign_in_url}">Zaloguj się na swoje konto</a> lub <a href="%{sign_up_url}">zarejestruj się</a>, aby dodać swój komentarz.
46
+ account_message: <a href="%{sign_in_url}">Zaloguj się</a> lub <a href="%{sign_up_url}">utwórz konto</a>, aby dodać swój komentarz.
47
47
  form:
48
48
  body:
49
49
  label: Komentarz
@@ -41,7 +41,6 @@ ro:
41
41
  error: A apărut o problemă la votarea comentariului.
42
42
  components:
43
43
  add_comment_form:
44
- account_message: <a href="%{sign_in_url}">Conectați-vă cu contul dumneavoastră</a> sau <a href="%{sign_up_url}">înregistrați-vă</a> pentru a adăuga un comentariu.
45
44
  form:
46
45
  body:
47
46
  label: Comentariu
@@ -25,7 +25,6 @@ tr:
25
25
  error: Yorum oylanırken bir sorun oluştu.
26
26
  components:
27
27
  add_comment_form:
28
- account_message: <a href="%{sign_in_url}">Hesabınızla giriş yapın</a> veya yorumunuzu eklemek için <a href="%{sign_up_url}">kaydolun</a>.
29
28
  form:
30
29
  body:
31
30
  label: Yorum
data/db/seeds.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # Since comments cannot exist without a real model we are not including
3
4
  # specific seeds for this engine.
4
5
  # Other engines are free to include comments on their seeds like this:
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  "homepage_uri" => "https://decidim.org",
20
20
  "source_code_uri" => "https://github.com/decidim/decidim"
21
21
  }
22
- s.required_ruby_version = "~> 3.1.0"
22
+ s.required_ruby_version = "~> 3.2.0"
23
23
 
24
24
  s.name = "decidim-comments"
25
25
  s.summary = "Decidim comments module"
@@ -17,9 +17,10 @@ module Decidim
17
17
  params = { "comment" => { "body" => body, "alignment" => alignment, "user_group_id" => user_group_id, "commentable" => object } }
18
18
  form = Decidim::Comments::CommentForm.from_params(params).with_context(
19
19
  current_organization: context[:current_organization],
20
+ current_user: context[:current_user],
20
21
  current_component: object.component
21
22
  )
22
- Decidim::Comments::CreateComment.call(form, context[:current_user]) do
23
+ Decidim::Comments::CreateComment.call(form) do
23
24
  on(:ok) do |comment|
24
25
  return comment
25
26
  end
@@ -28,7 +28,7 @@ module Decidim
28
28
  false
29
29
  end
30
30
 
31
- # Public: Whether the object's comments can have have votes or not. It enables the
31
+ # Public: Whether the object's comments can have votes or not. It enables the
32
32
  # upvote and downvote buttons for comments.
33
33
  def comments_have_votes?
34
34
  false
@@ -58,7 +58,7 @@ module Decidim
58
58
  end
59
59
 
60
60
  # Public: Updates the comments counter cache. We have to do it these
61
- # way in order to properly calculate the coutner with hidden
61
+ # way in order to properly calculate the counter with hidden
62
62
  # comments.
63
63
  #
64
64
  # rubocop:disable Rails/SkipsModelValidations
@@ -6,6 +6,7 @@ RSpec.shared_context "when creating a comment" do
6
6
  let(:component) { create(:component, participatory_space: participatory_process) }
7
7
  let(:user) { create(:user, organization:) }
8
8
  let(:author) { create(:user, organization:) }
9
+ let(:current_user) { author }
9
10
  let(:dummy_resource) { create :dummy_resource, component: }
10
11
  let(:commentable) { dummy_resource }
11
12
  let(:body) { Faker::Lorem.paragraph }
@@ -25,8 +26,8 @@ RSpec.shared_context "when creating a comment" do
25
26
  Decidim::Comments::CommentForm.from_params(
26
27
  form_params
27
28
  ).with_context(
28
- current_organization: organization
29
+ current_organization: organization, current_user:
29
30
  )
30
31
  end
31
- let(:command) { described_class.new(form, author) }
32
+ let(:command) { described_class.new(form) }
32
33
  end
@@ -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.28.2"
7
+ "0.29.0.rc2"
8
8
  end
9
9
  end
10
10
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :decidim_comments do
4
+ namespace :upgrade do
5
+ desc "Adds participatory_process_id to comments if they are associated with a participatory process"
6
+ task participatory_process_in_comments: :environment do
7
+ puts "Updating comments..."
8
+ ok = errors = 0
9
+
10
+ log = ActiveSupport::Logger.new(Rails.root.join("log/update_participatory_process_in_comments.log"))
11
+ Decidim::Comments::Comment.where(participatory_space: nil).find_each do |c|
12
+ c.participatory_space = if c.root_commentable.is_a?(Decidim::Participable)
13
+ c.root_commentable
14
+ else
15
+ c.commentable.try(:participatory_space)
16
+ end
17
+ c.save(validate: false)
18
+ ok += 1
19
+ rescue StandardError => e
20
+ errors += 1
21
+ log.info "Error updating comment ##{c.id}: #{e.message}"
22
+ end
23
+
24
+ puts "#{ok} comments updated."
25
+ puts "#{errors} errors found. Check the file 'log/update_participatory_process_in_comments.log' for more information." if errors.positive?
26
+ end
27
+ end
28
+ 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.28.2
4
+ version: 0.29.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josep Jaume Rey Peroy
@@ -18,14 +18,14 @@ dependencies:
18
18
  requirements:
19
19
  - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: 0.28.2
21
+ version: 0.29.0.rc2
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.28.2
28
+ version: 0.29.0.rc2
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.28.2
55
+ version: 0.29.0.rc2
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.28.2
62
+ version: 0.29.0.rc2
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.28.2
69
+ version: 0.29.0.rc2
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.28.2
76
+ version: 0.29.0.rc2
77
77
  description: Pluggable comments system for some components.
78
78
  email:
79
79
  - josepjaume@gmail.com
@@ -296,7 +296,7 @@ files:
296
296
  - lib/decidim/comments/test/shared_examples/has_comments_availability_attributes.rb
297
297
  - lib/decidim/comments/test/shared_examples/translatable_comment.rb
298
298
  - lib/decidim/comments/version.rb
299
- - lib/tasks/decidim_comments.rake
299
+ - lib/tasks/upgrade/decidim_comments.rake
300
300
  homepage: https://decidim.org
301
301
  licenses:
302
302
  - AGPL-3.0
@@ -314,14 +314,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
314
314
  requirements:
315
315
  - - "~>"
316
316
  - !ruby/object:Gem::Version
317
- version: 3.1.0
317
+ version: 3.2.0
318
318
  required_rubygems_version: !ruby/object:Gem::Requirement
319
319
  requirements:
320
- - - ">="
320
+ - - ">"
321
321
  - !ruby/object:Gem::Version
322
- version: '0'
322
+ version: 1.3.1
323
323
  requirements: []
324
- rubygems_version: 3.3.7
324
+ rubygems_version: 3.4.10
325
325
  signing_key:
326
326
  specification_version: 4
327
327
  summary: Decidim comments module
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- namespace :decidim_comments do
4
- desc "Adds participatory_process_id to comments if they are associated with a participatory process"
5
- task update_participatory_process_in_comments: :environment do
6
- puts "Updating comments..."
7
- ok = errors = 0
8
-
9
- log = ActiveSupport::Logger.new(Rails.root.join("log/update_participatory_process_in_comments.log"))
10
- Decidim::Comments::Comment.where(participatory_space: nil).find_each do |c|
11
- c.participatory_space = if c.root_commentable.is_a?(Decidim::Participable)
12
- c.root_commentable
13
- else
14
- c.commentable.try(:participatory_space)
15
- end
16
- c.save(validate: false)
17
- ok += 1
18
- rescue StandardError => e
19
- errors += 1
20
- log.info "Error updating comment ##{c.id}: #{e.message}"
21
- end
22
-
23
- puts "#{ok} comments updated."
24
- puts "#{errors} errors found. Check the file 'log/update_participatory_process_in_comments.log' for more information." if errors.positive?
25
- end
26
- end