commontator 4.3.0 → 4.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -11
- data/app/assets/stylesheets/commontator/comments.css +24 -3
- data/app/controllers/commontator/application_controller.rb +8 -3
- data/app/controllers/commontator/comments_controller.rb +13 -11
- data/app/controllers/commontator/subscriptions_controller.rb +2 -2
- data/app/controllers/commontator/threads_controller.rb +2 -2
- data/app/mailers/commontator/subscriptions_mailer.rb +5 -8
- data/app/models/commontator/comment.rb +37 -19
- data/app/models/commontator/thread.rb +18 -20
- data/app/views/commontator/comments/_body.html.erb +1 -1
- data/app/views/commontator/comments/_show.html.erb +10 -9
- data/app/views/commontator/comments/_votes.html.erb +11 -6
- data/app/views/commontator/comments/delete.js.erb +1 -1
- data/app/views/commontator/comments/update.js.erb +1 -1
- data/app/views/commontator/subscriptions_mailer/comment_created.html.erb +2 -2
- data/app/views/commontator/threads/_show.html.erb +3 -2
- data/config/initializers/commontator.rb +117 -96
- data/config/locales/{en.yml → commontator/en.yml} +15 -14
- data/lib/commontator.rb +61 -17
- data/lib/commontator/acts_as_commontable.rb +4 -0
- data/lib/commontator/acts_as_commontator.rb +16 -0
- data/lib/commontator/engine.rb +3 -0
- data/lib/commontator/shared_helper.rb +7 -19
- data/lib/commontator/version.rb +1 -1
- data/lib/tasks/commontator_tasks.rake +5 -2
- data/spec/app/mailers/commontator/subscriptions_mailer_spec.rb +2 -2
- data/spec/app/models/commontator/comment_spec.rb +19 -0
- data/spec/dummy/config/application.rb +1 -0
- data/spec/dummy/config/initializers/commontator.rb +3 -5
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/test.log +120400 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/72b63dddbc5c995f79af8e3c94904fd9 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/a77b1a9223d168112e1705c29220116f +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/d2244ccef8e05bb993f75715af0344cc +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/decb63cac838a5314aa0c22a979f5ac9 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/f721383d531f067d82b071e14aed7a92 +0 -0
- data/spec/lib/commontator/acts_as_commontable_spec.rb +1 -0
- data/spec/lib/commontator/acts_as_commontator_spec.rb +4 -0
- data/spec/lib/commontator/commontator_config_spec.rb +6 -4
- data/spec/test_helper.rb +0 -6
- metadata +3 -9
- data/app/helpers/commontator/comments_helper.rb +0 -17
- data/app/helpers/commontator/threads_helper.rb +0 -7
- data/spec/app/helpers/commontator/comments_helper_spec.rb +0 -29
- data/spec/app/helpers/commontator/threads_helper_spec.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95f7d24f572a92460e3feb574f48e3abfe55cf51
|
4
|
+
data.tar.gz: 80d83a831ca9d26f9aaec72e98611aa10e1c2778
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3cef85703c6ea3fe65f317e96404be9f6e55cfcdb7e27d4dec3b3da7aaceafe3bf504ccffe14b959ef5516d09a07669efcb948cd9f18ea9e8d188ec6ad533f3
|
7
|
+
data.tar.gz: 66e364a7b162b8223bea6a9ac97b08beb6977ed902a481ac50d1da490dcc127fc874a58ced12becd58c1a6534ab927d637ea1390ffe4ae78634a6e28a759b0cf
|
data/README.md
CHANGED
@@ -14,7 +14,7 @@ There are 4 steps you must follow to install commontator:
|
|
14
14
|
Add this line to your application's Gemfile:
|
15
15
|
|
16
16
|
```ruby
|
17
|
-
gem 'commontator', '~> 4.
|
17
|
+
gem 'commontator', '~> 4.4.1'
|
18
18
|
```
|
19
19
|
|
20
20
|
And then execute:
|
@@ -55,7 +55,8 @@ There are 4 steps you must follow to install commontator:
|
|
55
55
|
|
56
56
|
3. Configuration
|
57
57
|
|
58
|
-
Change commontator's configurations to suit your needs by editing config/
|
58
|
+
Change commontator's configurations to suit your needs by editing `config/initializers/commontator.rb`.
|
59
|
+
Make sure to check that your configuration file is up to date every time you update the gem, as available options can change with each minor version.
|
59
60
|
|
60
61
|
4. Routes
|
61
62
|
|
@@ -97,14 +98,13 @@ Follow the steps below to add commontator to your models and views:
|
|
97
98
|
|
98
99
|
This will create a link in the view that the user will be able to click to display the comment thread.
|
99
100
|
|
100
|
-
Note that model's record must already exist in the database, so do not use this in new.html.erb
|
101
|
-
We recommend you use this in the model's show.html.erb.
|
101
|
+
Note that model's record must already exist in the database, so do not use this in `new.html.erb`, `_form.html.erb` or similar.
|
102
|
+
We recommend you use this in the model's `show.html.erb` or similar.
|
102
103
|
|
103
104
|
3. Controllers
|
104
105
|
|
105
106
|
By default, the `commontator_thread` method only links to the desired comment thread.
|
106
|
-
If you want, instead, to have the thread display right away when the corresponding view page is loaded,
|
107
|
-
just add the following method call to the controller action that displays the view in question:
|
107
|
+
If you want, instead, to have the thread display right away when the corresponding view page is loaded, just add the following method call to the controller action that displays the view in question:
|
108
108
|
|
109
109
|
```ruby
|
110
110
|
commontator_thread_show(commontable)
|
@@ -112,15 +112,14 @@ Follow the steps below to add commontator to your models and views:
|
|
112
112
|
|
113
113
|
Note that the call to `commontator_thread` in the view is still necessary in either case.
|
114
114
|
|
115
|
-
The `commontator_thread_show` method checks the current user's read permission on the thread and will raise an
|
116
|
-
exception if the user is not allowed to read it according to the configuration options in the initializer.
|
115
|
+
The `commontator_thread_show` method checks the current user's read permission on the thread and will raise an exception if the user is not allowed to read it according to the configuration options in the initializer.
|
117
116
|
It is up to you to ensure that this method is only called if the user is authorized to read the thread.
|
118
117
|
|
119
118
|
That's it! Commontator is now ready for use.
|
120
119
|
|
121
120
|
## Voting
|
122
121
|
|
123
|
-
You can allow users to vote on each others' comments by adding the acts_as_votable gem to your gemfile:
|
122
|
+
You can allow users to vote on each others' comments by adding the `acts_as_votable` gem to your gemfile:
|
124
123
|
|
125
124
|
```ruby
|
126
125
|
gem 'acts_as_votable'
|
@@ -132,8 +131,8 @@ And enabling the relevant option in commontator's initializer:
|
|
132
131
|
config.can_vote_on_comments = true
|
133
132
|
```
|
134
133
|
|
135
|
-
Note that acts_as_votable is currently incompatible with the protected_attributes
|
136
|
-
gem if config.active_record.whitelist_attributes is
|
134
|
+
Note that `acts_as_votable` is currently incompatible with the `protected_attributes`
|
135
|
+
gem if `config.active_record.whitelist_attributes` is true.
|
137
136
|
|
138
137
|
## Browser Support
|
139
138
|
|
@@ -145,6 +144,8 @@ To function properly, this gem requires that visitors to the site have javascrip
|
|
145
144
|
Copy commontator's files to your app using any of the following commands:
|
146
145
|
|
147
146
|
```sh
|
147
|
+
$ rake commontator:copy:locales
|
148
|
+
|
148
149
|
$ rake commontator:copy:images
|
149
150
|
$ rake commontator:copy:stylesheets
|
150
151
|
|
@@ -158,6 +159,12 @@ $ rake commontator:copy:models
|
|
158
159
|
|
159
160
|
You are now free to modify them and have any changes made manifest in your application.
|
160
161
|
|
162
|
+
If copying commontator's locales, please note that by default Rails will not autoload locales in subfolders of `config/locales` (like ours) unless you add the following to your application's configuration file:
|
163
|
+
|
164
|
+
```rb
|
165
|
+
config.i18n.load_path += Dir[root.join('config', 'locales', '**', '*.{rb,yml}')]
|
166
|
+
```
|
167
|
+
|
161
168
|
## Contributing
|
162
169
|
|
163
170
|
1. Fork it
|
@@ -64,7 +64,9 @@
|
|
64
64
|
|
65
65
|
.comment_votes {
|
66
66
|
float: right;
|
67
|
-
|
67
|
+
margin-top: 5px;
|
68
|
+
margin-bottom: 5px;
|
69
|
+
|
68
70
|
text-align: center;
|
69
71
|
}
|
70
72
|
|
@@ -80,8 +82,27 @@
|
|
80
82
|
margin: 0px;
|
81
83
|
}
|
82
84
|
|
83
|
-
.comment_vote_count
|
84
|
-
margin:
|
85
|
+
.comment_vote_count {
|
86
|
+
margin-top: 7px;
|
87
|
+
margin-bottom: 7px;
|
88
|
+
}
|
89
|
+
|
90
|
+
.comment_upvote {
|
91
|
+
display: block;
|
92
|
+
height: 32px;
|
93
|
+
}
|
94
|
+
|
95
|
+
.comment_downvote {
|
96
|
+
display: block;
|
97
|
+
height: 32px;
|
98
|
+
}
|
99
|
+
|
100
|
+
.comment_like {
|
101
|
+
float: left;
|
102
|
+
}
|
103
|
+
|
104
|
+
.comment_like + .comment_vote_count {
|
105
|
+
float: right;
|
85
106
|
}
|
86
107
|
|
87
108
|
.comment_error_explanation {
|
@@ -13,18 +13,23 @@ module Commontator
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def ensure_user
|
16
|
-
|
16
|
+
security_transgression_unless(@user && @user.is_commontator)
|
17
17
|
end
|
18
18
|
|
19
19
|
def get_thread
|
20
20
|
@thread = params[:thread_id].blank? ? \
|
21
21
|
Commontator::Thread.find(params[:id]) : \
|
22
22
|
Commontator::Thread.find(params[:thread_id])
|
23
|
-
|
23
|
+
security_transgression_unless !@thread.commontable.nil?
|
24
24
|
end
|
25
25
|
|
26
26
|
def set_commontable_url
|
27
|
-
self.commontable_url = @thread.config.commontable_url_proc.call(
|
27
|
+
self.commontable_url = @thread.config.commontable_url_proc.call(
|
28
|
+
@thread.commontable, main_app)
|
29
|
+
end
|
30
|
+
|
31
|
+
def security_transgression_unless(check)
|
32
|
+
raise SecurityTransgression unless check
|
28
33
|
end
|
29
34
|
end
|
30
35
|
end
|
@@ -10,7 +10,7 @@ module Commontator
|
|
10
10
|
@comment.thread = @thread
|
11
11
|
@comment.creator = @user
|
12
12
|
|
13
|
-
|
13
|
+
security_transgression_unless @comment.can_be_created_by?(@user)
|
14
14
|
|
15
15
|
respond_to do |format|
|
16
16
|
format.html { redirect_to @thread }
|
@@ -26,16 +26,17 @@ module Commontator
|
|
26
26
|
@comment.thread = @thread
|
27
27
|
@comment.creator = @user
|
28
28
|
|
29
|
-
|
29
|
+
security_transgression_unless @comment.can_be_created_by?(@user)
|
30
30
|
|
31
31
|
respond_to do |format|
|
32
32
|
if !params[:cancel].nil?
|
33
33
|
format.html { redirect_to @thread }
|
34
34
|
format.js { render :cancel }
|
35
35
|
elsif @comment.save
|
36
|
-
@thread.subscribe(@user) if @thread.config.
|
36
|
+
@thread.subscribe(@user) if @thread.config.thread_subscription == :a ||\
|
37
|
+
@thread.config.thread_subscription == :b
|
37
38
|
@thread.add_unread_except_for(@user)
|
38
|
-
recipients = @thread.
|
39
|
+
recipients = @thread.subscribers.reject{|s| s == @user}
|
39
40
|
SubscriptionsMailer.comment_created(@comment, recipients).deliver \
|
40
41
|
unless recipients.empty?
|
41
42
|
|
@@ -50,7 +51,7 @@ module Commontator
|
|
50
51
|
|
51
52
|
# GET /comments/1/edit
|
52
53
|
def edit
|
53
|
-
|
54
|
+
security_transgression_unless @comment.can_be_edited_by?(@user)
|
54
55
|
|
55
56
|
respond_to do |format|
|
56
57
|
format.html { redirect_to @thread }
|
@@ -60,7 +61,7 @@ module Commontator
|
|
60
61
|
|
61
62
|
# PUT /comments/1
|
62
63
|
def update
|
63
|
-
|
64
|
+
security_transgression_unless @comment.can_be_edited_by?(@user)
|
64
65
|
@comment.body = params[:comment].nil? ? nil : params[:comment][:body]
|
65
66
|
@comment.editor = @user
|
66
67
|
|
@@ -80,7 +81,7 @@ module Commontator
|
|
80
81
|
|
81
82
|
# PUT /comments/1/delete
|
82
83
|
def delete
|
83
|
-
|
84
|
+
security_transgression_unless @comment.can_be_deleted_by?(@user)
|
84
85
|
|
85
86
|
@comment.errors.add(:base, t('commontator.comment.errors.already_deleted')) \
|
86
87
|
unless @comment.delete_by(@user)
|
@@ -93,7 +94,7 @@ module Commontator
|
|
93
94
|
|
94
95
|
# PUT /comments/1/undelete
|
95
96
|
def undelete
|
96
|
-
|
97
|
+
security_transgression_unless @comment.can_be_deleted_by?(@user)
|
97
98
|
|
98
99
|
@comment.errors.add(:base, t('commontator.comment.errors.not_deleted')) \
|
99
100
|
unless @comment.undelete_by(@user)
|
@@ -106,7 +107,7 @@ module Commontator
|
|
106
107
|
|
107
108
|
# PUT /comments/1/upvote
|
108
109
|
def upvote
|
109
|
-
|
110
|
+
security_transgression_unless @comment.can_be_voted_on_by?(@user)
|
110
111
|
|
111
112
|
@comment.upvote_from @user
|
112
113
|
|
@@ -118,7 +119,8 @@ module Commontator
|
|
118
119
|
|
119
120
|
# PUT /comments/1/downvote
|
120
121
|
def downvote
|
121
|
-
|
122
|
+
security_transgression_unless @comment.can_be_voted_on_by?(@user) &&\
|
123
|
+
@comment.thread.config.comment_voting.to_sym == :ld
|
122
124
|
|
123
125
|
@comment.downvote_from @user
|
124
126
|
|
@@ -130,7 +132,7 @@ module Commontator
|
|
130
132
|
|
131
133
|
# PUT /comments/1/unvote
|
132
134
|
def unvote
|
133
|
-
|
135
|
+
security_transgression_unless @comment.can_be_voted_on_by?(@user)
|
134
136
|
|
135
137
|
@comment.unvote :voter => @user
|
136
138
|
|
@@ -4,7 +4,7 @@ module Commontator
|
|
4
4
|
|
5
5
|
# PUT /threads/1/subscribe
|
6
6
|
def subscribe
|
7
|
-
|
7
|
+
security_transgression_unless @thread.can_subscribe?(@user)
|
8
8
|
|
9
9
|
@thread.errors.add(:base, t('commontator.subscription.errors.already_subscribed')) \
|
10
10
|
unless @thread.subscribe(@user)
|
@@ -18,7 +18,7 @@ module Commontator
|
|
18
18
|
|
19
19
|
# PUT /threads/1/unsubscribe
|
20
20
|
def unsubscribe
|
21
|
-
|
21
|
+
security_transgression_unless @thread.can_subscribe?(@user)
|
22
22
|
|
23
23
|
@thread.errors.add(:base, t('commontator.subscription.errors.not_subscribed')) \
|
24
24
|
unless @thread.unsubscribe(@user)
|
@@ -17,7 +17,7 @@ module Commontator
|
|
17
17
|
|
18
18
|
# PUT /threads/1/close
|
19
19
|
def close
|
20
|
-
|
20
|
+
security_transgression_unless @thread.can_be_edited_by?(@user)
|
21
21
|
|
22
22
|
@thread.errors.add(:base, t('commontator.thread.errors.already_closed')) \
|
23
23
|
unless @thread.close(@user)
|
@@ -30,7 +30,7 @@ module Commontator
|
|
30
30
|
|
31
31
|
# PUT /threads/1/reopen
|
32
32
|
def reopen
|
33
|
-
|
33
|
+
security_transgression_unless @thread.can_be_edited_by?(@user)
|
34
34
|
|
35
35
|
@thread.errors.add(:base, t('commontator.thread.errors.not_closed')) \
|
36
36
|
unless @thread.reopen
|
@@ -1,15 +1,12 @@
|
|
1
1
|
module Commontator
|
2
2
|
class SubscriptionsMailer < ActionMailer::Base
|
3
|
-
include SharedHelper
|
4
|
-
include ThreadsHelper
|
5
|
-
|
6
3
|
def comment_created(comment, recipients)
|
7
4
|
setup_variables(comment, recipients)
|
8
5
|
|
9
6
|
mail :to => @to,
|
10
7
|
:bcc => @bcc,
|
11
8
|
:from => @from,
|
12
|
-
:subject => t('commontator.
|
9
|
+
:subject => t('commontator.email.comment_created.subject',
|
13
10
|
:creator_name => @creator_name,
|
14
11
|
:commontable_name => @commontable_name,
|
15
12
|
:commontable_url => @commontable_url)
|
@@ -25,9 +22,9 @@ module Commontator
|
|
25
22
|
@commontable = @thread.commontable
|
26
23
|
@config = @thread.config
|
27
24
|
|
28
|
-
@creator_name =
|
25
|
+
@creator_name = @creator.commontator_name
|
29
26
|
|
30
|
-
@commontable_name = commontable_name
|
27
|
+
@commontable_name = @commontable.commontable_name
|
31
28
|
|
32
29
|
@commontable_url = ApplicationController.commontable_url
|
33
30
|
|
@@ -41,8 +38,8 @@ module Commontator
|
|
41
38
|
params[:commontable_name] = @commontable_name
|
42
39
|
params[:commontable_url] = @commontable_url
|
43
40
|
|
44
|
-
@to = t('commontator.
|
45
|
-
@bcc = recipients.collect{|s| commontator_email(
|
41
|
+
@to = t('commontator.email.undisclosed_recipients')
|
42
|
+
@bcc = recipients.collect{|s| s.commontator_email(self)}
|
46
43
|
@from = @config.email_from_proc.call(self)
|
47
44
|
end
|
48
45
|
end
|
@@ -11,8 +11,9 @@ module Commontator
|
|
11
11
|
validates_presence_of :thread
|
12
12
|
validates_presence_of :body
|
13
13
|
|
14
|
-
validates_uniqueness_of :body,
|
15
|
-
|
14
|
+
validates_uniqueness_of :body,
|
15
|
+
:scope => [:creator_type, :creator_id, :thread_id],
|
16
|
+
:message => I18n.t('commontator.comment.errors.double_posted')
|
16
17
|
|
17
18
|
protected
|
18
19
|
|
@@ -58,43 +59,60 @@ module Commontator
|
|
58
59
|
self.save
|
59
60
|
end
|
60
61
|
|
62
|
+
def created_timestamp
|
63
|
+
I18n.t 'commontator.comment.status.created_at',
|
64
|
+
:created_at => I18n.l(created_at, :format => :commontator)
|
65
|
+
end
|
66
|
+
|
67
|
+
def updated_timestamp
|
68
|
+
return '' if editor.nil?
|
69
|
+
|
70
|
+
I18n.t 'commontator.comment.status.updated_at',
|
71
|
+
:editor_name => editor.commontator_name,
|
72
|
+
:updated_at => I18n.l(updated_at, :format => :commontator)
|
73
|
+
end
|
74
|
+
|
61
75
|
##################
|
62
76
|
# Access Control #
|
63
77
|
##################
|
64
78
|
|
65
79
|
def can_be_read_by?(user)
|
66
|
-
|
67
|
-
|
68
|
-
thread.
|
80
|
+
return true if thread.can_be_edited_by?(user)
|
81
|
+
(!is_deleted? || !thread.config.hide_deleted_comments) &&\
|
82
|
+
thread.can_be_read_by?(user)
|
69
83
|
end
|
70
84
|
|
71
85
|
def can_be_created_by?(user)
|
72
|
-
|
86
|
+
user == creator && user.is_commontator &&\
|
87
|
+
!thread.is_closed? && thread.can_be_read_by?(user)
|
73
88
|
end
|
74
89
|
|
75
90
|
def can_be_edited_by?(user)
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
91
|
+
return true if thread.config.moderators_can_edit_comments &&\
|
92
|
+
thread.can_be_edited_by?(user)
|
93
|
+
comment_edit = thread.config.comment_editing.to_sym
|
94
|
+
!thread.is_closed? && !is_deleted? && user == creator &&\
|
95
|
+
comment_edit != :n && (is_latest? || comment_edit == :a) &&\
|
96
|
+
thread.can_be_read_by?(user)
|
82
97
|
end
|
83
98
|
|
84
99
|
def can_be_deleted_by?(user)
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
100
|
+
return true if thread.can_be_edited_by?(user)
|
101
|
+
comment_del = thread.config.comment_deletion.to_sym
|
102
|
+
!thread.is_closed? && (!is_deleted? || editor == user) &&\
|
103
|
+
user == creator && comment_del != :n &&\
|
104
|
+
(is_latest? || comment_del == :a) &&\
|
105
|
+
thread.can_be_read_by?(user)
|
90
106
|
end
|
91
107
|
|
92
108
|
def can_be_voted_on?
|
93
|
-
!thread.is_closed? &&
|
109
|
+
!thread.is_closed? && !is_deleted? &&\
|
110
|
+
thread.config.comment_voting != :n && is_votable?
|
94
111
|
end
|
95
112
|
|
96
113
|
def can_be_voted_on_by?(user)
|
97
|
-
|
114
|
+
!user.nil? && user.is_commontator && user != creator &&\
|
115
|
+
thread.can_be_read_by?(user) && can_be_voted_on?
|
98
116
|
end
|
99
117
|
end
|
100
118
|
end
|
@@ -7,18 +7,20 @@ module Commontator
|
|
7
7
|
has_many :subscriptions, :dependent => :destroy
|
8
8
|
|
9
9
|
validates_presence_of :commontable, :unless => :is_closed?
|
10
|
-
validates_uniqueness_of :commontable_id,
|
10
|
+
validates_uniqueness_of :commontable_id,
|
11
|
+
:scope => :commontable_type,
|
12
|
+
:allow_nil => true
|
11
13
|
|
12
14
|
def config
|
13
15
|
commontable.try(:commontable_config) || Commontator
|
14
16
|
end
|
15
17
|
|
16
18
|
def ordered_comments
|
17
|
-
case config.
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
case config.comment_order.to_sym
|
20
|
+
when :l then comments.order('id DESC')
|
21
|
+
when :ve then comments.order('cached_votes_down - cached_votes_up')
|
22
|
+
when :vl then comments.order('cached_votes_down - cached_votes_up', 'id DESC')
|
23
|
+
else comments
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
@@ -30,10 +32,6 @@ module Commontator
|
|
30
32
|
subscriptions.collect{|s| s.subscriber}
|
31
33
|
end
|
32
34
|
|
33
|
-
def active_subscribers
|
34
|
-
subscribers.select{|s| s.is_commontator && s.commontator_config.user_email_enable_proc.call(s)}
|
35
|
-
end
|
36
|
-
|
37
35
|
def subscription_for(subscriber)
|
38
36
|
return nil if !subscriber || !subscriber.is_commontator
|
39
37
|
subscriber.subscriptions.where(:thread_id => self.id).first
|
@@ -105,24 +103,24 @@ module Commontator
|
|
105
103
|
# Access Control #
|
106
104
|
##################
|
107
105
|
|
108
|
-
# Reader capabilities (user can be nil or false)
|
106
|
+
# Reader capabilities (remember: user can be nil or false)
|
109
107
|
def can_be_read_by?(user)
|
110
|
-
(
|
111
|
-
|
112
|
-
|
113
|
-
can_be_edited_by?(user)
|
108
|
+
return true if can_be_edited_by?(user)
|
109
|
+
!commontable.nil? && (!is_closed? || !config.hide_closed_threads) &&\
|
110
|
+
config.thread_read_proc.call(self, user)
|
114
111
|
end
|
115
112
|
|
116
113
|
# Thread moderator capabilities
|
117
114
|
def can_be_edited_by?(user)
|
118
|
-
!commontable.nil? && user && user.is_commontator &&\
|
119
|
-
|
120
|
-
config.can_edit_thread_proc.call(self, user))
|
115
|
+
!commontable.nil? && !user.nil? && user.is_commontator &&\
|
116
|
+
config.thread_moderator_proc.call(self, user)
|
121
117
|
end
|
122
118
|
|
123
119
|
def can_subscribe?(user)
|
124
|
-
|
125
|
-
|
120
|
+
thread_sub = config.thread_subscription.to_sym
|
121
|
+
!is_closed? && !user.nil? && user.is_commontator &&\
|
122
|
+
thread_sub != :n && thread_sub != :a &&\
|
123
|
+
can_be_read_by?(user)
|
126
124
|
end
|
127
125
|
end
|
128
126
|
end
|