commontator 4.11.1 → 5.0.0
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/README.md +6 -5
- data/app/controllers/commontator/application_controller.rb +4 -4
- data/app/controllers/commontator/comments_controller.rb +15 -15
- data/app/controllers/commontator/subscriptions_controller.rb +1 -1
- data/app/controllers/commontator/threads_controller.rb +5 -5
- data/app/mailers/commontator/subscriptions_mailer.rb +25 -37
- data/app/models/commontator/comment.rb +11 -11
- data/app/models/commontator/subscription.rb +2 -2
- data/app/models/commontator/thread.rb +9 -9
- data/app/views/commontator/comments/_actions.html.erb +8 -8
- data/app/views/commontator/comments/_body.html.erb +1 -1
- data/app/views/commontator/comments/_form.html.erb +3 -3
- data/app/views/commontator/comments/_list.html.erb +3 -3
- data/app/views/commontator/comments/_show.html.erb +8 -8
- data/app/views/commontator/comments/_votes.html.erb +16 -16
- data/app/views/commontator/comments/cancel.js.erb +5 -5
- data/app/views/commontator/comments/create.js.erb +9 -9
- data/app/views/commontator/comments/delete.js.erb +7 -7
- data/app/views/commontator/comments/edit.js.erb +2 -2
- data/app/views/commontator/comments/new.js.erb +4 -4
- data/app/views/commontator/comments/update.js.erb +1 -1
- data/app/views/commontator/comments/vote.js.erb +3 -3
- data/app/views/commontator/shared/_thread.html.erb +6 -6
- data/app/views/commontator/subscriptions/_link.html.erb +5 -5
- data/app/views/commontator/subscriptions/subscribe.js.erb +3 -3
- data/app/views/commontator/subscriptions_mailer/comment_created.html.erb +6 -6
- data/app/views/commontator/threads/_reply.html.erb +6 -6
- data/app/views/commontator/threads/_show.html.erb +33 -33
- data/app/views/commontator/threads/_show.js.erb +7 -7
- data/app/views/commontator/threads/show.js.erb +6 -6
- data/config/initializers/commontator.rb +43 -38
- data/config/locales/de.yml +100 -0
- data/config/locales/en.yml +26 -27
- data/config/locales/pt-BR.yml +78 -0
- data/config/locales/ru.yml +25 -26
- data/config/locales/zh.yml +26 -27
- data/config/routes.rb +4 -4
- data/db/migrate/0_install_commontator.rb +17 -17
- data/lib/commontator.rb +2 -2
- data/lib/commontator/acts_as_commontable.rb +14 -12
- data/lib/commontator/acts_as_commontator.rb +5 -5
- data/lib/commontator/shared_helper.rb +6 -6
- data/lib/commontator/version.rb +1 -1
- data/lib/tasks/commontator_tasks.rake +2 -2
- data/spec/controllers/commontator/comments_controller_spec.rb +76 -75
- data/spec/controllers/commontator/subscriptions_controller_spec.rb +26 -27
- data/spec/controllers/commontator/threads_controller_spec.rb +42 -41
- data/spec/dummy/app/controllers/dummy_models_controller.rb +1 -1
- data/spec/dummy/app/views/layouts/application.html.erb +1 -2
- data/spec/dummy/config/application.rb +1 -1
- data/spec/dummy/config/environments/development.rb +1 -2
- data/spec/dummy/config/environments/production.rb +1 -2
- data/spec/dummy/config/environments/test.rb +1 -2
- data/spec/dummy/config/initializers/commontator.rb +7 -7
- data/spec/dummy/config/routes.rb +2 -3
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/1_create_dummy_models.rb +2 -3
- data/spec/dummy/db/migrate/2_create_dummy_users.rb +2 -3
- data/spec/dummy/db/migrate/3_acts_as_votable_migration.rb +4 -10
- data/spec/dummy/db/schema.rb +45 -48
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +413 -0
- data/spec/dummy/log/test.log +33690 -0
- data/spec/lib/commontator/commontable_config_spec.rb +4 -5
- data/spec/lib/commontator/commontator_config_spec.rb +4 -5
- data/spec/lib/commontator_spec.rb +2 -3
- data/spec/mailers/commontator/subscriptions_mailer_spec.rb +2 -3
- data/spec/models/commontator/comment_spec.rb +10 -10
- data/spec/rails_helper.rb +3 -2
- metadata +64 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fcd57c56f76291406b85f24de5a0ad2235c350ca
|
4
|
+
data.tar.gz: 8af611ffdae4c578f9a784b39f10a1d4a9860503
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 328b21764347f350e0bbef130ab82bf5d26bb5866d8e864261e6080fc9a1052368f505d1a5ff2fbd947c5bc9fe123fe95fd7f6d321e9809ad199f21e7d898681
|
7
|
+
data.tar.gz: 9db4ba13a3576b3629239496012bdf92c096aa0f5f6377919a249026da2097ceb9519ac3a55c25990c0539482fc40c0a903ee6d51e3d3a8f47a8e0bd9e9b4db5
|
data/README.md
CHANGED
@@ -132,7 +132,7 @@ That's it! Commontator is now ready for use.
|
|
132
132
|
When you enable subscriptions, emails are sent automatically by Commontator. If sending emails, remember to add your host URL's to your environment files (test.rb, development.rb and production.rb):
|
133
133
|
|
134
134
|
```rb
|
135
|
-
config.action_mailer.default_url_options = { :
|
135
|
+
config.action_mailer.default_url_options = { host: "www.example.com" }
|
136
136
|
```
|
137
137
|
|
138
138
|
Batch sending through Mailgun is also supported and automatically detected.
|
@@ -172,12 +172,13 @@ Then enable mentions in commontator's initializer:
|
|
172
172
|
config.mentions_enabled = true
|
173
173
|
```
|
174
174
|
|
175
|
-
Finally configure the user_mentions_proc, which receives the current user
|
176
|
-
and the search query inputted by that user and should
|
177
|
-
containing the users that can be mentioned and match the
|
175
|
+
Finally configure the user_mentions_proc, which receives the current user,
|
176
|
+
the current thread, and the search query inputted by that user and should
|
177
|
+
return a relation containing the users that can be mentioned and match the
|
178
|
+
query string:
|
178
179
|
|
179
180
|
```rb
|
180
|
-
config.user_mentions_proc =
|
181
|
+
config.user_mentions_proc = ->(current_user, thread, query) { ... }
|
181
182
|
```
|
182
183
|
|
183
184
|
Please be aware that with mentions enabled, any registered user
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module Commontator
|
2
2
|
class ApplicationController < ActionController::Base
|
3
|
-
|
4
|
-
|
5
|
-
rescue_from SecurityTransgression, :
|
6
|
-
|
3
|
+
before_action :set_user, :ensure_user
|
4
|
+
|
5
|
+
rescue_from SecurityTransgression, with: -> { head(:forbidden) }
|
6
|
+
|
7
7
|
protected
|
8
8
|
|
9
9
|
def security_transgression_unless(check)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Commontator
|
2
2
|
class CommentsController < Commontator::ApplicationController
|
3
|
-
|
4
|
-
|
3
|
+
before_action :set_thread, only: [:new, :create]
|
4
|
+
before_action :set_comment_and_thread, except: [:new, :create]
|
5
5
|
|
6
6
|
# GET /threads/1/comments/new
|
7
7
|
def new
|
@@ -16,7 +16,7 @@ module Commontator
|
|
16
16
|
format.html { redirect_to @thread }
|
17
17
|
format.js
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
end
|
21
21
|
|
22
22
|
# POST /threads/1/comments
|
@@ -27,7 +27,7 @@ module Commontator
|
|
27
27
|
@comment.body = params[:comment].nil? ? nil : params[:comment][:body]
|
28
28
|
security_transgression_unless @comment.can_be_created_by?(@user)
|
29
29
|
subscribe_mentioned if Commontator.mentions_enabled
|
30
|
-
|
30
|
+
|
31
31
|
respond_to do |format|
|
32
32
|
if !params[:cancel].nil?
|
33
33
|
format.html { redirect_to @thread }
|
@@ -91,7 +91,7 @@ module Commontator
|
|
91
91
|
format.js { render :delete }
|
92
92
|
end
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
# PUT /comments/1/undelete
|
96
96
|
def undelete
|
97
97
|
security_transgression_unless @comment.can_be_deleted_by?(@user)
|
@@ -104,11 +104,11 @@ module Commontator
|
|
104
104
|
format.js { render :delete }
|
105
105
|
end
|
106
106
|
end
|
107
|
-
|
107
|
+
|
108
108
|
# PUT /comments/1/upvote
|
109
109
|
def upvote
|
110
110
|
security_transgression_unless @comment.can_be_voted_on_by?(@user)
|
111
|
-
|
111
|
+
|
112
112
|
@comment.upvote_from @user
|
113
113
|
|
114
114
|
respond_to do |format|
|
@@ -116,12 +116,12 @@ module Commontator
|
|
116
116
|
format.js { render :vote }
|
117
117
|
end
|
118
118
|
end
|
119
|
-
|
119
|
+
|
120
120
|
# PUT /comments/1/downvote
|
121
121
|
def downvote
|
122
122
|
security_transgression_unless @comment.can_be_voted_on_by?(@user) &&\
|
123
123
|
@comment.thread.config.comment_voting.to_sym == :ld
|
124
|
-
|
124
|
+
|
125
125
|
@comment.downvote_from @user
|
126
126
|
|
127
127
|
respond_to do |format|
|
@@ -129,21 +129,21 @@ module Commontator
|
|
129
129
|
format.js { render :vote }
|
130
130
|
end
|
131
131
|
end
|
132
|
-
|
132
|
+
|
133
133
|
# PUT /comments/1/unvote
|
134
134
|
def unvote
|
135
135
|
security_transgression_unless @comment.can_be_voted_on_by?(@user)
|
136
|
-
|
137
|
-
@comment.unvote :
|
136
|
+
|
137
|
+
@comment.unvote voter: @user
|
138
138
|
|
139
139
|
respond_to do |format|
|
140
140
|
format.html { redirect_to @thread }
|
141
141
|
format.js { render :vote }
|
142
142
|
end
|
143
143
|
end
|
144
|
-
|
144
|
+
|
145
145
|
protected
|
146
|
-
|
146
|
+
|
147
147
|
def set_comment_and_thread
|
148
148
|
@comment = Comment.find(params[:id])
|
149
149
|
@thread = @comment.thread
|
@@ -151,7 +151,7 @@ module Commontator
|
|
151
151
|
end
|
152
152
|
|
153
153
|
def subscribe_mentioned
|
154
|
-
Commontator.commontator_mentions(@user, '').where(id: params[:mentioned_ids]).each do |user|
|
154
|
+
Commontator.commontator_mentions(@user, @thread, '').where(id: params[:mentioned_ids]).each do |user|
|
155
155
|
@thread.subscribe(user)
|
156
156
|
end
|
157
157
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Commontator
|
2
2
|
class ThreadsController < Commontator::ApplicationController
|
3
|
-
|
4
|
-
|
3
|
+
skip_before_action :ensure_user, only: :show
|
4
|
+
before_action :set_thread
|
5
5
|
|
6
6
|
# GET /threads/1
|
7
7
|
def show
|
@@ -13,7 +13,7 @@ module Commontator
|
|
13
13
|
format.js
|
14
14
|
end
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
# PUT /threads/1/close
|
18
18
|
def close
|
19
19
|
security_transgression_unless @thread.can_be_edited_by?(@user)
|
@@ -28,7 +28,7 @@ module Commontator
|
|
28
28
|
format.js { render :show }
|
29
29
|
end
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
# PUT /threads/1/reopen
|
33
33
|
def reopen
|
34
34
|
security_transgression_unless @thread.can_be_edited_by?(@user)
|
@@ -60,7 +60,7 @@ module Commontator
|
|
60
60
|
protected
|
61
61
|
|
62
62
|
def serialized_mentions(query)
|
63
|
-
{ mentions: Commontator.commontator_mentions(@user, query).map do |user|
|
63
|
+
{ mentions: Commontator.commontator_mentions(@user, @thread, query).map do |user|
|
64
64
|
{ id: user.id, name: Commontator.commontator_name(user), type: 'user' }
|
65
65
|
end }
|
66
66
|
end
|
@@ -2,15 +2,10 @@ module Commontator
|
|
2
2
|
class SubscriptionsMailer < ActionMailer::Base
|
3
3
|
def comment_created(comment, recipients)
|
4
4
|
setup_variables(comment, recipients)
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
:creator_name => @creator_name,
|
10
|
-
:commontable_name => @commontable_name,
|
11
|
-
:comment_url => @comment_url)
|
12
|
-
|
13
|
-
message.mailgun_recipient_variables = mailgun_recipient_variables(recipients) if uses_mailgun?
|
5
|
+
|
6
|
+
mail(@mail_params).tap do |message|
|
7
|
+
message.mailgun_recipient_variables = @mailgun_recipient_variables if @using_mailgun
|
8
|
+
end
|
14
9
|
end
|
15
10
|
|
16
11
|
protected
|
@@ -20,42 +15,35 @@ module Commontator
|
|
20
15
|
@thread = @comment.thread
|
21
16
|
@creator = @comment.creator
|
22
17
|
|
23
|
-
@
|
24
|
-
|
25
|
-
@commontable_name = Commontator.commontable_name(@thread)
|
18
|
+
@mail_params = { from: @thread.config.email_from_proc.call(@thread) }
|
26
19
|
|
27
|
-
@
|
20
|
+
@recipient_emails = recipients.map do |recipient|
|
21
|
+
Commontator.commontator_email(recipient, self)
|
22
|
+
end
|
28
23
|
|
29
|
-
|
30
|
-
params[:comment] = @comment
|
31
|
-
params[:thread] = @thread
|
32
|
-
params[:creator] = @creator
|
33
|
-
params[:creator_name] = @creator_name
|
34
|
-
params[:commontable_name] = @commontable_name
|
35
|
-
params[:comment_url] = @comment_url
|
24
|
+
@using_mailgun = Rails.application.config.action_mailer.delivery_method == :mailgun
|
36
25
|
|
37
|
-
if
|
38
|
-
@
|
26
|
+
if @using_mailgun
|
27
|
+
@recipients_header = :to
|
28
|
+
@mailgun_recipient_variables = {}.tap do |mailgun_recipient_variables|
|
29
|
+
@recipient_emails.each { |email| mailgun_recipient_variables[email] = {} }
|
30
|
+
end
|
39
31
|
else
|
40
|
-
@
|
41
|
-
@bcc = recipient_emails(recipients)
|
32
|
+
@recipients_header = :bcc
|
42
33
|
end
|
43
34
|
|
44
|
-
@
|
45
|
-
end
|
35
|
+
@mail_params[@recipients_header] = @recipient_emails
|
46
36
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
def mailgun_recipient_variables(recipients)
|
52
|
-
recipient_emails(recipients).each_with_object({}) do |user_email, memo|
|
53
|
-
memo[user_email] = {}
|
54
|
-
end
|
55
|
-
end
|
37
|
+
@creator_name = Commontator.commontator_name(@creator)
|
38
|
+
@commontable_name = Commontator.commontable_name(@thread)
|
39
|
+
@comment_url = Commontator.comment_url(@comment, main_app)
|
56
40
|
|
57
|
-
|
58
|
-
|
41
|
+
@mail_params[:subject] = t(
|
42
|
+
'commontator.email.comment_created.subject',
|
43
|
+
creator_name: @creator_name,
|
44
|
+
commontable_name: @commontable_name,
|
45
|
+
comment_url: @comment_url
|
46
|
+
)
|
59
47
|
end
|
60
48
|
end
|
61
49
|
end
|
@@ -1,17 +1,17 @@
|
|
1
1
|
module Commontator
|
2
2
|
class Comment < ActiveRecord::Base
|
3
|
-
belongs_to :creator, :
|
4
|
-
belongs_to :editor, :
|
3
|
+
belongs_to :creator, polymorphic: true
|
4
|
+
belongs_to :editor, polymorphic: true, optional: true
|
5
5
|
belongs_to :thread
|
6
6
|
|
7
|
-
validates_presence_of :creator, :
|
8
|
-
validates_presence_of :editor, :
|
7
|
+
validates_presence_of :creator, on: :create
|
8
|
+
validates_presence_of :editor, on: :update
|
9
9
|
validates_presence_of :thread
|
10
10
|
validates_presence_of :body
|
11
11
|
|
12
12
|
validates_uniqueness_of :body,
|
13
|
-
:
|
14
|
-
:
|
13
|
+
scope: [:creator_type, :creator_id, :thread_id, :deleted_at],
|
14
|
+
message: I18n.t('commontator.comment.errors.double_posted')
|
15
15
|
|
16
16
|
protected
|
17
17
|
|
@@ -36,7 +36,7 @@ module Commontator
|
|
36
36
|
|
37
37
|
def get_vote_by(user)
|
38
38
|
return nil unless is_votable? && !user.nil? && user.is_commontator
|
39
|
-
votes_for.where(:
|
39
|
+
votes_for.where(voter_type: user.class.name, voter_id: user.id).first
|
40
40
|
end
|
41
41
|
|
42
42
|
def update_cached_votes(vote_scope = nil)
|
@@ -64,13 +64,13 @@ module Commontator
|
|
64
64
|
|
65
65
|
def created_timestamp
|
66
66
|
I18n.t 'commontator.comment.status.created_at',
|
67
|
-
:
|
67
|
+
created_at: I18n.l(created_at, format: :commontator)
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
def updated_timestamp
|
71
71
|
I18n.t 'commontator.comment.status.updated_at',
|
72
|
-
:
|
73
|
-
:
|
72
|
+
editor_name: Commontator.commontator_name(editor || creator),
|
73
|
+
updated_at: I18n.l(updated_at, format: :commontator)
|
74
74
|
end
|
75
75
|
|
76
76
|
##################
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module Commontator
|
2
2
|
class Subscription < ActiveRecord::Base
|
3
|
-
belongs_to :subscriber, :
|
3
|
+
belongs_to :subscriber, polymorphic: true
|
4
4
|
belongs_to :thread
|
5
5
|
|
6
6
|
validates_presence_of :subscriber, :thread
|
7
|
-
validates_uniqueness_of :thread_id, :
|
7
|
+
validates_uniqueness_of :thread_id, scope: [:subscriber_type, :subscriber_id]
|
8
8
|
|
9
9
|
def self.comment_created(comment)
|
10
10
|
recipients = comment.thread.subscribers.reject{|s| s == comment.creator}
|
@@ -1,15 +1,15 @@
|
|
1
1
|
module Commontator
|
2
2
|
class Thread < ActiveRecord::Base
|
3
|
-
belongs_to :closer, :
|
4
|
-
belongs_to :commontable, :
|
3
|
+
belongs_to :closer, polymorphic: true, optional: true
|
4
|
+
belongs_to :commontable, polymorphic: true, optional: true
|
5
5
|
|
6
|
-
has_many :comments, :
|
7
|
-
has_many :subscriptions, :
|
6
|
+
has_many :comments, dependent: :destroy
|
7
|
+
has_many :subscriptions, dependent: :destroy
|
8
8
|
|
9
|
-
validates_presence_of :commontable, :
|
9
|
+
validates_presence_of :commontable, unless: :is_closed?
|
10
10
|
validates_uniqueness_of :commontable_id,
|
11
|
-
:
|
12
|
-
:
|
11
|
+
scope: :commontable_type,
|
12
|
+
allow_nil: true
|
13
13
|
|
14
14
|
def config
|
15
15
|
@config ||= commontable.try(:commontable_config) || Commontator
|
@@ -45,7 +45,7 @@ module Commontator
|
|
45
45
|
def paginated_comments(page = 1, per_page = config.comments_per_page)
|
46
46
|
oc = ordered_comments
|
47
47
|
return oc unless will_paginate?
|
48
|
-
oc.paginate(:
|
48
|
+
oc.paginate(page: page, per_page: per_page)
|
49
49
|
end
|
50
50
|
|
51
51
|
def new_comment_page(per_page = config.comments_per_page)
|
@@ -91,7 +91,7 @@ module Commontator
|
|
91
91
|
|
92
92
|
def subscription_for(subscriber)
|
93
93
|
return nil if !subscriber || !subscriber.is_commontator
|
94
|
-
subscriber.subscriptions.where(:
|
94
|
+
subscriber.subscriptions.where(thread_id: self.id).first
|
95
95
|
end
|
96
96
|
|
97
97
|
def subscribe(subscriber)
|
@@ -9,9 +9,9 @@
|
|
9
9
|
<% if can_edit %>
|
10
10
|
<%= link_to t('commontator.comment.actions.edit'),
|
11
11
|
commontator.edit_comment_path(comment),
|
12
|
-
:
|
13
|
-
:
|
14
|
-
:
|
12
|
+
id: "comment_#{comment.id.to_s}_edit_link",
|
13
|
+
class: "comment_edit_link",
|
14
|
+
remote: true %>
|
15
15
|
<% end %>
|
16
16
|
|
17
17
|
|
@@ -21,9 +21,9 @@
|
|
21
21
|
<% del_string = is_deleted ? 'undelete' : 'delete' %>
|
22
22
|
<%= link_to t("commontator.comment.actions.#{del_string}"),
|
23
23
|
commontator.polymorphic_path([del_string, comment]),
|
24
|
-
:
|
25
|
-
:
|
26
|
-
:
|
27
|
-
:
|
28
|
-
:
|
24
|
+
confirm: (!is_deleted ? t('commontator.comment.actions.confirm_delete') : nil),
|
25
|
+
method: :put,
|
26
|
+
id: "comment_#{comment.id.to_s}_#{del_string}_link",
|
27
|
+
class: "comment_#{del_string}_link",
|
28
|
+
remote: true %>
|
29
29
|
<% end %>
|
@@ -22,18 +22,18 @@
|
|
22
22
|
<% end %>
|
23
23
|
|
24
24
|
<%= form_for([commontator, thread, comment],
|
25
|
-
:
|
25
|
+
remote: !no_remote) do |f| %>
|
26
26
|
|
27
27
|
<%= hidden_field_tag :per_page, per_page %>
|
28
28
|
|
29
29
|
<div class="comment_form_field">
|
30
|
-
<%= f.text_area :body, :
|
30
|
+
<%= f.text_area :body, rows: '7' %>
|
31
31
|
<%= javascript_tag('Commontator.initMentions()') if Commontator.mentions_enabled %>
|
32
32
|
</div>
|
33
33
|
|
34
34
|
<div class="comment_form_actions">
|
35
35
|
<%= f.submit t("commontator.comment.actions.#{comment.id.blank? ? 'create' : 'update'}") %>
|
36
|
-
<%= f.submit t('commontator.comment.actions.cancel'), :
|
36
|
+
<%= f.submit t('commontator.comment.actions.cancel'), name: 'cancel' %>
|
37
37
|
</div>
|
38
38
|
|
39
39
|
<% end %>
|