commontator 0.4.1 → 0.5.12
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +35 -23
- data/app/assets/stylesheets/commontator/comments.css +1 -1
- data/app/assets/stylesheets/commontator/comments.css~ +0 -4
- data/app/controllers/commontator/application_controller.rb +4 -5
- data/app/controllers/commontator/application_controller.rb~ +5 -5
- data/app/controllers/commontator/comments_controller.rb +30 -30
- data/app/controllers/commontator/comments_controller.rb~ +31 -31
- data/app/controllers/commontator/subscriptions_controller.rb +8 -7
- data/app/controllers/commontator/subscriptions_controller.rb~ +6 -7
- data/app/controllers/commontator/threads_controller.rb +8 -9
- data/app/controllers/commontator/threads_controller.rb~ +9 -10
- data/app/helpers/commontator/comments_helper.rb~ +14 -24
- data/app/helpers/commontator/subscriptions_helper.rb~ +3 -3
- data/app/helpers/commontator/threads_helper.rb +0 -8
- data/app/helpers/commontator/threads_helper.rb~ +5 -5
- data/app/mailers/commontator/subscriptions_mailer.rb +8 -8
- data/app/mailers/commontator/subscriptions_mailer.rb~ +9 -10
- data/app/models/commontator/comment.rb +14 -6
- data/app/models/commontator/comment.rb~ +15 -12
- data/app/views/commontator/comments/_actions.html.erb +6 -5
- data/app/views/commontator/comments/_actions.html.erb~ +6 -5
- data/app/views/commontator/comments/_body.html.erb +2 -1
- data/app/views/commontator/comments/_body.html.erb~ +1 -2
- data/app/views/commontator/comments/_form.html.erb +8 -3
- data/app/views/commontator/comments/_form.html.erb~ +7 -4
- data/app/views/commontator/comments/_show.html.erb +11 -8
- data/app/views/commontator/comments/_show.html.erb~ +11 -8
- data/app/views/commontator/comments/_votes.html.erb +7 -6
- data/app/views/commontator/comments/create.js.erb +4 -2
- data/app/views/commontator/comments/delete.js.erb +5 -3
- data/app/views/commontator/comments/delete.js.erb~ +5 -3
- data/app/views/commontator/comments/update.js.erb +1 -1
- data/app/views/commontator/comments/update.js.erb~ +1 -1
- data/app/views/commontator/comments/vote.js.erb +2 -1
- data/app/views/commontator/shared/_thread.html.erb +17 -0
- data/app/views/commontator/shared/_thread.html.erb~ +16 -0
- data/app/views/commontator/shared/_thread_link.html.erb~ +16 -0
- data/app/views/commontator/subscriptions/_link.html.erb +3 -2
- data/app/views/commontator/subscriptions/subscribe.js.erb +2 -1
- data/app/views/commontator/subscriptions_mailer/comment_created_email.html.erb +1 -1
- data/app/views/commontator/threads/_show.html.erb +18 -11
- data/app/views/commontator/threads/_show.html.erb~ +18 -11
- data/app/views/commontator/threads/show.js.erb +2 -1
- data/config/initializers/commontator.rb +14 -14
- data/db/migrate/0_install_commontator.rb +3 -3
- data/lib/commontator.rb +5 -6
- data/lib/commontator.rb~ +5 -6
- data/lib/commontator/acts_as_commontable.rb +2 -0
- data/lib/commontator/acts_as_commontator.rb +2 -0
- data/lib/commontator/controller_includes.rb +23 -0
- data/lib/commontator/controller_includes.rb~ +23 -0
- data/lib/commontator/shared_helper.rb +42 -0
- data/lib/commontator/shared_helper.rb~ +42 -0
- data/lib/commontator/shared_methods.rb~ +24 -0
- data/lib/commontator/version.rb +1 -1
- data/lib/commontator/version.rb~ +1 -1
- data/test/dummy/config/initializers/commontator.rb +15 -15
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/1_install_commontator.commontator.rb +3 -3
- data/test/dummy/db/schema.rb +3 -3
- data/test/dummy/log/development.log +64 -0
- metadata +10 -70
- data/app/assets/stylesheets/commontator/application.css~ +0 -88
- data/app/assets/stylesheets/commontator/threads.css~ +0 -13
- data/app/helpers/commontator/application_helper.rb~ +0 -11
- data/app/helpers/commontator/comments_helper.rb +0 -51
- data/app/helpers/commontator/commontable_helper.rb~ +0 -9
- data/app/helpers/commontator/commontator_helper.rb +0 -8
- data/app/helpers/commontator/commontator_helper.rb~ +0 -8
- data/app/helpers/commontator/subscriptions_helper.rb +0 -8
- data/app/mailers/commontator/subscription_mailer.rb~ +0 -38
- data/app/models/commontator/subscription.rb~ +0 -21
- data/app/models/commontator/thread.rb~ +0 -143
- data/app/views/commontator/comments/_votes.html.erb~ +0 -62
- data/app/views/commontator/comments/create.js.erb~ +0 -15
- data/app/views/commontator/comments/destroy.js.erb~ +0 -1
- data/app/views/commontator/comments/edit.html.erb~ +0 -6
- data/app/views/commontator/comments/edit.js.erb~ +0 -5
- data/app/views/commontator/comments/new.html.erb~ +0 -8
- data/app/views/commontator/comments/new.js.erb~ +0 -12
- data/app/views/commontator/comments/vote.js.erb~ +0 -5
- data/app/views/commontator/shared/_thread_link.html.erb +0 -13
- data/app/views/commontator/subscriptions/_index.html.erb~ +0 -16
- data/app/views/commontator/subscriptions/_link.html.erb~ +0 -15
- data/app/views/commontator/subscriptions/_subscription_link.html.erb~ +0 -13
- data/app/views/commontator/subscriptions/create.js.erb~ +0 -5
- data/app/views/commontator/subscriptions/destroy.js.erb~ +0 -3
- data/app/views/commontator/subscriptions/index.html.erb~ +0 -16
- data/app/views/commontator/subscriptions/subscribe.js.erb~ +0 -5
- data/app/views/commontator/subscriptions_mailer/comment_created_email.html.erb~ +0 -6
- data/app/views/commontator/threads/_actions.html.erb~ +0 -28
- data/app/views/commontator/threads/_link.html.erb~ +0 -14
- data/app/views/commontator/threads/close.js.erb~ +0 -5
- data/app/views/commontator/threads/show.html.erb~ +0 -3
- data/app/views/commontator/threads/show.js.erb~ +0 -6
- data/config/initializers/commontator.rb~ +0 -179
- data/config/routes.rb~ +0 -24
- data/db/migrate/0_install_commontator.rb~ +0 -48
- data/lib/commontator/acts_as_commontable.rb~ +0 -39
- data/lib/commontator/acts_as_commontator.rb~ +0 -28
- data/lib/commontator/commontable_config.rb~ +0 -13
- data/lib/commontator/commontator_config.rb~ +0 -13
- data/lib/commontator/routes.rb~ +0 -37
- data/lib/tasks/commontator_tasks.rake~ +0 -41
- data/test/dummy/config/initializers/commontator.rb~ +0 -179
- data/test/dummy/config/routes.rb~ +0 -3
- data/test/functional/comment_thread_subscriptions_controller_test.rb~ +0 -125
- data/test/functional/comments_controller_test.rb~ +0 -184
- data/test/functional/subscriptions_controller_test.rb~ +0 -122
- data/test/unit/comment_test.rb~ +0 -38
- data/test/unit/comment_thread_subscription_test.rb~ +0 -18
- data/test/unit/comment_thread_test.rb~ +0 -60
- data/test/unit/helpers/comment_thread_subscriptions_helper_test.rb~ +0 -7
- data/test/unit/helpers/comments_helper_test.rb~ +0 -7
- data/test/unit/helpers/subscriptions_helper_test.rb~ +0 -4
- data/test/unit/subscription_test.rb~ +0 -15
- 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
|
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?(@
|
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(@
|
11
|
+
unless @thread.subscribe(@user)
|
11
12
|
|
12
13
|
respond_to do |format|
|
13
|
-
format.html { redirect_to @
|
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?(@
|
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(@
|
25
|
+
unless @thread.unsubscribe(@user)
|
25
26
|
|
26
27
|
respond_to do |format|
|
27
|
-
format.html { redirect_to @
|
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
|
-
|
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?(@
|
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(@
|
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?(@
|
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(@
|
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
|
-
|
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?(@
|
18
|
+
raise SecurityTransgression unless @thread.can_be_edited_by?(@user)
|
20
19
|
|
21
|
-
@thread.close(@
|
22
|
-
@thread.thread_closed_callback(@
|
20
|
+
@thread.close(@user)
|
21
|
+
@thread.thread_closed_callback(@user)
|
23
22
|
|
24
23
|
respond_to do |format|
|
25
|
-
format.html { redirect_to @
|
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?(@
|
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 @
|
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
|
-
|
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
|
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?(@
|
18
|
+
raise SecurityTransgression unless @thread.can_be_edited_by?(@user)
|
20
19
|
|
21
|
-
@thread.close(@
|
22
|
-
@thread.thread_closed_callback(@
|
20
|
+
@thread.close(@user)
|
21
|
+
@thread.thread_closed_callback(@user)
|
23
22
|
|
24
23
|
respond_to do |format|
|
25
|
-
format.html { redirect_to
|
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?(@
|
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
|
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(
|
4
|
-
|
5
|
-
|
6
|
-
config
|
7
|
-
|
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
|
27
|
-
|
28
|
-
|
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(
|
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
|
41
|
-
|
42
|
-
return '' if
|
43
|
-
config =
|
44
|
-
name =
|
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
|
4
|
-
config =
|
5
|
-
config.email_method.blank? ? '' :
|
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
|
-
|
16
|
-
return Commontator.
|
17
|
-
config =
|
18
|
-
config.
|
19
|
-
|
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
|
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
|
-
@
|
19
|
+
@creator = @comment.creator
|
20
20
|
|
21
|
-
@bcc = @thread.subscribers.reject{|s| s == @
|
22
|
-
.collect{|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
|
-
@
|
30
|
-
@comment_timestamp =
|
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[:
|
40
|
+
params[:creator] = @creator
|
41
41
|
params[:commontable] = @commontable
|
42
42
|
params[:config] = @config
|
43
|
-
params[:
|
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
|
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
|
-
@
|
18
|
+
@creator = @comment.creator
|
20
19
|
|
21
|
-
@bcc = @thread.subscribers.reject{|s| s == @
|
22
|
-
.collect{|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
|
-
@
|
30
|
-
@comment_timestamp =
|
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[:
|
39
|
+
params[:creator] = @creator
|
41
40
|
params[:commontable] = @commontable
|
42
41
|
params[:config] = @config
|
43
|
-
params[:
|
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 :
|
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 :
|
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 ==
|
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 ==
|
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 ==
|
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 !=
|
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 :
|
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
|
-
|
9
|
-
|
10
|
-
|
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 ==
|
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 ==
|
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 ==
|
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 !=
|
82
|
+
thread.can_be_read_by?(user) && user != creator
|
80
83
|
end
|
81
84
|
end
|
82
85
|
end
|