commontator 0.5.14 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. data/README.md +47 -10
  2. data/Rakefile +6 -5
  3. data/app/controllers/commontator/application_controller.rb +3 -1
  4. data/app/controllers/commontator/application_controller.rb~ +5 -2
  5. data/app/controllers/commontator/comments_controller.rb +9 -10
  6. data/app/controllers/commontator/comments_controller.rb~ +9 -10
  7. data/app/controllers/commontator/commontator_controller.rb~ +22 -0
  8. data/app/controllers/commontator/subscriptions_controller.rb +2 -2
  9. data/app/controllers/commontator/subscriptions_controller.rb~ +3 -3
  10. data/app/controllers/commontator/threads_controller.rb +4 -3
  11. data/app/controllers/commontator/threads_controller.rb~ +5 -3
  12. data/app/helpers/commontator/commontator_helper.rb~ +7 -0
  13. data/app/mailers/commontator/subscriptions_mailer.rb +2 -1
  14. data/app/mailers/commontator/subscriptions_mailer.rb~ +3 -1
  15. data/app/models/commontator/comment.rb +13 -9
  16. data/app/models/commontator/comment.rb~ +14 -10
  17. data/app/models/commontator/subscription.rb +3 -3
  18. data/app/models/commontator/subscription.rb~ +19 -0
  19. data/app/models/commontator/thread.rb +17 -41
  20. data/app/models/commontator/thread.rb~ +119 -0
  21. data/app/views/commontator/shared/_thread.html.erb +4 -1
  22. data/app/views/commontator/shared/_thread.html.erb~ +5 -2
  23. data/app/views/commontator/subscriptions_mailer/comment_created_email.html.erb +1 -1
  24. data/app/views/commontator/subscriptions_mailer/comment_created_email.html.erb~ +6 -0
  25. data/config/initializers/commontator.rb +42 -64
  26. data/{test/dummy/config/initializers/commontator.rb → config/initializers/commontator.rb~} +42 -64
  27. data/db/migrate/0_install_commontator.rb +1 -1
  28. data/{test/dummy/db/migrate/1_install_commontator.commontator.rb → db/migrate/0_install_commontator.rb~} +1 -2
  29. data/lib/commontator.rb +7 -12
  30. data/lib/commontator.rb~ +7 -12
  31. data/lib/commontator/commontable_config.rb +1 -1
  32. data/lib/commontator/commontable_config.rb~ +13 -0
  33. data/lib/commontator/commontator_config.rb +1 -1
  34. data/lib/commontator/commontator_config.rb~ +13 -0
  35. data/lib/commontator/controller_includes.rb +1 -0
  36. data/lib/commontator/controller_includes.rb~ +1 -1
  37. data/lib/commontator/security_transgression.rb +3 -0
  38. data/{test/dummy/public/favicon.ico → lib/commontator/security_transgression.rb~} +0 -0
  39. data/lib/commontator/shared_helper.rb +1 -1
  40. data/lib/commontator/shared_helper.rb~ +2 -2
  41. data/lib/commontator/version.rb +1 -1
  42. data/lib/commontator/version.rb~ +1 -1
  43. metadata +46 -89
  44. data/test/commontator_test.rb +0 -7
  45. data/test/dummy/README.rdoc +0 -261
  46. data/test/dummy/Rakefile +0 -7
  47. data/test/dummy/app/assets/javascripts/application.js +0 -15
  48. data/test/dummy/app/assets/stylesheets/application.css +0 -13
  49. data/test/dummy/app/controllers/application_controller.rb +0 -3
  50. data/test/dummy/app/helpers/application_helper.rb +0 -2
  51. data/test/dummy/app/views/layouts/application.html.erb +0 -14
  52. data/test/dummy/config.ru +0 -4
  53. data/test/dummy/config/application.rb +0 -59
  54. data/test/dummy/config/boot.rb +0 -10
  55. data/test/dummy/config/database.yml +0 -25
  56. data/test/dummy/config/environment.rb +0 -5
  57. data/test/dummy/config/environments/development.rb +0 -37
  58. data/test/dummy/config/environments/production.rb +0 -67
  59. data/test/dummy/config/environments/test.rb +0 -37
  60. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  61. data/test/dummy/config/initializers/inflections.rb +0 -15
  62. data/test/dummy/config/initializers/mime_types.rb +0 -5
  63. data/test/dummy/config/initializers/secret_token.rb +0 -7
  64. data/test/dummy/config/initializers/session_store.rb +0 -8
  65. data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  66. data/test/dummy/config/locales/en.yml +0 -5
  67. data/test/dummy/config/routes.rb +0 -4
  68. data/test/dummy/db/development.sqlite3 +0 -0
  69. data/test/dummy/db/schema.rb +0 -61
  70. data/test/dummy/log/development.log +0 -414
  71. data/test/dummy/public/404.html +0 -26
  72. data/test/dummy/public/422.html +0 -26
  73. data/test/dummy/public/500.html +0 -25
  74. data/test/dummy/script/rails +0 -6
  75. data/test/functional/comments_controller_test.rb +0 -181
  76. data/test/functional/subscriptions_controller_test.rb +0 -122
  77. data/test/integration/navigation_test.rb +0 -10
  78. data/test/test_helper.rb +0 -15
  79. data/test/unit/comment_test.rb +0 -35
  80. data/test/unit/helpers/comments_helper_test.rb +0 -4
  81. data/test/unit/helpers/subscriptions_helper_test.rb +0 -4
  82. data/test/unit/subscription_test.rb +0 -15
  83. data/test/unit/thread_test.rb +0 -57
@@ -8,15 +8,16 @@ module Commontator
8
8
 
9
9
  validates_presence_of :creator, :on => :create
10
10
  validates_presence_of :thread
11
+ validates_presence_of :body
11
12
 
12
13
  attr_accessible :body
13
14
 
14
- cattr_accessor :is_votable
15
- if respond_to?(:acts_as_votable)
16
- acts_as_votable if respond_to?(:acts_as_votable)
17
- self.is_votable = true
18
- else
19
- self.is_votable = false
15
+ cattr_accessor :acts_as_votable_initialized
16
+
17
+ def is_votable?
18
+ return false unless self.class.respond_to?(:acts_as_votable)
19
+ self.class.acts_as_votable unless acts_as_votable_initialized
20
+ self.class.acts_as_votable_initialized = true
20
21
  end
21
22
 
22
23
  def is_modified?
@@ -31,16 +32,18 @@ module Commontator
31
32
  config = thread.config
32
33
  (is_modified? ? 'Last modified on ' : \
33
34
  "#{config.comment_create_verb_past.capitalize} on ") + \
34
- comment.updated_at.strftime(config.timestamp_format)
35
+ updated_at.strftime(config.timestamp_format)
35
36
  end
36
37
 
37
38
  def delete(user = nil)
39
+ return false if is_deleted?
38
40
  self.deleted_at = Time.now
39
41
  self.deleter = user
40
42
  self.save!
41
43
  end
42
44
 
43
45
  def undelete
46
+ return false unless is_deleted?
44
47
  self.deleted_at = nil
45
48
  self.save!
46
49
  end
@@ -61,20 +64,21 @@ module Commontator
61
64
 
62
65
  def can_be_edited_by?(user)
63
66
  !thread.is_closed? && !is_deleted? &&\
64
- ((user == creator && thread.config.can_edit_own_comments) ||\
67
+ ((user == creator && thread.config.can_edit_own_comments && thread.can_be_read_by?(user)) ||\
65
68
  (thread.can_be_edited_by?(user) && thread.config.admin_can_edit_comments)) &&\
66
69
  (thread.comments.last == self || thread.config.can_edit_old_comments)
67
70
  end
68
71
 
69
72
  def can_be_deleted_by?(user)
70
73
  (!thread.is_closed? &&\
71
- ((user == creator && thread.config.can_delete_own_comments) &&\
74
+ ((user == creator && thread.config.can_delete_own_comments && \
75
+ thread.can_be_read_by?(user) && (!is_deleted? || deleter == user)) &&\
72
76
  (thread.comments.last == self || thread.config.can_delete_old_comments))) ||\
73
77
  thread.can_be_edited_by?(user)
74
78
  end
75
79
 
76
80
  def can_be_voted_on?
77
- is_votable && !is_deleted? && thread.config.comments_can_be_voted_on
81
+ is_votable? && !is_deleted? && thread.config.comments_can_be_voted_on
78
82
  end
79
83
 
80
84
  def can_be_voted_on_by?(user)
@@ -9,11 +9,11 @@ module Commontator
9
9
  attr_accessible :subscriber, :thread
10
10
 
11
11
  def mark_as_read
12
- self.update_attribute(:is_unread, false)
12
+ self.update_attribute(:unread, 0)
13
13
  end
14
14
 
15
- def mark_as_unread
16
- self.update_attribute(:is_unread, true)
15
+ def add_unread
16
+ self.update_attribute(:unread, unread + 1)
17
17
  end
18
18
  end
19
19
  end
@@ -0,0 +1,19 @@
1
+ module Commontator
2
+ class Subscription < ActiveRecord::Base
3
+ belongs_to :subscriber, :polymorphic => true
4
+ belongs_to :thread
5
+
6
+ validates_presence_of :subscriber, :thread
7
+ validates_uniqueness_of :thread_id, :scope => [:subscriber_id, :subscriber_type]
8
+
9
+ attr_accessible :subscriber, :thread
10
+
11
+ def mark_as_read
12
+ self.update_attribute(:is_unread, false)
13
+ end
14
+
15
+ def add_unread
16
+ self.update_attribute(:unread, unread + 1)
17
+ end
18
+ end
19
+ end
@@ -15,7 +15,7 @@ module Commontator
15
15
  end
16
16
 
17
17
  def ordered_comments
18
- (!commontable.blank? && config.comments_can_be_voted_on && config.comments_ordered_by_votes) ? \
18
+ (!commontable.blank? && config.can_vote_on_comments && config.comments_ordered_by_votes) ? \
19
19
  comments.order("cached_votes_down - cached_votes_up") : comments
20
20
  end
21
21
 
@@ -24,6 +24,7 @@ module Commontator
24
24
  end
25
25
 
26
26
  def subscription_for(subscriber)
27
+ return nil if subscriber.nil?
27
28
  Subscription.find_by_thread_id_and_subscriber_id_and_subscriber_type(self.id, subscriber.id, subscriber.class.name)
28
29
  end
29
30
 
@@ -39,14 +40,12 @@ module Commontator
39
40
  return false if is_subscribed?(subscriber)
40
41
  subscription = Subscription.create(
41
42
  :subscriber => subscriber, :thread => self)
42
- subscribe_callback(subscriber)
43
43
  end
44
44
 
45
45
  def unsubscribe(subscriber)
46
46
  subscription = subscription_for(subscriber)
47
47
  return false if subscription.blank?
48
48
  subscription.destroy
49
- unsubscribe_callback(subscriber)
50
49
  end
51
50
 
52
51
  def mark_as_read_for(subscriber)
@@ -54,19 +53,21 @@ module Commontator
54
53
  subscription_for(subscriber).mark_as_read
55
54
  end
56
55
 
57
- def mark_as_unread_except_for(subscriber)
56
+ def add_unread_except_for(subscriber)
58
57
  Subscription.transaction do
59
- subscriptions.each{|s| s.mark_as_unread unless s.subscriber == subscriber}
58
+ subscriptions.each{|s| s.add_unread unless s.subscriber == subscriber}
60
59
  end
61
60
  end
62
61
 
63
62
  def close(user = nil)
63
+ return false if is_closed?
64
64
  self.closed_at = Time.now
65
65
  self.closer = user
66
66
  self.save!
67
67
  end
68
68
 
69
69
  def reopen
70
+ return false unless is_closed?
70
71
  self.closed_at = nil
71
72
  self.save!
72
73
  end
@@ -91,49 +92,24 @@ module Commontator
91
92
  self.close(user)
92
93
  end
93
94
  end
94
-
95
- ####################
96
- # Callback methods #
97
- ####################
98
-
99
- def comment_created_callback(user, comment)
100
- commontable.blank? || config.comment_created_callback.blank? || commontable.send(config.comment_created_callback, user, comment)
101
- end
102
-
103
- def comment_edited_callback(user, comment)
104
- commontable.blank? || config.comment_edited_callback.blank? || commontable.send(config.comment_edited_callback, user, comment)
105
- end
106
-
107
- def comment_deleted_callback(user, comment)
108
- commontable.blank? || config.comment_deleted_callback.blank? || commontable.send(config.comment_deleted_callback, user, comment)
109
- end
110
-
111
- def thread_closed_callback(user)
112
- commontable.blank? || config.thread_closed_callback.blank? || commontable.send(config.thread_closed_callback, user)
113
- end
114
-
115
- def subscribe_callback(user)
116
- commontable.blank? || config.subscribe_callback.blank? || commontable.send(config.subscribe_callback, user)
117
- end
118
-
119
- def unsubscribe_callback(user)
120
- commontable.blank? || config.unsubscribe_callback.blank? || commontable.send(config.unsubscribe_callback, user)
121
- end
122
95
 
123
96
  ##########################
124
97
  # Access control methods #
125
98
  ##########################
126
-
127
- def can_be_read_by?(user) # Reader and poster capabilities
128
- (!commontable.blank? && (!is_closed? || config.closed_threads_are_readable) &&\
129
- config.can_read_thread_method.blank? ? true : commontable.send(config.can_read_thread_method, user)) ||\
99
+
100
+ # Reader and poster capabilities
101
+ def can_be_read_by?(user)
102
+ (!commontable.blank? && \
103
+ (!is_closed? || config.closed_threads_are_readable) && \
104
+ config.can_read_thread_proc.call(self, user)) || \
130
105
  can_be_edited_by?(user)
131
106
  end
132
107
 
133
- def can_be_edited_by?(user) # Thread admin capabilities
134
- !commontable.blank? && (config.can_edit_thread_method.blank? ?
135
- (user.commontator_config.is_admin_method.blank? ? false : user.send(user.commontator_config.is_admin_method)) :
136
- commontable.send(config.can_edit_thread_method, user))
108
+ # Thread moderator capabilities
109
+ def can_be_edited_by?(user)
110
+ !commontable.blank? && \
111
+ (config.can_edit_thread_proc.call(self, user) || \
112
+ (!user.nil? && user.commontator_config.user_admin_proc.call(user)))
137
113
  end
138
114
 
139
115
  def can_subscribe?(user)
@@ -0,0 +1,119 @@
1
+ module Commontator
2
+ class Thread < ActiveRecord::Base
3
+ belongs_to :closer, :polymorphic => true
4
+ belongs_to :commontable, :polymorphic => true
5
+
6
+ has_many :comments, :dependent => :destroy
7
+ has_many :subscriptions, :dependent => :destroy
8
+
9
+ validates_presence_of :commontable, :on => :create
10
+
11
+ attr_accessible :is_closed
12
+
13
+ def config
14
+ commontable.try(:commontable_config)
15
+ end
16
+
17
+ def ordered_comments
18
+ (!commontable.blank? && config.comments_can_be_voted_on && config.comments_ordered_by_votes) ? \
19
+ comments.order("cached_votes_down - cached_votes_up") : comments
20
+ end
21
+
22
+ def subscribers
23
+ subscriptions.collect{|s| s.subscriber}
24
+ end
25
+
26
+ def subscription_for(subscriber)
27
+ return nil if subscriber.nil?
28
+ Subscription.find_by_thread_id_and_subscriber_id_and_subscriber_type(self.id, subscriber.id, subscriber.class.name)
29
+ end
30
+
31
+ def is_closed?
32
+ !closed_at.blank?
33
+ end
34
+
35
+ def is_subscribed?(subscriber)
36
+ !subscription_for(subscriber).blank?
37
+ end
38
+
39
+ def subscribe(subscriber)
40
+ return false if is_subscribed?(subscriber)
41
+ subscription = Subscription.create(
42
+ :subscriber => subscriber, :thread => self)
43
+ end
44
+
45
+ def unsubscribe(subscriber)
46
+ subscription = subscription_for(subscriber)
47
+ return false if subscription.blank?
48
+ subscription.destroy
49
+ end
50
+
51
+ def mark_as_read_for(subscriber)
52
+ return if !subscription_for(subscriber)
53
+ subscription_for(subscriber).mark_as_read
54
+ end
55
+
56
+ def add_unread_except_for(subscriber)
57
+ Subscription.transaction do
58
+ subscriptions.each{|s| s.add_unread unless s.subscriber == subscriber}
59
+ end
60
+ end
61
+
62
+ def close(user = nil)
63
+ return false if is_closed?
64
+ self.closed_at = Time.now
65
+ self.closer = user
66
+ self.save!
67
+ end
68
+
69
+ def reopen
70
+ return false unless is_closed?
71
+ self.closed_at = nil
72
+ self.save!
73
+ end
74
+
75
+ # Creates a new empty thread and assigns it to the commontable
76
+ # The old thread is kept in the database for archival purposes
77
+
78
+ def clear(user = nil)
79
+ return if commontable.blank?
80
+ new_thread = Thread.new
81
+ new_thread.commontable = commontable
82
+ self.with_lock do
83
+ new_thread.save!
84
+ commontable.thread = new_thread
85
+ commontable.save!
86
+ subscriptions.each do |s|
87
+ s.thread = new_thread
88
+ s.save!
89
+ s.mark_as_read
90
+ end
91
+ self.commontable = nil
92
+ self.close(user)
93
+ end
94
+ end
95
+
96
+ ##########################
97
+ # Access control methods #
98
+ ##########################
99
+
100
+ # Reader and poster capabilities
101
+ def can_be_read_by?(user)
102
+ (!commontable.blank? && \
103
+ (!is_closed? || config.closed_threads_are_readable) && \
104
+ config.can_read_thread_proc.call(self, user)) || \
105
+ can_be_edited_by?(user)
106
+ end
107
+
108
+ # Thread moderator capabilities
109
+ def can_be_edited_by?(user)
110
+ !commontable.blank? && \
111
+ (config.can_edit_thread_proc.call(self, user) || \
112
+ (!user.nil? && user.commontator_config.user_admin_proc.call(user)))
113
+ end
114
+
115
+ def can_subscribe?(user)
116
+ !commontable.blank? && config.can_subscribe_to_thread && !is_closed? && can_be_read_by?(user)
117
+ end
118
+ end
119
+ end
@@ -3,6 +3,8 @@
3
3
  # user
4
4
  %>
5
5
 
6
+ <% subscription = thread.subscription_for(user) %>
7
+
6
8
  <% if thread.can_be_read_by?(user) %>
7
9
  <%= stylesheet_link_tag "commontator/application", :media => "all" %>
8
10
 
@@ -11,7 +13,8 @@
11
13
  <%= render :partial => 'commontator/threads/show', :locals => {:thread => thread,
12
14
  :user => user} %>
13
15
  <% else %>
14
- <%= link_to "Show #{thread.config.comment_name.pluralize} (#{thread.comments.count})", commontator.thread_path(thread), :remote => true %>
16
+ <%= link_to "Show #{thread.config.comment_name.pluralize} (#{subscription ? subscription.unread + '/' + thread.comments.count : thread.comments.count})", \
17
+ commontator.thread_path(thread), :remote => true %>
15
18
  <% end %>
16
19
  </div>
17
20
  <% end %>
@@ -3,15 +3,18 @@
3
3
  # user
4
4
  %>
5
5
 
6
+ <% subscription = thread.subscription_for(user) %>
7
+
6
8
  <% if thread.can_be_read_by?(user) %>
7
9
  <%= stylesheet_link_tag "commontator/application", :media => "all" %>
8
10
 
9
- <div id="thread_<%= thread.id %>_div" class="thread">
11
+ <div id="thread_<%= thread.id %>_div" class="thread" style="display: none;">
10
12
  <% if @commontator_thread_show %>
11
13
  <%= render :partial => 'commontator/threads/show', :locals => {:thread => thread,
12
14
  :user => user} %>
13
15
  <% else %>
14
- <%= link_to "Show #{thread.config.comment_name.pluralize} (#{thread.comments.count})", commontator.thread_path(thread), :remote => true %>
16
+ <%= link_to "Show #{thread.config.comment_name.pluralize} (#{subscription ? subscription.unread + '/' + thread.comments.count : thread.comments.count})", \
17
+ commontator.thread_path(thread), :remote => true %>
15
18
  <% end %>
16
19
  </div>
17
20
  <% end %>
@@ -1,4 +1,4 @@
1
- <h4><%= @creator_name %>'s <%= @thread.config.comment_name %> on <%= @commontable_name %> #<%= @commontable_id %>:</h4>
1
+ <h4><%= @creator_name %>'s <%= @thread.config.comment_name %> on <%= @commontable_name %> <%= @commontable_id %>:</h4>
2
2
 
3
3
  <%= render :partial => 'commontator/comments/body',
4
4
  :locals => { :comment => @comment } %>
@@ -0,0 +1,6 @@
1
+ <h4><%= @creator_name %>'s <%= @thread.config.comment_name %> on <%= @commontable_name %> #<%= @commontable_id %>:</h4>
2
+
3
+ <%= render :partial => 'commontator/comments/body',
4
+ :locals => { :comment => @comment } %>
5
+
6
+ <p><a href="<%= @commontable_url %>">Click here</a> to visit this thread.</p>
@@ -4,7 +4,7 @@ Commontator.configure do |config|
4
4
 
5
5
  # Engine Configuration
6
6
 
7
- # Method called on ApplicationController to return the current user
7
+ # Name of the ApplicationController helper method that returns the current user
8
8
  # Default: 'current_user'
9
9
  config.current_user_method = 'current_user'
10
10
 
@@ -25,6 +25,11 @@ Commontator.configure do |config|
25
25
  # Whether the user's name is clickable in the comment view
26
26
  # Default: false
27
27
  config.user_name_clickable = false
28
+
29
+ # Whether automated emails are sent to the user whenever
30
+ # a comment is posted on a thread they subscribe to
31
+ # Default: true
32
+ config.subscription_emails = true
28
33
 
29
34
  # The method that returns the user's email address
30
35
  # Default: 'email'
@@ -34,10 +39,11 @@ Commontator.configure do |config|
34
39
  # Default: '' (use user_missing_name)
35
40
  config.user_name_method = ''
36
41
 
37
- # Method that returns true if the user is an admin for all threads
42
+ # Proc called with user as argument that returns true if the user is an admin
38
43
  # Admins can always delete other users' comments and close threads
39
- # Default: '' (no admins)
40
- config.is_admin_method = ''
44
+ # Note: user can be nil
45
+ # Default: lambda { |user| false } (no admins)
46
+ config.user_admin_proc = lambda { |user| false }
41
47
 
42
48
 
43
49
  # Commontable (acts_as_commontable) Configuration
@@ -60,23 +66,6 @@ Commontator.configure do |config|
60
66
  # as an argument to acts_as_commontable in each one
61
67
  # Default: 'commontable'
62
68
  config.commontable_name = 'commontable'
63
-
64
- # Proc that returns the commontable url that contains the thread
65
- # (defaults to the commontable show url)
66
- # Main application's routes can be accessed using main_app object
67
- # Default: lambda { |main_app, commontable| main_app.polymorphic_url(commontable) }
68
- config.commontable_url_proc = lambda { |main_app, commontable| main_app.polymorphic_url(commontable) }
69
-
70
- # Proc that returns the subscription email subject
71
- # Default:
72
- # lambda do |params|
73
- # "#{params[:creator_name]} #{params[:config].comment_create_verb_past} a " + \
74
- # "#{params[:config].comment_name} on #{params[:commontable_name]} ##{params[:commontable_id]}"
75
- # end
76
- config.subscription_email_subject_proc = lambda do |params|
77
- "#{params[:creator_name]} #{params[:config].comment_create_verb_past} a " + \
78
- "#{params[:config].comment_name} on #{params[:commontable_name]} ##{params[:commontable_id]}"
79
- end
80
69
 
81
70
  # The format of the timestamps used by Commontator
82
71
  # Default: '%b %d %Y, %I:%M %p'
@@ -100,8 +89,8 @@ Commontator.configure do |config|
100
89
  config.can_edit_old_comments = false
101
90
 
102
91
  # Whether users can delete their own comments
103
- # Default: false
104
- config.can_delete_own_comments = false
92
+ # Default: true
93
+ config.can_delete_own_comments = true
105
94
 
106
95
  # Whether users can delete their own comments
107
96
  # after someone posted a newer comment
@@ -116,7 +105,7 @@ Commontator.configure do |config|
116
105
  # Note: requires acts_as_votable gem installed
117
106
  # and configured for your application
118
107
  # Default: false
119
- config.comments_can_be_voted_on = false
108
+ config.can_vote_on_comments = false
120
109
 
121
110
  # Whether comments should be ordered by vote score
122
111
  # instead of by order posted
@@ -132,48 +121,37 @@ Commontator.configure do |config|
132
121
  # Default: true
133
122
  config.deleted_comments_are_visible = true
134
123
 
135
- # Method called on commontable to return its id
124
+ # The method which returns the commontable's id that is sent to users in email messages
136
125
  # Default: 'id'
137
126
  config.commontable_id_method = 'id'
138
127
 
139
- # Method called on commontable and passed user as argument
140
- # If true, that user is a moderator for that particular commontable's thread
128
+ # Proc called with thread and user as arguments
129
+ # If it returns true, that user is a moderator for that particular thread
141
130
  # and is given admin-like capabilities for that thread only
142
- # Default: '' (no thread-specific moderators)
143
- config.can_edit_thread_method = ''
144
-
145
- # Method called on commontable and passed user as argument
146
- # If true, that user is allowed to read that commontable's thread
147
- # Default: '' (no read restrictions)
148
- config.can_read_thread_method = ''
149
-
150
- # Method called on commontable when a comment is created
151
- # Passed user, comment as arguments
152
- # Default: '' (no callback)
153
- config.comment_created_callback = ''
154
-
155
- # Method called on commontable when a comment is edited
156
- # Passed user, comment as arguments
157
- # Default: '' (no callback)
158
- config.comment_edited_callback = ''
159
-
160
- # Method called on commontable when a comment is deleted
161
- # Passed user, comment as arguments
162
- # Default: '' (no callback)
163
- config.comment_deleted_callback = ''
164
-
165
- # Method called on commontable when a thread is closed
166
- # Passed user as argument
167
- # Default: '' (no callback)
168
- config.thread_closed_callback = ''
169
-
170
- # Method called on commontable when a thread is subscribed to
171
- # Passed user as argument
172
- # Default: '' (no callback)
173
- config.subscribe_callback = ''
174
-
175
- # Method called on commontable when a thread is unsubscribed to
176
- # Passed user as argument
177
- # Default: '' (no callback)
178
- config.unsubscribe_callback = ''
131
+ # Note: user can be nil
132
+ # Default: lambda { |thread, user| false } (no thread-specific moderators)
133
+ config.can_edit_thread_proc = lambda { |thread, user| false }
134
+
135
+ # Proc called with thread and user as arguments
136
+ # If it returns true, that user is allowed to read that thread
137
+ # Note: user can be nil
138
+ # Default: lambda { |thread, user| true } (no read restrictions)
139
+ config.can_read_thread_proc = lambda { |thread, user| true }
140
+
141
+ # Proc that returns the commontable url that contains the thread
142
+ # (defaults to the commontable show url)
143
+ # Main application's routes can be accessed using main_app object
144
+ # Default: lambda { |main_app, commontable| main_app.polymorphic_url(commontable) }
145
+ config.commontable_url_proc = lambda { |main_app, commontable| main_app.polymorphic_url(commontable) }
146
+
147
+ # Proc that returns the subscription email subject string
148
+ # Default:
149
+ # lambda do |params|
150
+ # "#{params[:creator_name]} #{params[:config].comment_create_verb_past} a " + \
151
+ # "#{params[:config].comment_name} on #{params[:commontable_name]} ##{params[:commontable_id]}"
152
+ # end
153
+ config.subscription_email_subject_proc = lambda do |params|
154
+ "#{params[:creator_name]} #{params[:config].comment_create_verb_past} a " + \
155
+ "#{params[:config].comment_name} on #{params[:commontable_name]} ##{params[:commontable_id]}"
156
+ end
179
157
  end