commontator 0.4.1 → 0.5.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. data/README.md +35 -23
  2. data/app/assets/stylesheets/commontator/comments.css +1 -1
  3. data/app/assets/stylesheets/commontator/comments.css~ +0 -4
  4. data/app/controllers/commontator/application_controller.rb +4 -5
  5. data/app/controllers/commontator/application_controller.rb~ +5 -5
  6. data/app/controllers/commontator/comments_controller.rb +30 -30
  7. data/app/controllers/commontator/comments_controller.rb~ +31 -31
  8. data/app/controllers/commontator/subscriptions_controller.rb +8 -7
  9. data/app/controllers/commontator/subscriptions_controller.rb~ +6 -7
  10. data/app/controllers/commontator/threads_controller.rb +8 -9
  11. data/app/controllers/commontator/threads_controller.rb~ +9 -10
  12. data/app/helpers/commontator/comments_helper.rb~ +14 -24
  13. data/app/helpers/commontator/subscriptions_helper.rb~ +3 -3
  14. data/app/helpers/commontator/threads_helper.rb +0 -8
  15. data/app/helpers/commontator/threads_helper.rb~ +5 -5
  16. data/app/mailers/commontator/subscriptions_mailer.rb +8 -8
  17. data/app/mailers/commontator/subscriptions_mailer.rb~ +9 -10
  18. data/app/models/commontator/comment.rb +14 -6
  19. data/app/models/commontator/comment.rb~ +15 -12
  20. data/app/views/commontator/comments/_actions.html.erb +6 -5
  21. data/app/views/commontator/comments/_actions.html.erb~ +6 -5
  22. data/app/views/commontator/comments/_body.html.erb +2 -1
  23. data/app/views/commontator/comments/_body.html.erb~ +1 -2
  24. data/app/views/commontator/comments/_form.html.erb +8 -3
  25. data/app/views/commontator/comments/_form.html.erb~ +7 -4
  26. data/app/views/commontator/comments/_show.html.erb +11 -8
  27. data/app/views/commontator/comments/_show.html.erb~ +11 -8
  28. data/app/views/commontator/comments/_votes.html.erb +7 -6
  29. data/app/views/commontator/comments/create.js.erb +4 -2
  30. data/app/views/commontator/comments/delete.js.erb +5 -3
  31. data/app/views/commontator/comments/delete.js.erb~ +5 -3
  32. data/app/views/commontator/comments/update.js.erb +1 -1
  33. data/app/views/commontator/comments/update.js.erb~ +1 -1
  34. data/app/views/commontator/comments/vote.js.erb +2 -1
  35. data/app/views/commontator/shared/_thread.html.erb +17 -0
  36. data/app/views/commontator/shared/_thread.html.erb~ +16 -0
  37. data/app/views/commontator/shared/_thread_link.html.erb~ +16 -0
  38. data/app/views/commontator/subscriptions/_link.html.erb +3 -2
  39. data/app/views/commontator/subscriptions/subscribe.js.erb +2 -1
  40. data/app/views/commontator/subscriptions_mailer/comment_created_email.html.erb +1 -1
  41. data/app/views/commontator/threads/_show.html.erb +18 -11
  42. data/app/views/commontator/threads/_show.html.erb~ +18 -11
  43. data/app/views/commontator/threads/show.js.erb +2 -1
  44. data/config/initializers/commontator.rb +14 -14
  45. data/db/migrate/0_install_commontator.rb +3 -3
  46. data/lib/commontator.rb +5 -6
  47. data/lib/commontator.rb~ +5 -6
  48. data/lib/commontator/acts_as_commontable.rb +2 -0
  49. data/lib/commontator/acts_as_commontator.rb +2 -0
  50. data/lib/commontator/controller_includes.rb +23 -0
  51. data/lib/commontator/controller_includes.rb~ +23 -0
  52. data/lib/commontator/shared_helper.rb +42 -0
  53. data/lib/commontator/shared_helper.rb~ +42 -0
  54. data/lib/commontator/shared_methods.rb~ +24 -0
  55. data/lib/commontator/version.rb +1 -1
  56. data/lib/commontator/version.rb~ +1 -1
  57. data/test/dummy/config/initializers/commontator.rb +15 -15
  58. data/test/dummy/db/development.sqlite3 +0 -0
  59. data/test/dummy/db/migrate/1_install_commontator.commontator.rb +3 -3
  60. data/test/dummy/db/schema.rb +3 -3
  61. data/test/dummy/log/development.log +64 -0
  62. metadata +10 -70
  63. data/app/assets/stylesheets/commontator/application.css~ +0 -88
  64. data/app/assets/stylesheets/commontator/threads.css~ +0 -13
  65. data/app/helpers/commontator/application_helper.rb~ +0 -11
  66. data/app/helpers/commontator/comments_helper.rb +0 -51
  67. data/app/helpers/commontator/commontable_helper.rb~ +0 -9
  68. data/app/helpers/commontator/commontator_helper.rb +0 -8
  69. data/app/helpers/commontator/commontator_helper.rb~ +0 -8
  70. data/app/helpers/commontator/subscriptions_helper.rb +0 -8
  71. data/app/mailers/commontator/subscription_mailer.rb~ +0 -38
  72. data/app/models/commontator/subscription.rb~ +0 -21
  73. data/app/models/commontator/thread.rb~ +0 -143
  74. data/app/views/commontator/comments/_votes.html.erb~ +0 -62
  75. data/app/views/commontator/comments/create.js.erb~ +0 -15
  76. data/app/views/commontator/comments/destroy.js.erb~ +0 -1
  77. data/app/views/commontator/comments/edit.html.erb~ +0 -6
  78. data/app/views/commontator/comments/edit.js.erb~ +0 -5
  79. data/app/views/commontator/comments/new.html.erb~ +0 -8
  80. data/app/views/commontator/comments/new.js.erb~ +0 -12
  81. data/app/views/commontator/comments/vote.js.erb~ +0 -5
  82. data/app/views/commontator/shared/_thread_link.html.erb +0 -13
  83. data/app/views/commontator/subscriptions/_index.html.erb~ +0 -16
  84. data/app/views/commontator/subscriptions/_link.html.erb~ +0 -15
  85. data/app/views/commontator/subscriptions/_subscription_link.html.erb~ +0 -13
  86. data/app/views/commontator/subscriptions/create.js.erb~ +0 -5
  87. data/app/views/commontator/subscriptions/destroy.js.erb~ +0 -3
  88. data/app/views/commontator/subscriptions/index.html.erb~ +0 -16
  89. data/app/views/commontator/subscriptions/subscribe.js.erb~ +0 -5
  90. data/app/views/commontator/subscriptions_mailer/comment_created_email.html.erb~ +0 -6
  91. data/app/views/commontator/threads/_actions.html.erb~ +0 -28
  92. data/app/views/commontator/threads/_link.html.erb~ +0 -14
  93. data/app/views/commontator/threads/close.js.erb~ +0 -5
  94. data/app/views/commontator/threads/show.html.erb~ +0 -3
  95. data/app/views/commontator/threads/show.js.erb~ +0 -6
  96. data/config/initializers/commontator.rb~ +0 -179
  97. data/config/routes.rb~ +0 -24
  98. data/db/migrate/0_install_commontator.rb~ +0 -48
  99. data/lib/commontator/acts_as_commontable.rb~ +0 -39
  100. data/lib/commontator/acts_as_commontator.rb~ +0 -28
  101. data/lib/commontator/commontable_config.rb~ +0 -13
  102. data/lib/commontator/commontator_config.rb~ +0 -13
  103. data/lib/commontator/routes.rb~ +0 -37
  104. data/lib/tasks/commontator_tasks.rake~ +0 -41
  105. data/test/dummy/config/initializers/commontator.rb~ +0 -179
  106. data/test/dummy/config/routes.rb~ +0 -3
  107. data/test/functional/comment_thread_subscriptions_controller_test.rb~ +0 -125
  108. data/test/functional/comments_controller_test.rb~ +0 -184
  109. data/test/functional/subscriptions_controller_test.rb~ +0 -122
  110. data/test/unit/comment_test.rb~ +0 -38
  111. data/test/unit/comment_thread_subscription_test.rb~ +0 -18
  112. data/test/unit/comment_thread_test.rb~ +0 -60
  113. data/test/unit/helpers/comment_thread_subscriptions_helper_test.rb~ +0 -7
  114. data/test/unit/helpers/comments_helper_test.rb~ +0 -7
  115. data/test/unit/helpers/subscriptions_helper_test.rb~ +0 -4
  116. data/test/unit/subscription_test.rb~ +0 -15
  117. data/test/unit/thread_test.rb~ +0 -57
@@ -1,16 +1,17 @@
1
1
  module Commontator
2
2
  class SubscriptionsController < ApplicationController
3
- before_filter :get_thread, :except => :index
3
+ before_filter :get_thread
4
+ before_filter :get_commontable_url
4
5
 
5
6
  # POST /1/subscribe
6
7
  def create
7
- raise SecurityTransgression unless @thread.can_subscribe?(@commontator)
8
+ raise SecurityTransgression unless @thread.can_subscribe?(@user)
8
9
 
9
10
  @thread.errors.add(:base, "You are already subscribed to this thread") \
10
- unless @thread.subscribe(@commontator)
11
+ unless @thread.subscribe(@user)
11
12
 
12
13
  respond_to do |format|
13
- format.html { redirect_to @commontable_url }
14
+ format.html { redirect_to @thread }
14
15
  format.js { render :subscribe }
15
16
  end
16
17
 
@@ -18,13 +19,13 @@ module Commontator
18
19
 
19
20
  # POST /1/unsubscribe
20
21
  def destroy
21
- raise SecurityTransgression unless @thread.can_subscribe?(@commontator)
22
+ raise SecurityTransgression unless @thread.can_subscribe?(@user)
22
23
 
23
24
  @thread.errors.add(:base, "You are not subscribed to this thread") \
24
- unless @thread.unsubscribe(@commontator)
25
+ unless @thread.unsubscribe(@user)
25
26
 
26
27
  respond_to do |format|
27
- format.html { redirect_to @commontable_url }
28
+ format.html { redirect_to @thread }
28
29
  format.js { render :subscribe }
29
30
  end
30
31
  end
@@ -1,15 +1,14 @@
1
1
  module Commontator
2
2
  class SubscriptionsController < ApplicationController
3
- helper ThreadsHelper
4
-
5
- before_filter :get_thread, :except => :index
3
+ before_filter :get_thread
4
+ before_filter :get_commontable_url
6
5
 
7
6
  # POST /1/subscribe
8
7
  def create
9
- raise SecurityTransgression unless @thread.can_subscribe?(@commontator)
8
+ raise SecurityTransgression unless @thread.can_subscribe?(@user)
10
9
 
11
10
  @thread.errors.add(:base, "You are already subscribed to this thread") \
12
- unless @thread.subscribe(@commontator)
11
+ unless @thread.subscribe(@user)
13
12
 
14
13
  respond_to do |format|
15
14
  format.html { redirect_to @commontable_url }
@@ -20,10 +19,10 @@ module Commontator
20
19
 
21
20
  # POST /1/unsubscribe
22
21
  def destroy
23
- raise SecurityTransgression unless @thread.can_subscribe?(@commontator)
22
+ raise SecurityTransgression unless @thread.can_subscribe?(@user)
24
23
 
25
24
  @thread.errors.add(:base, "You are not subscribed to this thread") \
26
- unless @thread.unsubscribe(@commontator)
25
+ unless @thread.unsubscribe(@user)
27
26
 
28
27
  respond_to do |format|
29
28
  format.html { redirect_to @commontable_url }
@@ -1,12 +1,11 @@
1
1
  module Commontator
2
2
  class ThreadsController < ApplicationController
3
3
  before_filter :get_thread
4
+ before_filter :get_commontable_url, :only => :show
4
5
 
5
6
  # GET /threads/1
6
7
  def show
7
- raise SecurityTransgression unless @thread.can_be_read_by?(@commontator)
8
-
9
- @thread.mark_as_read_for(@commontator)
8
+ commontator_thread_show(@thread.commontable)
10
9
 
11
10
  respond_to do |format|
12
11
  format.html { redirect_to @commontable_url }
@@ -16,24 +15,24 @@ module Commontator
16
15
 
17
16
  # PUT /threads/1/close
18
17
  def close
19
- raise SecurityTransgression unless @thread.can_be_edited_by?(@commontator)
18
+ raise SecurityTransgression unless @thread.can_be_edited_by?(@user)
20
19
 
21
- @thread.close(@commontator)
22
- @thread.thread_closed_callback(@commontator)
20
+ @thread.close(@user)
21
+ @thread.thread_closed_callback(@user)
23
22
 
24
23
  respond_to do |format|
25
- format.html { redirect_to @commontable_url }
24
+ format.html { redirect_to @thread }
26
25
  end
27
26
  end
28
27
 
29
28
  # PUT /threads/1/reopen
30
29
  def reopen
31
- raise SecurityTransgression unless @thread.can_be_edited_by?(@commontator)
30
+ raise SecurityTransgression unless @thread.can_be_edited_by?(@user)
32
31
 
33
32
  @thread.reopen
34
33
 
35
34
  respond_to do |format|
36
- format.html { redirect_to @commontable_url }
35
+ format.html { redirect_to @thread }
37
36
  end
38
37
  end
39
38
  end
@@ -1,39 +1,38 @@
1
1
  module Commontator
2
2
  class ThreadsController < ApplicationController
3
3
  before_filter :get_thread
4
+ before_filter :get_commontable_url, :only => :show
4
5
 
5
6
  # GET /threads/1
6
7
  def show
7
- raise SecurityTransgression unless @thread.can_be_read_by?(@commontator)
8
-
9
- @thread.mark_as_read_for(@commontator)
8
+ commontator_thread_show(@thread.commontable, @user)
10
9
 
11
10
  respond_to do |format|
12
- format.html { redirect_to commontable_url(@thread) }
11
+ format.html { redirect_to @commontable_url }
13
12
  format.js
14
13
  end
15
14
  end
16
15
 
17
16
  # PUT /threads/1/close
18
17
  def close
19
- raise SecurityTransgression unless @thread.can_be_edited_by?(@commontator)
18
+ raise SecurityTransgression unless @thread.can_be_edited_by?(@user)
20
19
 
21
- @thread.close(@commontator)
22
- @thread.thread_closed_callback(@commontator)
20
+ @thread.close(@user)
21
+ @thread.thread_closed_callback(@user)
23
22
 
24
23
  respond_to do |format|
25
- format.html { redirect_to commontable_url(@thread) }
24
+ format.html { redirect_to @thread }
26
25
  end
27
26
  end
28
27
 
29
28
  # PUT /threads/1/reopen
30
29
  def reopen
31
- raise SecurityTransgression unless @thread.can_be_edited_by?(@commontator)
30
+ raise SecurityTransgression unless @thread.can_be_edited_by?(@user)
32
31
 
33
32
  @thread.reopen
34
33
 
35
34
  respond_to do |format|
36
- format.html { redirect_to commontable_url(@thread) }
35
+ format.html { redirect_to @thread }
37
36
  end
38
37
  end
39
38
  end
@@ -1,19 +1,10 @@
1
1
  module Commontator
2
2
  module CommentsHelper
3
- def commontator_name(comment)
4
- commontator = comment.commontator
5
- return Commontator.commontator_missing_name if commontator.nil?
6
- config = commontator.commontator_config
7
- config.commontator_name_method.blank? ? config.commontator_missing_name : \
8
- commontator.send(config.commontator_name_method
9
- end
10
-
11
- def deleter_name(comment)
12
- deleter = comment.deleter
13
- return Commontator.commontator_missing_name if deleter.nil?
14
- config = deleter.commontator_config
15
- config.commontator_name_method.blank? ? config.commontator_missing_name : \
16
- deleter.send(config.commontator_name_method)
3
+ def commontator_name(user)
4
+ return Commontator.user_missing_name if user.nil?
5
+ config = user.commontator_config
6
+ config.user_name_method.blank? ? config.user_missing_name : \
7
+ user.send(config.user_name_method)
17
8
  end
18
9
 
19
10
  def comment_timestamp(comment)
@@ -23,25 +14,24 @@ module Commontator
23
14
  ' on ') + comment.updated_at.strftime(config.timestamp_format)
24
15
  end
25
16
 
26
- def gravatar_url(comment, options = {})
27
- commontator = comment.commontator
28
- return '' if commontator.nil?
29
- config = commontator.commontator_config
17
+ def commontator_gravatar_url(user, options = {})
18
+ return '' if user.nil?
19
+ config = user.commontator_config
30
20
 
31
21
  options[:secure] ||= request.ssl?
32
22
  options[:size] ||= 50
33
23
 
34
- hash = Digest::MD5.hexdigest(commontator.send(config.commontator_email_method))
24
+ hash = Digest::MD5.hexdigest(user.send(config.user_email_method))
35
25
  base = options[:secure] ? "s://secure" : "://www"
36
26
 
37
27
  "http#{base}.gravatar.com/avatar/#{hash}?s=#{options[:size]}"
38
28
  end
39
29
 
40
- def gravatar_image(comment, options = {})
41
- commontator = comment.commontator
42
- return '' if commontator.nil?
43
- config = commontator.commontator_config
44
- name = commontator.send(config.commontator_name_method)
30
+ def commontator_gravatar_image(comment, options = {})
31
+ user = comment.creator
32
+ return '' if user.nil?
33
+ config = user.commontator_config
34
+ name = user.send(config.user_name_method)
45
35
  image_tag(gravatar_url(comment, options),
46
36
  { :alt => name,
47
37
  :title => name,
@@ -1,8 +1,8 @@
1
1
  module Commontator
2
2
  module SubscriptionsHelper
3
- def email(subscriber)
4
- config = subscriber.commontator_config
5
- config.email_method.blank? ? '' : subscriber.send config.email_method
3
+ def commontator_email(user)
4
+ config = user.commontator_config
5
+ config.email_method.blank? ? '' : user.send(config.email_method)
6
6
  end
7
7
  end
8
8
  end
@@ -10,13 +10,5 @@ module Commontator
10
10
  def commontable_id(thread)
11
11
  thread.commontable.send(thread.config.commontable_id_method)
12
12
  end
13
-
14
- def closer_name(thread)
15
- closer = thread.closer
16
- return Commontator.commontator_missing_name if closer.nil?
17
- config = closer.commontator_config
18
- config.commontator_name_method.blank? ? config.commontator_missing_name : \
19
- closer.send(config.commontator_name_method)
20
- end
21
13
  end
22
14
  end
@@ -12,11 +12,11 @@ module Commontator
12
12
  end
13
13
 
14
14
  def closer_name(thread)
15
- closer = thread.closer
16
- return Commontator.commontator_missing_name if closer.nil?
17
- config = closer.commontator_config
18
- config.commontator_name_method.blank? ? config.commontator_no_name : \
19
- closer.send(config.commontator_name_method)
15
+ user = thread.closer
16
+ return Commontator.user_missing_name if user.nil?
17
+ config = user.commontator_config
18
+ config.user_name_method.blank? ? config.user_missing_name : \
19
+ user.send(config.user_name_method)
20
20
  end
21
21
  end
22
22
  end
@@ -1,6 +1,6 @@
1
1
  module Commontator
2
2
  class SubscriptionsMailer < ActionMailer::Base
3
- include CommentsHelper
3
+ include SharedHelper
4
4
  include ThreadsHelper
5
5
 
6
6
  def comment_created_email(comment, commontable_url)
@@ -16,18 +16,18 @@ protected
16
16
 
17
17
  @comment = comment
18
18
  @thread = @comment.thread
19
- @commontator = @comment.commontator
19
+ @creator = @comment.creator
20
20
 
21
- @bcc = @thread.subscribers.reject{|s| s == @commontator}\
22
- .collect{|s| email(s)}
21
+ @bcc = @thread.subscribers.reject{|s| s == @creator}\
22
+ .collect{|s| commontator_email(s)}
23
23
 
24
24
  return if @bcc.empty?
25
25
 
26
26
  @commontable = @thread.commontable
27
27
  @config = @thread.config
28
28
 
29
- @commontator_name = commontator_name(@comment)
30
- @comment_timestamp = comment_timestamp(@comment)
29
+ @creator_name = commontator_name(@creator)
30
+ @comment_timestamp = @comment.timestamp
31
31
 
32
32
  @commontable_name = commontable_name(@thread)
33
33
  @commontable_id = commontable_id(@thread).to_s
@@ -37,10 +37,10 @@ protected
37
37
  params = Hash.new
38
38
  params[:comment] = @comment
39
39
  params[:thread] = @thread
40
- params[:commontator] = @commontator
40
+ params[:creator] = @creator
41
41
  params[:commontable] = @commontable
42
42
  params[:config] = @config
43
- params[:commontator_name] = @commontator_name
43
+ params[:creator_name] = @creator_name
44
44
  params[:comment_timestamp] = @comment_timestamp
45
45
  params[:commontable_name] = @commontable_name
46
46
  params[:commontable_id] = @commontable_id
@@ -1,7 +1,6 @@
1
1
  module Commontator
2
2
  class SubscriptionsMailer < ActionMailer::Base
3
- include CommentsHelper
4
- include ThreadsHelper
3
+ include SharedHelper
5
4
 
6
5
  def comment_created_email(comment, commontable_url)
7
6
  setup_variables(comment, commontable_url)
@@ -16,18 +15,18 @@ protected
16
15
 
17
16
  @comment = comment
18
17
  @thread = @comment.thread
19
- @commontator = @comment.commontator
18
+ @creator = @comment.creator
20
19
 
21
- @bcc = @thread.subscribers.reject{|s| s == @commontator}\
22
- .collect{|s| email(s)}
20
+ @bcc = @thread.subscribers.reject{|s| s == @creator}\
21
+ .collect{|s| commontator_email(s)}
23
22
 
24
23
  return if @bcc.empty?
25
24
 
26
25
  @commontable = @thread.commontable
27
26
  @config = @thread.config
28
27
 
29
- @commontator_name = commontator_name(@comment)
30
- @comment_timestamp = comment_timestamp(@comment)
28
+ @creator_name = commontator_name(@creator)
29
+ @comment_timestamp = @comment.timestamp
31
30
 
32
31
  @commontable_name = commontable_name(@thread)
33
32
  @commontable_id = commontable_id(@thread).to_s
@@ -37,14 +36,14 @@ protected
37
36
  params = Hash.new
38
37
  params[:comment] = @comment
39
38
  params[:thread] = @thread
40
- params[:commontator] = @commontator
39
+ params[:creator] = @creator
41
40
  params[:commontable] = @commontable
42
41
  params[:config] = @config
43
- params[:commontator_name] = @commontator_name
42
+ params[:creator_name] = @creator_name
44
43
  params[:comment_timestamp] = @comment_timestamp
45
- params[:commontable_url] = @commontable_url
46
44
  params[:commontable_name] = @commontable_name
47
45
  params[:commontable_id] = @commontable_id
46
+ params[:commontable_url] = @commontable_url
48
47
 
49
48
  @subject = @config.subscription_email_subject_proc.call(params)
50
49
  end
@@ -1,12 +1,13 @@
1
1
  module Commontator
2
2
  class Comment < ActiveRecord::Base
3
- belongs_to :commontator, :polymorphic => true
3
+ belongs_to :creator, :polymorphic => true
4
4
  belongs_to :deleter, :polymorphic => true
5
5
  belongs_to :thread
6
6
 
7
7
  has_one :commontable, :through => :thread
8
8
 
9
- validates_presence_of :commontator, :thread
9
+ validates_presence_of :creator, :on => :create
10
+ validates_presence_of :thread
10
11
 
11
12
  attr_accessible :body
12
13
 
@@ -26,6 +27,13 @@ module Commontator
26
27
  !deleted_at.blank?
27
28
  end
28
29
 
30
+ def timestamp
31
+ config = thread.config
32
+ (is_modified? ? 'Last modified on ' : \
33
+ "#{config.comment_create_verb_past.capitalize} on ") + \
34
+ updated_at.strftime(config.timestamp_format)
35
+ end
36
+
29
37
  def delete(user = nil)
30
38
  self.deleted_at = Time.now
31
39
  self.deleter = user
@@ -48,19 +56,19 @@ module Commontator
48
56
  end
49
57
 
50
58
  def can_be_created_by?(user)
51
- !thread.is_closed? && thread.can_be_read_by?(user) && user == commontator
59
+ !thread.is_closed? && thread.can_be_read_by?(user) && user == creator
52
60
  end
53
61
 
54
62
  def can_be_edited_by?(user)
55
63
  !thread.is_closed? && !is_deleted? &&\
56
- ((user == commontator && thread.config.can_edit_own_comments) ||\
64
+ ((user == creator && thread.config.can_edit_own_comments) ||\
57
65
  (thread.can_be_edited_by?(user) && thread.config.admin_can_edit_comments)) &&\
58
66
  (thread.comments.last == self || thread.config.can_edit_old_comments)
59
67
  end
60
68
 
61
69
  def can_be_deleted_by?(user)
62
70
  (!thread.is_closed? &&\
63
- ((user == commontator && thread.config.can_delete_own_comments) &&\
71
+ ((user == creator && thread.config.can_delete_own_comments) &&\
64
72
  (thread.comments.last == self || thread.config.can_delete_old_comments))) ||\
65
73
  thread.can_be_edited_by?(user)
66
74
  end
@@ -71,7 +79,7 @@ module Commontator
71
79
 
72
80
  def can_be_voted_on_by?(user)
73
81
  can_be_voted_on? && !thread.is_closed? &&\
74
- thread.can_be_read_by?(user) && user != commontator
82
+ thread.can_be_read_by?(user) && user != creator
75
83
  end
76
84
  end
77
85
  end
@@ -1,17 +1,13 @@
1
1
  module Commontator
2
2
  class Comment < ActiveRecord::Base
3
- belongs_to :commontator, :polymorphic => true
3
+ belongs_to :creator, :polymorphic => true
4
4
  belongs_to :deleter, :polymorphic => true
5
5
  belongs_to :thread
6
6
 
7
7
  has_one :commontable, :through => :thread
8
- #has_one :subthread, :class_name => "Commontator::Thread",
9
- # :as => :commontable,
10
- # :dependent => :destroy
11
-
12
- #before_validation :build_subthread, :on => :create
13
- validates_presence_of :commontator, :thread#, :subthread
14
- #validates_uniqueness_of :subthread
8
+
9
+ validates_presence_of :creator, :on => :create
10
+ validates_presence_of :thread
15
11
 
16
12
  attr_accessible :body
17
13
 
@@ -31,6 +27,13 @@ module Commontator
31
27
  !deleted_at.blank?
32
28
  end
33
29
 
30
+ def timestamp
31
+ config = thread.config
32
+ (is_modified? ? 'Last modified on ' : \
33
+ "#{config.comment_create_verb_past.capitalize} on ") + \
34
+ comment.updated_at.strftime(config.timestamp_format)
35
+ end
36
+
34
37
  def delete(user = nil)
35
38
  self.deleted_at = Time.now
36
39
  self.deleter = user
@@ -53,19 +56,19 @@ module Commontator
53
56
  end
54
57
 
55
58
  def can_be_created_by?(user)
56
- !thread.is_closed? && thread.can_be_read_by?(user) && user == commontator
59
+ !thread.is_closed? && thread.can_be_read_by?(user) && user == creator
57
60
  end
58
61
 
59
62
  def can_be_edited_by?(user)
60
63
  !thread.is_closed? && !is_deleted? &&\
61
- ((user == commontator && thread.config.can_edit_own_comments) ||\
64
+ ((user == creator && thread.config.can_edit_own_comments) ||\
62
65
  (thread.can_be_edited_by?(user) && thread.config.admin_can_edit_comments)) &&\
63
66
  (thread.comments.last == self || thread.config.can_edit_old_comments)
64
67
  end
65
68
 
66
69
  def can_be_deleted_by?(user)
67
70
  (!thread.is_closed? &&\
68
- ((user == commontator && thread.config.can_delete_own_comments) &&\
71
+ ((user == creator && thread.config.can_delete_own_comments) &&\
69
72
  (thread.comments.last == self || thread.config.can_delete_old_comments))) ||\
70
73
  thread.can_be_edited_by?(user)
71
74
  end
@@ -76,7 +79,7 @@ module Commontator
76
79
 
77
80
  def can_be_voted_on_by?(user)
78
81
  can_be_voted_on? && !thread.is_closed? &&\
79
- thread.can_be_read_by?(user) && user != commontator
82
+ thread.can_be_read_by?(user) && user != creator
80
83
  end
81
84
  end
82
85
  end