commontator 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +1 -1
  3. data/app/controllers/commontator/application_controller.rb~ +27 -0
  4. data/app/controllers/commontator/comments_controller.rb~ +20 -12
  5. data/app/controllers/commontator/subscriptions_controller.rb~ +32 -0
  6. data/app/controllers/commontator/threads_controller.rb~ +42 -0
  7. data/app/mailers/commontator/subscriptions_mailer.rb~ +50 -0
  8. data/app/models/commontator/comment.rb~ +2 -6
  9. data/app/models/commontator/subscription.rb~ +2 -5
  10. data/app/models/commontator/thread.rb~ +5 -7
  11. data/app/views/commontator/comments/_actions.html.erb~ +30 -0
  12. data/app/views/commontator/comments/_votes.html.erb~ +1 -1
  13. data/app/views/commontator/shared/_thread.html.erb~ +20 -0
  14. data/app/views/commontator/subscriptions/_link.html.erb~ +16 -0
  15. data/app/views/commontator/threads/_show.html.erb~ +62 -0
  16. data/config/initializers/commontator.rb~ +1 -1
  17. data/config/routes.rb~ +22 -0
  18. data/db/migrate/0_install.rb~ +1 -1
  19. data/db/migrate/{0_install.rb → 0_install_commontator.rb} +1 -1
  20. data/lib/commontator/controller_includes.rb~ +22 -0
  21. data/lib/commontator/shared_helper.rb~ +42 -0
  22. data/lib/commontator/version.rb +1 -1
  23. data/lib/commontator/version.rb~ +1 -1
  24. data/spec/app/controllers/commontator/comments_controller_spec.rb~ +55 -2
  25. data/spec/app/controllers/commontator/subscriptions_controller_spec.rb~ +16 -16
  26. data/spec/app/controllers/commontator/threads_controller_spec.rb~ +1 -1
  27. data/spec/app/helpers/commontator/application_helper_spec.rb~ +2 -0
  28. data/spec/app/helpers/commontator/threads_helper_spec.rb~ +1 -1
  29. data/spec/app/mailers/commontator/subscriptions_mailer_spec.rb~ +1 -1
  30. data/spec/app/models/commontator/comment_spec.rb~ +1 -1
  31. data/spec/app/models/commontator/subscription_spec.rb~ +1 -1
  32. data/spec/app/models/commontator/thread_spec.rb~ +1 -1
  33. data/spec/dummy/Rakefile~ +1 -1
  34. data/spec/dummy/config.ru~ +4 -0
  35. data/spec/dummy/config/application.rb~ +23 -0
  36. data/spec/dummy/config/environment.rb~ +5 -0
  37. data/spec/dummy/config/environments/development.rb~ +31 -0
  38. data/spec/dummy/config/environments/production.rb~ +67 -0
  39. data/spec/dummy/config/environments/test.rb~ +31 -0
  40. data/spec/dummy/config/initializers/secret_token.rb~ +12 -0
  41. data/spec/dummy/db/development.sqlite3 +0 -0
  42. data/spec/dummy/db/test.sqlite3 +0 -0
  43. data/spec/dummy/log/development.log +1250 -0
  44. data/spec/dummy/log/test.log +170101 -0
  45. data/spec/dummy/tmp/cache/assets/test/sprockets/02d4b791eb831cf2057bf4703a1218d1 +0 -0
  46. data/spec/dummy/tmp/cache/assets/test/sprockets/0f196a1a50363b0a076ec6e1ee5417f6 +0 -0
  47. data/spec/dummy/tmp/cache/assets/test/sprockets/a3fb9025f90ff05a6fd4afc7ded2692c +0 -0
  48. data/spec/dummy/tmp/cache/assets/test/sprockets/a41c8be5379abec3c0d0d98e2f0d5609 +0 -0
  49. data/spec/dummy/tmp/cache/assets/test/sprockets/c69ee3cc5796188d873574179290a6ef +0 -0
  50. data/spec/dummy/tmp/cache/assets/test/sprockets/e1f674c11941d62aac1764ef3a7134e4 +0 -0
  51. data/spec/dummy/tmp/cache/assets/test/sprockets/e85565206c3e5fdf9dfeb367c85557b1 +0 -0
  52. data/spec/lib/commontator/acts_as_commontable_spec.rb~ +2 -2
  53. data/spec/lib/commontator/acts_as_commontator_spec.rb~ +1 -1
  54. data/spec/lib/commontator/commontable_config_spec.rb~ +1 -1
  55. data/spec/lib/commontator/commontator_config_spec.rb~ +1 -1
  56. data/spec/lib/commontator/controller_includes_spec.rb~ +3 -3
  57. data/spec/lib/commontator/shared_helper_spec.rb~ +7 -3
  58. data/spec/lib/commontator_spec.rb~ +1 -1
  59. data/spec/test_helper.rb~ +37 -0
  60. metadata +61 -31
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8e80641594c9354508803c783181a053cadf8d5b
4
+ data.tar.gz: 656bda25be213ff0f5186c363d02ac8f63667e07
5
+ SHA512:
6
+ metadata.gz: afe7369d598e62151110282f724582724e261e44814bf57582ad86221c0a8b3d25b8f530a95023526f8529fc4fb284debafd38c24dcf8e8db7d09b5a33af88cb
7
+ data.tar.gz: 295d8301ae86ad273f2604dafcf257f88b44593dc74e105dcb32461c14ee856aa56faf4a5cf99c28743c64ac80fcb919592556e835422f25fc8c0fa0a2f8c581
data/README.md CHANGED
@@ -13,7 +13,7 @@ There are 4 steps you must follow to install commontator:
13
13
  Add this line to your application's Gemfile:
14
14
 
15
15
  ```ruby
16
- gem 'commontator', '~> 1.1.0'
16
+ gem 'commontator', '~> 2.0.2'
17
17
  ```
18
18
 
19
19
  And then execute:
@@ -0,0 +1,27 @@
1
+ module Commontator
2
+ class CommontatorController < ActionController::Base
3
+ before_filter :get_user
4
+
5
+ cattr_accessor :commontable_url
6
+
7
+ rescue_from SecurityTransgression, :with => lambda { head(:forbidden) }
8
+
9
+ protected
10
+
11
+ def get_user
12
+ @user = self.send Commontator.current_user_method
13
+ raise SecurityTransgression unless (@user.nil? || @user.is_commontator)
14
+ end
15
+
16
+ def get_thread
17
+ @thread = params[:thread_id].blank? ? \
18
+ Commontator::Thread.find(params[:id]) : \
19
+ Commontator::Thread.find(params[:thread_id])
20
+ raise SecurityTransgression if @thread.commontable.nil?
21
+ end
22
+
23
+ def set_commontable_url
24
+ self.commontable_url = @thread.config.commontable_url_proc.call(main_app, @thread.commontable)
25
+ end
26
+ end
27
+ end
@@ -1,10 +1,10 @@
1
1
  module Commontator
2
- class CommentsController < ApplicationController
2
+ class CommentsController < Commontator::ApplicationController
3
3
  before_filter :get_thread, :only => [:new, :create]
4
4
  before_filter :get_comment_and_thread, :except => [:new, :create]
5
5
  before_filter :set_commontable_url, :only => :create
6
6
 
7
- # GET /1/comments/new
7
+ # GET /threads/1/comments/new
8
8
  def new
9
9
  @comment = Comment.new
10
10
  @comment.thread = @thread
@@ -19,9 +19,10 @@ module Commontator
19
19
 
20
20
  end
21
21
 
22
- # POST /1/comments
22
+ # POST /threads/1/comments
23
23
  def create
24
- @comment = Comment.new(params[:comment])
24
+ @comment = Comment.new
25
+ @comment.body = params[:comment][:body] unless params[:comment].nil?
25
26
  @comment.thread = @thread
26
27
  @comment.creator = @user
27
28
 
@@ -29,6 +30,12 @@ module Commontator
29
30
 
30
31
  respond_to do |format|
31
32
  if @comment.save
33
+ @thread.subscribe(@user) if @thread.config.auto_subscribe_on_comment
34
+ @thread.add_unread_except_for(@user)
35
+ recipients = @thread.active_subscribers.reject{|s| s == @user}
36
+ SubscriptionsMailer.comment_created(@comment, recipients).deliver \
37
+ unless recipients.empty?
38
+
32
39
  format.html { redirect_to @thread }
33
40
  format.js
34
41
  else
@@ -48,13 +55,14 @@ module Commontator
48
55
  end
49
56
  end
50
57
 
51
- # PUT /comments/1
58
+ # PATCH /comments/1
52
59
  def update
53
60
  raise SecurityTransgression unless @comment.can_be_edited_by?(@user)
61
+ @comment.body = params[:comment][:body] unless params[:comment].nil?
54
62
  @comment.editor = @user
55
63
 
56
64
  respond_to do |format|
57
- if @comment.update_attributes(params[:comment])
65
+ if @comment.save
58
66
  format.html { redirect_to @thread }
59
67
  format.js
60
68
  else
@@ -64,12 +72,12 @@ module Commontator
64
72
  end
65
73
  end
66
74
 
67
- # PUT /comments/1/delete
75
+ # PATCH /comments/1/delete
68
76
  def delete
69
77
  raise SecurityTransgression unless @comment.can_be_deleted_by?(@user)
70
78
 
71
79
  @comment.errors.add(:base, 'This comment has already been deleted.') \
72
- unless @comment.delete(@user)
80
+ unless @comment.delete_by(@user)
73
81
 
74
82
  respond_to do |format|
75
83
  format.html { redirect_to @thread }
@@ -77,7 +85,7 @@ module Commontator
77
85
  end
78
86
  end
79
87
 
80
- # PUT /comments/1/undelete
88
+ # PATCH /comments/1/undelete
81
89
  def undelete
82
90
  raise SecurityTransgression unless @comment.can_be_deleted_by?(@user)
83
91
 
@@ -90,7 +98,7 @@ module Commontator
90
98
  end
91
99
  end
92
100
 
93
- # PUT /comments/1/upvote
101
+ # PATCH /comments/1/upvote
94
102
  def upvote
95
103
  raise SecurityTransgression unless @comment.can_be_voted_on_by?(@user)
96
104
 
@@ -102,7 +110,7 @@ module Commontator
102
110
  end
103
111
  end
104
112
 
105
- # PUT /comments/1/downvote
113
+ # PATCH /comments/1/downvote
106
114
  def downvote
107
115
  raise SecurityTransgression unless @comment.can_be_voted_on_by?(@user)
108
116
 
@@ -114,7 +122,7 @@ module Commontator
114
122
  end
115
123
  end
116
124
 
117
- # PUT /comments/1/unvote
125
+ # PATCH /comments/1/unvote
118
126
  def unvote
119
127
  raise SecurityTransgression unless @comment.can_be_voted_on_by?(@user)
120
128
 
@@ -0,0 +1,32 @@
1
+ module Commontator
2
+ class SubscriptionsController < Commontator::ApplicationController
3
+ before_filter :get_thread
4
+
5
+ # PATCH threads/1/subscribe
6
+ def subscribe
7
+ raise SecurityTransgression unless @thread.can_subscribe?(@user)
8
+
9
+ @thread.errors.add(:subscription, "You are already subscribed to this thread") \
10
+ unless @thread.subscribe(@user)
11
+
12
+ respond_to do |format|
13
+ format.html { redirect_to @thread }
14
+ format.js { render :subscribe }
15
+ end
16
+
17
+ end
18
+
19
+ # PATCH threads/1/unsubscribe
20
+ def unsubscribe
21
+ raise SecurityTransgression unless @thread.can_subscribe?(@user)
22
+
23
+ @thread.errors.add(:subscription, "You are not subscribed to this thread") \
24
+ unless @thread.unsubscribe(@user)
25
+
26
+ respond_to do |format|
27
+ format.html { redirect_to @thread }
28
+ format.js { render :subscribe }
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,42 @@
1
+ module Commontator
2
+ class ThreadsController < Commontator::ApplicationController
3
+ before_filter :get_thread
4
+ before_filter :set_commontable_url, :only => :show
5
+
6
+ # GET /threads/1
7
+ def show
8
+ commontator_thread_show(@thread.commontable)
9
+
10
+ respond_to do |format|
11
+ format.html { redirect_to commontable_url }
12
+ format.js
13
+ end
14
+ end
15
+
16
+ # PATCH /threads/1/close
17
+ def close
18
+ raise SecurityTransgression unless @thread.can_be_edited_by?(@user)
19
+
20
+ @thread.errors.add(:base, 'This thread has already been closed.') \
21
+ unless @thread.close(@user)
22
+
23
+ respond_to do |format|
24
+ format.html { redirect_to @thread }
25
+ format.js { render :show }
26
+ end
27
+ end
28
+
29
+ # PUT /threads/1/reopen
30
+ def reopen
31
+ raise SecurityTransgression unless @thread.can_be_edited_by?(@user)
32
+
33
+ @thread.errors.add(:base, 'This thread is not closed.') \
34
+ unless @thread.reopen
35
+
36
+ respond_to do |format|
37
+ format.html { redirect_to @thread }
38
+ format.js { render :show }
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,50 @@
1
+ module Commontator
2
+ class SubscriptionsMailer < ActionMailer::Base
3
+ include SharedHelper
4
+ include ThreadsHelper
5
+
6
+ def comment_created(comment, recipients)
7
+ setup_variables(comment, recipients)
8
+
9
+ mail :to => 'Undisclosed Recipients'
10
+ :bcc => @bcc,
11
+ :from => @from,
12
+ :subject => @subject
13
+ end
14
+
15
+ protected
16
+
17
+ def setup_variables(comment, recipients)
18
+ @comment = comment
19
+ @thread = @comment.thread
20
+ @creator = @comment.creator
21
+
22
+ @commontable = @thread.commontable
23
+ @config = @thread.config
24
+
25
+ @creator_name = commontator_name(@creator)
26
+ @comment_timestamp = @comment.timestamp
27
+
28
+ @commontable_name = commontable_name(@thread)
29
+ @commontable_id = commontable_id(@thread).to_s
30
+
31
+ @commontable_url = ApplicationController.commontable_url
32
+
33
+ params = Hash.new
34
+ params[:comment] = @comment
35
+ params[:thread] = @thread
36
+ params[:creator] = @creator
37
+ params[:commontable] = @commontable
38
+ params[:config] = @config
39
+ params[:creator_name] = @creator_name
40
+ params[:comment_timestamp] = @comment_timestamp
41
+ params[:commontable_name] = @commontable_name
42
+ params[:commontable_id] = @commontable_id
43
+ params[:commontable_url] = @commontable_url
44
+
45
+ @bcc = recipients.collect{|s| commontator_email(s)}
46
+ @from = @config.subscription_email_from_proc.call(params)
47
+ @subject = @config.subscription_email_subject_proc.call(params)
48
+ end
49
+ end
50
+ end
@@ -2,16 +2,14 @@ module Commontator
2
2
  class Comment < ActiveRecord::Base
3
3
  belongs_to :creator, :polymorphic => true
4
4
  belongs_to :editor, :polymorphic => true
5
-
6
5
  belongs_to :thread
7
6
 
8
7
  has_one :commontable, :through => :thread
9
8
 
10
- attr_accessible :body
9
+ attr_accessible :body if respond_to?(:attr_accessible)
11
10
 
12
11
  validates_presence_of :creator, :on => :create
13
12
  validates_presence_of :editor, :on => :update
14
-
15
13
  validates_presence_of :thread
16
14
  validates_presence_of :body
17
15
 
@@ -60,7 +58,7 @@ module Commontator
60
58
 
61
59
  def timestamp
62
60
  config = thread.config
63
- "#{config.comment_create_verb_past.capitalize} on ") + \
61
+ "#{config.comment_create_verb_past.capitalize} on " + \
64
62
  created_at.strftime(config.timestamp_format) + \
65
63
  (is_modified? ? " | Last #{config.comment_edit_verb_past} on " + \
66
64
  updated_at.strftime(config.timestamp_format) : '')
@@ -103,6 +101,4 @@ module Commontator
103
101
  can_be_voted_on? && thread.can_be_read_by?(user) && user != creator
104
102
  end
105
103
  end
106
-
107
- CommentObserver.instance
108
104
  end
@@ -4,18 +4,15 @@ module Commontator
4
4
 
5
5
  belongs_to :thread
6
6
 
7
- attr_accessible :subscriber, :thread
8
-
9
7
  validates_presence_of :subscriber, :thread
10
-
11
8
  validates_uniqueness_of :thread_id, :scope => [:subscriber_type, :subscriber_id]
12
9
 
13
10
  def mark_as_read
14
- self.update_attribute(:unread, 0)
11
+ update_attribute(:unread, 0)
15
12
  end
16
13
 
17
14
  def add_unread
18
- self.update_attribute(:unread, unread + 1)
15
+ update_attribute(:unread, unread + 1)
19
16
  end
20
17
  end
21
18
  end
@@ -1,17 +1,12 @@
1
1
  module Commontator
2
2
  class Thread < ActiveRecord::Base
3
3
  belongs_to :closer, :polymorphic => true
4
-
5
4
  belongs_to :commontable, :polymorphic => true
6
5
 
7
6
  has_many :comments, :dependent => :destroy
8
-
9
7
  has_many :subscriptions, :dependent => :destroy
10
8
 
11
- attr_accessible :is_closed
12
-
13
9
  validates_presence_of :commontable, :unless => :is_closed?
14
-
15
10
  validates_uniqueness_of :commontable_id, :scope => :commontable_type, :allow_nil => true
16
11
 
17
12
  def config
@@ -28,6 +23,7 @@ module Commontator
28
23
  end
29
24
 
30
25
  def subscribers
26
+ subscriptions.collect{|s| s.subscriber}
31
27
  end
32
28
 
33
29
  def active_subscribers
@@ -45,8 +41,10 @@ module Commontator
45
41
 
46
42
  def subscribe(subscriber)
47
43
  return false if is_subscribed?(subscriber) || !subscriber.is_commontator
48
- subscription = Subscription.create(
49
- :subscriber => subscriber, :thread => self)
44
+ subscription = Subscription.new
45
+ subscription.subscriber = subscriber
46
+ subscription.thread => self
47
+ subscription.save
50
48
  end
51
49
 
52
50
  def unsubscribe(subscriber)
@@ -0,0 +1,30 @@
1
+ <% # Clients of this partial must supply the following variables:
2
+ # comment
3
+ # user
4
+ %>
5
+
6
+ <% can_edit = comment.can_be_edited_by?(user)
7
+ can_delete = comment.can_be_deleted_by?(user) %>
8
+
9
+ <% if can_edit %>
10
+ <%= link_to 'Edit', commontator.edit_comment_path(comment),
11
+ :id => "comment_#{comment.id.to_s}_edit_link",
12
+ :class => "comment_edit_link",
13
+ :remote => true %>
14
+ <% end %>
15
+
16
+ &nbsp;
17
+
18
+ <% if can_delete %>
19
+ <% is_deleted = comment.is_deleted? %>
20
+ <% del_string = is_deleted ? "undelete" : "delete" %>
21
+ <%= link_to del_string.capitalize,
22
+ commontator.polymorphic_path([del_string, comment]),
23
+ :confirm => (!is_deleted ? \
24
+ "Are you sure you want to delete this " + \
25
+ "#{comment.thread.config.comment_name}?" : nil),
26
+ :method => :put,
27
+ :id => "comment_#{comment.id.to_s}_#{del_string}_link",
28
+ :class => "comment_#{del_string}_link",
29
+ :remote => true %>
30
+ <% end %>
@@ -5,7 +5,7 @@
5
5
 
6
6
  <% if comment.can_be_voted_on? %>
7
7
  <% can_vote = comment.can_be_voted_on_by?(user) %>
8
- <% vote = comment.get_vote_from(user) %>
8
+ <% vote = comment.get_vote_by(user) %>
9
9
 
10
10
  <span id="comment_<%= comment.id %>_upvote_span" class="comment_upvote">
11
11
  <% if can_vote && (vote.blank? || !vote.vote_flag) %>
@@ -0,0 +1,20 @@
1
+ <% # Clients of this partial must supply the following variables:
2
+ # thread
3
+ # user
4
+ %>
5
+
6
+ <% subscription = thread.subscription_for(user) %>
7
+
8
+ <% if thread.can_be_read_by?(user) %>
9
+ <%= stylesheet_link_tag "commontator/application.CSS", :media => "all" %>
10
+
11
+ <div id="thread_<%= thread.id %>_div" class="thread" style="display: none;">
12
+ <% if @commontator_thread_show %>
13
+ <%= render :partial => 'commontator/threads/show', :locals => {:thread => thread,
14
+ :user => user} %>
15
+ <% else %>
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 %>
18
+ <% end %>
19
+ </div>
20
+ <% end %>
@@ -0,0 +1,16 @@
1
+ <% # Clients of this partial must supply the following variable:
2
+ # thread
3
+ # user
4
+ %>
5
+
6
+ <% is_subscribed = thread.is_subscribed?(user) %>
7
+ <% sub_string = is_subscribed ? "unsubscribe" : "subscribe" %>
8
+ <%= link_to sub_string.capitalize,
9
+ commontator.polymorphic_path([sub_string, thread]),
10
+ :confirm => (is_subscribed ? \
11
+ "Are you sure you want to unsubscribe from this thread?" : \
12
+ nil),
13
+ :method => :put,
14
+ :id => "thread_#{thread.id.to_s}_#{sub_string}_link",
15
+ :class => "thread_#{sub_string}_link",
16
+ :remote => true %>