decidim-comments 0.18.1 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d12a0b7056820ba66e3075215d6458de6249bfd570fc2763bb221543a223bee0
4
- data.tar.gz: a91677309faca25128e0e21148b473f930e4de1920b3db0c8105f4eab3744467
3
+ metadata.gz: 3f4e5986a2b09374bb8c2280de408bf5558d5ce57ee51d9d96e019a14310600d
4
+ data.tar.gz: f8a6f8e3d129d97233ca57feb43fa4ab0d4c0eebe7e3970dea66a550899ff288
5
5
  SHA512:
6
- metadata.gz: 2e1aa966f20ee100c28592bc7f1780c9ccb0d25654964d666b354fabeb97c2d22d20e4f9e8a84e53e588321fe4e20c62046a8a58dd6e6396542aa82c12443c68
7
- data.tar.gz: e776ad91bdf6e93be5ab4e9a1ab0e8218838390a4de8847693d5ad519f0c618c872013e425b3e0d645a01c70bb008a74fb7fe809e6d12ac75c6986a715e2a13c
6
+ metadata.gz: b7ca0fe89067bbbcb59fd111d2f6ad4c13ada5ced2b51affc57e967070f8a6681d0a1e69fc213d4dc4f5f4935e25a2bddcd439057b1643bf44ea344e17429942
7
+ data.tar.gz: f99afe1133b42867846a51793cc9f96d5401fd6a5b891aac310aa19fa0aa3d5a20a22dff7063f260bba4482d1840154786a3d0b510d3aab192c04ae782738b50
@@ -61,6 +61,7 @@ module Decidim
61
61
 
62
62
  def root_commentable(commentable)
63
63
  return commentable.root_commentable if commentable.is_a? Decidim::Comments::Comment
64
+
64
65
  commentable
65
66
  end
66
67
  end
@@ -3,31 +3,7 @@
3
3
  module Decidim
4
4
  module Comments
5
5
  class CommentByFollowedUserEvent < Decidim::Events::SimpleEvent
6
- include Decidim::Events::AuthorEvent
7
-
8
- delegate :author, to: :comment
9
-
10
- def resource_path
11
- resource_locator.path(url_params)
12
- end
13
-
14
- def resource_url
15
- resource_locator.url(url_params)
16
- end
17
-
18
- def resource_text
19
- comment.body
20
- end
21
-
22
- private
23
-
24
- def comment
25
- @comment ||= Decidim::Comments::Comment.find(extra[:comment_id])
26
- end
27
-
28
- def url_params
29
- { anchor: "comment_#{comment.id}" }
30
- end
6
+ include Decidim::Comments::CommentEvent
31
7
  end
32
8
  end
33
9
  end
@@ -3,31 +3,7 @@
3
3
  module Decidim
4
4
  module Comments
5
5
  class CommentCreatedEvent < Decidim::Events::SimpleEvent
6
- include Decidim::Events::AuthorEvent
7
-
8
- delegate :author, to: :comment
9
-
10
- def resource_path
11
- resource_locator.path(url_params)
12
- end
13
-
14
- def resource_url
15
- resource_locator.url(url_params)
16
- end
17
-
18
- def resource_text
19
- comment.body
20
- end
21
-
22
- private
23
-
24
- def comment
25
- @comment ||= Decidim::Comments::Comment.find(extra[:comment_id])
26
- end
27
-
28
- def url_params
29
- { anchor: "comment_#{comment.id}" }
30
- end
6
+ include Decidim::Comments::CommentEvent
31
7
  end
32
8
  end
33
9
  end
@@ -0,0 +1,38 @@
1
+ # frozen-string_literal: true
2
+
3
+ module Decidim
4
+ module Comments
5
+ # This module is used to be included in events triggered by comments.
6
+ #
7
+ module CommentEvent
8
+ extend ActiveSupport::Concern
9
+ include Decidim::Events::AuthorEvent
10
+
11
+ included do
12
+ delegate :author, to: :comment
13
+
14
+ def resource_path
15
+ resource_locator.path(url_params)
16
+ end
17
+
18
+ def resource_url
19
+ resource_locator.url(url_params)
20
+ end
21
+
22
+ def resource_text
23
+ comment.formatted_body
24
+ end
25
+
26
+ private
27
+
28
+ def comment
29
+ @comment ||= Decidim::Comments::Comment.find(extra[:comment_id])
30
+ end
31
+
32
+ def url_params
33
+ { anchor: "comment_#{comment.id}" }
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -3,31 +3,7 @@
3
3
  module Decidim
4
4
  module Comments
5
5
  class ReplyCreatedEvent < Decidim::Events::SimpleEvent
6
- include Decidim::Events::AuthorEvent
7
-
8
- delegate :author, to: :comment
9
-
10
- def resource_path
11
- resource_locator.path(url_params)
12
- end
13
-
14
- def resource_url
15
- resource_locator.url(url_params)
16
- end
17
-
18
- def resource_text
19
- comment.body
20
- end
21
-
22
- private
23
-
24
- def comment
25
- @comment ||= Decidim::Comments::Comment.find(extra[:comment_id])
26
- end
27
-
28
- def url_params
29
- { anchor: "comment_#{comment.id}" }
30
- end
6
+ include Decidim::Comments::CommentEvent
31
7
  end
32
8
  end
33
9
  end
@@ -3,31 +3,7 @@
3
3
  module Decidim
4
4
  module Comments
5
5
  class UserMentionedEvent < Decidim::Events::SimpleEvent
6
- include Decidim::Events::AuthorEvent
7
-
8
- delegate :author, to: :comment
9
-
10
- def resource_path
11
- resource_locator.path(url_params)
12
- end
13
-
14
- def resource_url
15
- resource_locator.url(url_params)
16
- end
17
-
18
- def resource_text
19
- comment.body
20
- end
21
-
22
- private
23
-
24
- def comment
25
- @comment ||= Decidim::Comments::Comment.find(extra[:comment_id])
26
- end
27
-
28
- def url_params
29
- { anchor: "comment_#{comment.id}" }
30
- end
6
+ include Decidim::Comments::CommentEvent
31
7
  end
32
8
  end
33
9
  end
@@ -41,6 +41,7 @@ module Decidim
41
41
 
42
42
  def participatory_space
43
43
  return root_commentable if root_commentable.is_a?(Decidim::Participable)
44
+
44
45
  root_commentable.participatory_space
45
46
  end
46
47
 
@@ -105,6 +106,12 @@ module Decidim
105
106
  .map(&:author).pluck(:id).flatten.compact.uniq
106
107
  end
107
108
 
109
+ def can_participate?(user)
110
+ return true unless root_commentable&.respond_to?(:can_participate?)
111
+
112
+ root_commentable.can_participate?(user)
113
+ end
114
+
108
115
  private
109
116
 
110
117
  # Private: Check if commentable can have comments and if not adds
@@ -23,6 +23,7 @@ module Decidim
23
23
  # Private: check if the comment and the author have the same organization
24
24
  def author_and_comment_same_organization
25
25
  return unless author.present? && comment.present?
26
+
26
27
  errors.add(:comment, :invalid) unless author.organization == comment.organization
27
28
  end
28
29
  end
@@ -18,6 +18,7 @@ module Decidim
18
18
  related_object = comment.root_commentable
19
19
  next unless related_object
20
20
  next unless check_participatory_space(@resource, related_object)
21
+
21
22
  cumulative_users << comment.decidim_author_id
22
23
  quantity_users << comment.decidim_author_id if comment.created_at >= start_time
23
24
  end
@@ -32,6 +33,7 @@ module Decidim
32
33
  def check_participatory_space(participatory_space, related_object)
33
34
  return related_object.participatory_space == participatory_space if related_object.respond_to?(:participatory_space)
34
35
  return related_object == participatory_space if related_object.is_a?(Decidim::Participable)
36
+
35
37
  false
36
38
  end
37
39
 
@@ -15,6 +15,7 @@ module Decidim
15
15
  query.each do |key, results|
16
16
  cumulative_value = results[:cumulative]
17
17
  next if cumulative_value.zero?
18
+
18
19
  quantity_value = results[:quantity] || 0
19
20
  space_type, space_id, category_id, related_object_type, related_object_id = key
20
21
  record = Decidim::Metric.find_or_initialize_by(day: @day.to_s, metric_type: @metric_name,
@@ -44,6 +45,8 @@ module Decidim
44
45
  next grouped_comments unless related_object
45
46
 
46
47
  group_key = generate_group_key(related_object)
48
+ next grouped_comments unless group_key
49
+
47
50
  grouped_comments[group_key] ||= { cumulative: 0, quantity: 0 }
48
51
  grouped_comments[group_key][:cumulative] += 1
49
52
  grouped_comments[group_key][:quantity] += 1 if comment.created_at >= start_time
@@ -70,6 +73,8 @@ module Decidim
70
73
  # Generates a group key from the related object of a Comment
71
74
  def generate_group_key(related_object)
72
75
  participatory_space = retrieve_participatory_space(related_object)
76
+ return unless participatory_space
77
+
73
78
  category_id = related_object.respond_to?(:category) ? related_object.category.try(:id) : ""
74
79
  group_key = []
75
80
  group_key += [participatory_space.class.name, participatory_space.id]
@@ -20,6 +20,7 @@ class UpdateRootCommentableForComments < ActiveRecord::Migration[5.0]
20
20
 
21
21
  def root_commentable(comment)
22
22
  return comment.commentable if comment.depth.zero?
23
+
23
24
  root_commentable comment.commentable
24
25
  end
25
26
  end
@@ -9,6 +9,7 @@ module Decidim
9
9
  # resource - A commentable resource
10
10
  def comments_for(resource)
11
11
  return unless resource.commentable?
12
+
12
13
  content_for :expanded do
13
14
  inline_comments_for(resource)
14
15
  end
@@ -21,6 +22,7 @@ module Decidim
21
22
  # Returns a div which contain a RectComponent
22
23
  def inline_comments_for(resource)
23
24
  return unless resource.commentable?
25
+
24
26
  commentable_type = resource.commentable_type
25
27
  commentable_id = resource.id.to_s
26
28
  node_id = "comments-for-#{commentable_type.demodulize}-#{commentable_id}"
@@ -1,3 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "decidim/comments/test/shared_examples/create_comment_context"
4
+ require "decidim/comments/test/shared_examples/comment_event"
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ shared_context "when it's a comment event" do
6
+ include Decidim::ComponentPathHelper
7
+ include Decidim::SanitizeHelper
8
+
9
+ include_context "when a simple event"
10
+
11
+ let(:resource) { comment.commentable }
12
+
13
+ let(:comment) { create :comment }
14
+ let(:comment_author) { comment.author }
15
+ let(:comment_author_name) { decidim_html_escape comment.author.name }
16
+
17
+ let(:extra) { { comment_id: comment.id } }
18
+ let(:resource_title) { decidim_html_escape resource.title }
19
+ end
20
+
21
+ shared_examples_for "a comment event" do
22
+ it_behaves_like "a simple event"
23
+
24
+ describe "author" do
25
+ it "returns the comment author" do
26
+ expect(subject.author).to eq(comment_author)
27
+ end
28
+ end
29
+
30
+ describe "resource_text" do
31
+ it "outputs the comment body" do
32
+ expect(subject.resource_text).to eq comment.formatted_body
33
+ end
34
+ end
35
+ 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.18.1"
7
+ "0.19.0"
8
8
  end
9
9
  end
10
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decidim-comments
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.1
4
+ version: 0.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josep Jaume Rey Peroy
@@ -18,56 +18,56 @@ dependencies:
18
18
  requirements:
19
19
  - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: 0.18.1
21
+ version: 0.19.0
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.18.1
28
+ version: 0.19.0
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: jquery-rails
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
33
  - - "~>"
34
34
  - !ruby/object:Gem::Version
35
- version: '4.0'
35
+ version: '4.3'
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - - "~>"
41
41
  - !ruby/object:Gem::Version
42
- version: '4.0'
42
+ version: '4.3'
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: decidim-admin
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - '='
48
48
  - !ruby/object:Gem::Version
49
- version: 0.18.1
49
+ version: 0.19.0
50
50
  type: :development
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - '='
55
55
  - !ruby/object:Gem::Version
56
- version: 0.18.1
56
+ version: 0.19.0
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: decidim-dev
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
61
  - - '='
62
62
  - !ruby/object:Gem::Version
63
- version: 0.18.1
63
+ version: 0.19.0
64
64
  type: :development
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
68
  - - '='
69
69
  - !ruby/object:Gem::Version
70
- version: 0.18.1
70
+ version: 0.19.0
71
71
  description: Pluggable comments system for some components.
72
72
  email:
73
73
  - josepjaume@gmail.com
@@ -88,6 +88,7 @@ files:
88
88
  - app/commands/decidim/comments/vote_comment.rb
89
89
  - app/events/decidim/comments/comment_by_followed_user_event.rb
90
90
  - app/events/decidim/comments/comment_created_event.rb
91
+ - app/events/decidim/comments/comment_event.rb
91
92
  - app/events/decidim/comments/reply_created_event.rb
92
93
  - app/events/decidim/comments/user_mentioned_event.rb
93
94
  - app/forms/decidim/comments/comment_form.rb
@@ -204,6 +205,7 @@ files:
204
205
  - lib/decidim/comments/query_extensions.rb
205
206
  - lib/decidim/comments/test.rb
206
207
  - lib/decidim/comments/test/factories.rb
208
+ - lib/decidim/comments/test/shared_examples/comment_event.rb
207
209
  - lib/decidim/comments/test/shared_examples/create_comment_context.rb
208
210
  - lib/decidim/comments/version.rb
209
211
  homepage: https://github.com/decidim/decidim