decidim-comments 0.27.4 → 0.28.0.rc5
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.
- checksums.yaml +4 -4
- data/app/cells/decidim/comments/comment/actions.erb +13 -7
- data/app/cells/decidim/comments/comment/alignment_badge.erb +1 -4
- data/app/cells/decidim/comments/comment/deletion_data.erb +9 -1
- data/app/cells/decidim/comments/comment/moderation_data.erb +1 -1
- data/app/cells/decidim/comments/comment/replies.erb +3 -0
- data/app/cells/decidim/comments/comment/show.erb +72 -35
- data/app/cells/decidim/comments/comment/votes.erb +14 -14
- data/app/cells/decidim/comments/comment_activity_cell.rb +11 -7
- data/app/cells/decidim/comments/comment_card_cell.rb +2 -2
- data/app/cells/decidim/comments/comment_cell.rb +5 -15
- data/app/cells/decidim/comments/comment_form/comment_as.erb +3 -3
- data/app/cells/decidim/comments/comment_form/opinion.erb +18 -0
- data/app/cells/decidim/comments/comment_form/show.erb +33 -16
- data/app/cells/decidim/comments/comment_form_cell.rb +11 -3
- data/app/cells/decidim/comments/comment_metadata_cell.rb +27 -0
- data/app/cells/decidim/comments/comment_s_cell.rb +27 -0
- data/app/cells/decidim/comments/comment_thread/show.erb +2 -5
- data/app/cells/decidim/comments/comment_thread_cell.rb +0 -6
- data/app/cells/decidim/comments/comments/add_comment.erb +1 -20
- data/app/cells/decidim/comments/comments/blocked_comments_warning.erb +1 -3
- data/app/cells/decidim/comments/comments/comments_loading.erb +1 -3
- data/app/cells/decidim/comments/comments/order_control.erb +11 -35
- data/app/cells/decidim/comments/comments/show.erb +8 -9
- data/app/cells/decidim/comments/comments/single_comment_warning.erb +6 -9
- data/app/cells/decidim/comments/comments/user_comments_blocked_warning.erb +9 -6
- data/app/cells/decidim/comments/comments_cell.rb +1 -1
- data/app/cells/decidim/comments/edit_comment_modal_form/show.erb +20 -15
- data/app/commands/decidim/comments/create_comment.rb +17 -5
- data/app/commands/decidim/comments/delete_comment.rb +1 -1
- data/app/commands/decidim/comments/update_comment.rb +14 -2
- data/app/commands/decidim/comments/vote_comment.rb +1 -1
- data/app/controllers/decidim/comments/comments_controller.rb +14 -9
- data/app/controllers/decidim/comments/votes_controller.rb +1 -1
- data/app/events/decidim/comments/comment_by_followed_user_event.rb +1 -1
- data/app/events/decidim/comments/comment_by_followed_user_group_event.rb +1 -1
- data/app/events/decidim/comments/comment_event.rb +2 -3
- data/app/events/decidim/comments/reply_created_event.rb +1 -1
- data/app/events/decidim/comments/user_group_mentioned_event.rb +1 -1
- data/app/events/decidim/comments/user_mentioned_event.rb +1 -1
- data/app/helpers/decidim/comments/comment_cells_helper.rb +1 -1
- data/app/jobs/decidim/comments/hide_all_created_by_author_job.rb +13 -0
- data/app/models/decidim/comments/comment.rb +8 -4
- data/app/models/decidim/comments/seed.rb +30 -14
- data/app/packs/entrypoints/decidim_comments.js +5 -0
- data/app/packs/src/decidim/comments/comments.component.js +27 -36
- data/app/packs/src/decidim/comments/comments.component.test.js +218 -240
- data/app/packs/src/decidim/comments/comments.component_for_testing.js +1 -1
- data/app/packs/src/decidim/comments/comments.js +20 -1
- data/app/packs/stylesheets/comments.scss +327 -0
- data/app/queries/decidim/comments/metrics/comments_metric_manage.rb +1 -1
- data/app/queries/decidim/comments/sorted_comments.rb +10 -10
- data/app/services/decidim/comments/comment_creation.rb +1 -1
- data/app/services/decidim/comments/new_comment_notification_creator.rb +8 -8
- data/app/views/decidim/comments/admin/shared/_availability_fields.html.erb +4 -9
- data/app/views/decidim/comments/comments/_comment.html.erb +1 -1
- data/app/views/decidim/comments/comments/_comments.html.erb +1 -1
- data/app/views/decidim/comments/comments/_delete.html.erb +2 -4
- data/app/views/decidim/comments/comments/_moderated.html.erb +2 -4
- data/app/views/decidim/comments/comments/create.js.erb +5 -3
- data/app/views/decidim/comments/comments/delete.js.erb +4 -1
- data/app/views/decidim/comments/comments/index.js.erb +8 -1
- data/app/views/decidim/comments/comments/reload.js.erb +1 -2
- data/app/views/decidim/comments/comments/update.js.erb +5 -4
- data/app/views/decidim/comments/votes/create.js.erb +5 -5
- data/config/assets.rb +3 -0
- data/config/environment.rb +3 -0
- data/config/locales/ar.yml +0 -16
- data/config/locales/ca.yml +8 -10
- data/config/locales/cs.yml +8 -10
- data/config/locales/de.yml +6 -8
- data/config/locales/el.yml +3 -11
- data/config/locales/en.yml +10 -12
- data/config/locales/es-MX.yml +10 -12
- data/config/locales/es-PY.yml +10 -12
- data/config/locales/es.yml +9 -11
- data/config/locales/eu.yml +26 -28
- data/config/locales/fi-plain.yml +7 -9
- data/config/locales/fi.yml +7 -9
- data/config/locales/fr-CA.yml +9 -11
- data/config/locales/fr.yml +9 -11
- data/config/locales/ga-IE.yml +0 -4
- data/config/locales/gl.yml +0 -16
- data/config/locales/hu.yml +5 -11
- data/config/locales/id-ID.yml +0 -11
- data/config/locales/is-IS.yml +0 -8
- data/config/locales/it.yml +0 -16
- data/config/locales/ja.yml +10 -12
- data/config/locales/lb.yml +0 -16
- data/config/locales/lt.yml +12 -10
- data/config/locales/lv.yml +0 -11
- data/config/locales/nl.yml +0 -16
- data/config/locales/no.yml +0 -16
- data/config/locales/pl.yml +16 -10
- data/config/locales/pt-BR.yml +0 -16
- data/config/locales/pt.yml +0 -16
- data/config/locales/ro-RO.yml +2 -10
- data/config/locales/ru.yml +0 -11
- data/config/locales/sk.yml +0 -11
- data/config/locales/sq-AL.yml +1 -0
- data/config/locales/sv.yml +5 -16
- data/config/locales/th-TH.yml +1 -0
- data/config/locales/tr-TR.yml +1 -13
- data/config/locales/uk.yml +0 -8
- data/config/locales/zh-CN.yml +0 -13
- data/config/locales/zh-TW.yml +1 -9
- data/lib/decidim/api/commentable_interface.rb +1 -1
- data/lib/decidim/comments/comment_serializer.rb +2 -2
- data/lib/decidim/comments/comment_vote_serializer.rb +2 -2
- data/lib/decidim/comments/commentable.rb +1 -1
- data/lib/decidim/comments/comments_helper.rb +6 -3
- data/lib/decidim/comments/engine.rb +31 -1
- data/lib/decidim/comments/export.rb +1 -1
- data/lib/decidim/comments/test/factories.rb +2 -2
- data/lib/decidim/comments/test/shared_examples/comment_event.rb +3 -3
- data/lib/decidim/comments/test/shared_examples/comment_voted_event.rb +3 -3
- data/lib/decidim/comments/test/shared_examples/create_comment_context.rb +5 -5
- data/lib/decidim/comments/test/shared_examples/has_comments_availability_attributes.rb +2 -2
- data/lib/decidim/comments/test/shared_examples/translatable_comment.rb +3 -3
- data/lib/decidim/comments/version.rb +1 -1
- metadata +28 -20
- data/app/cells/decidim/comments/comment/author.erb +0 -1
- data/app/cells/decidim/comments/comment/utilities.erb +0 -41
- data/app/cells/decidim/comments/comment_m/footer.erb +0 -5
- data/app/cells/decidim/comments/comment_m/top.erb +0 -7
- data/app/cells/decidim/comments/comment_m_cell.rb +0 -29
- data/app/cells/decidim/comments/comment_thread/title.erb +0 -3
|
@@ -1,36 +1,12 @@
|
|
|
1
|
-
<div class="
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
|
2
|
+
<div id="comments">
|
|
3
3
|
<div class="comments">
|
|
4
|
-
<div class="
|
|
5
|
-
<
|
|
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
|
-
|
|
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
|
-
</
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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>
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
<
|
|
4
|
-
|
|
5
|
-
<
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
|
@@ -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
|
|
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
|
-
|
|
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:
|
|
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
|
|
75
|
+
enforce_permission_to(:create, :comment, commentable:)
|
|
75
76
|
|
|
76
77
|
form = Decidim::Comments::CommentForm.from_params(
|
|
77
|
-
params.merge(commentable:
|
|
78
|
+
params.merge(commentable:)
|
|
78
79
|
).with_context(
|
|
79
|
-
current_organization
|
|
80
|
-
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
|
|
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
|
|
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
|
|
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
|
-
#
|
|
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
|
-
|
|
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
|
|
@@ -29,6 +29,7 @@ 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
|
|
32
33
|
|
|
33
34
|
belongs_to :commentable, foreign_key: "decidim_commentable_id", foreign_type: "decidim_commentable_type", polymorphic: true
|
|
34
35
|
belongs_to :root_commentable, foreign_key: "decidim_root_commentable_id", foreign_type: "decidim_root_commentable_type", polymorphic: true, touch: true
|
|
@@ -179,12 +180,15 @@ module Decidim
|
|
|
179
180
|
root_commentable.can_participate?(user)
|
|
180
181
|
end
|
|
181
182
|
|
|
182
|
-
|
|
183
|
-
|
|
183
|
+
# The override_translation argument has been added to be able to use this
|
|
184
|
+
# method from comment event in the resource_text method which requires
|
|
185
|
+
# the use of this argument in translated_attribute of body
|
|
186
|
+
def formatted_body(override_translation = nil)
|
|
187
|
+
Decidim::ContentProcessor.render(sanitize_content_for_comment(render_markdown(translated_body(override_translation))), "div")
|
|
184
188
|
end
|
|
185
189
|
|
|
186
|
-
def translated_body
|
|
187
|
-
translated_attribute(body, organization)
|
|
190
|
+
def translated_body(override_translation = nil)
|
|
191
|
+
translated_attribute(body, organization, override_translation)
|
|
188
192
|
end
|
|
189
193
|
|
|
190
194
|
def delete!
|
|
@@ -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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return
|
|
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
|
-
|
|
19
|
+
Decidim::Comments::Comment.reset_column_information
|
|
18
20
|
|
|
19
|
-
|
|
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
|
-
|
|
22
|
-
|
|
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
|
|
30
|
-
user_group:
|
|
45
|
+
author:,
|
|
46
|
+
user_group:
|
|
31
47
|
}
|
|
32
48
|
|
|
33
49
|
Decidim.traceability.create!(
|