commontator 4.5.4 → 4.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -13
- data/MIT-LICENSE +2 -1
- data/README.md +31 -34
- data/Rakefile +3 -2
- data/app/assets/stylesheets/commontator/application.css +1 -0
- data/app/assets/stylesheets/commontator/comments.css +1 -0
- data/app/assets/stylesheets/commontator/threads.css +13 -7
- data/{spec/dummy/tmp/cache/assets/test/sprockets/a473b3873e554893372a53d71f5e9879 → app/assets/stylesheets/commontator/threads.css~} +0 -0
- data/app/controllers/commontator/application_controller.rb +14 -14
- data/app/controllers/commontator/application_controller.rb~ +35 -0
- data/app/controllers/commontator/comments_controller.rb +8 -7
- data/app/controllers/commontator/comments_controller.rb~ +153 -0
- data/app/controllers/commontator/subscriptions_controller.rb +1 -0
- data/app/controllers/commontator/threads_controller.rb +7 -2
- data/app/helpers/commontator/application_helper.rb +1 -0
- data/app/mailers/commontator/subscriptions_mailer.rb +8 -10
- data/app/mailers/commontator/subscriptions_mailer.rb~ +44 -0
- data/app/models/commontator/comment.rb +14 -13
- data/app/models/commontator/comment.rb~ +119 -0
- data/app/models/commontator/subscription.rb +8 -4
- data/app/models/commontator/thread.rb +64 -43
- data/app/models/commontator/thread.rb~ +159 -0
- data/app/views/commontator/comments/_actions.html.erb +1 -0
- data/app/views/commontator/comments/_body.html.erb +2 -1
- data/app/views/commontator/comments/_form.html.erb +5 -1
- data/app/views/commontator/comments/_form.html.erb~ +39 -0
- data/app/views/commontator/comments/_list.html.erb +1 -1
- data/app/views/commontator/comments/_show.html.erb +5 -3
- data/app/views/commontator/comments/_show.html.erb~ +49 -0
- data/app/views/commontator/comments/_votes.html.erb +2 -1
- data/app/views/commontator/comments/_votes.html.erb~ +69 -0
- data/app/views/commontator/comments/cancel.js.erb +1 -0
- data/app/views/commontator/comments/create.js.erb +6 -4
- data/app/views/commontator/comments/create.js.erb~ +14 -0
- data/app/views/commontator/comments/delete.js.erb +1 -0
- data/app/views/commontator/comments/edit.js.erb +1 -0
- data/app/views/commontator/comments/new.js.erb +3 -1
- data/app/views/commontator/comments/new.js.erb~ +13 -0
- data/app/views/commontator/comments/update.js.erb +1 -0
- data/app/views/commontator/comments/vote.js.erb +1 -0
- data/app/views/commontator/shared/_thread.html.erb +4 -5
- data/app/views/commontator/subscriptions/_link.html.erb +2 -1
- data/app/views/commontator/subscriptions/_link.html.erb~ +16 -0
- data/app/views/commontator/subscriptions/subscribe.js.erb +1 -0
- data/app/views/commontator/subscriptions_mailer/comment_created.html.erb +1 -0
- data/app/views/commontator/threads/_reply.html.erb +4 -2
- data/app/views/commontator/threads/_reply.html.erb~ +19 -0
- data/app/views/commontator/threads/_show.html.erb +44 -9
- data/app/views/commontator/threads/_show.html.erb~ +95 -0
- data/app/views/commontator/threads/_show.js.erb +19 -0
- data/app/views/commontator/threads/show.js.erb +4 -4
- data/config/initializers/commontator.rb +169 -132
- data/config/initializers/commontator.rb~ +238 -0
- data/config/locales/commontator/en.yml +12 -3
- data/config/locales/commontator/en.yml~ +104 -0
- data/config/routes.rb +1 -0
- data/db/migrate/0_install_commontator.rb +9 -11
- data/db/migrate/0_install_commontator.rb~ +54 -0
- data/lib/commontator.rb +57 -16
- data/lib/commontator.rb~ +142 -0
- data/lib/commontator/acts_as_commontable.rb +12 -14
- data/lib/commontator/acts_as_commontator.rb +1 -16
- data/lib/commontator/commontable_config.rb +1 -0
- data/lib/commontator/commontator_config.rb +1 -0
- data/lib/commontator/controller_includes.rb +3 -3
- data/lib/commontator/engine.rb +1 -0
- data/lib/commontator/link_renderer.rb +29 -0
- data/lib/commontator/security_transgression.rb +1 -0
- data/lib/commontator/shared_helper.rb +7 -5
- data/lib/commontator/version.rb +2 -1
- data/lib/tasks/commontator_tasks.rake +1 -0
- data/spec/app/controllers/commontator/comments_controller_spec.rb +12 -11
- data/spec/app/controllers/commontator/subscriptions_controller_spec.rb +2 -1
- data/spec/app/controllers/commontator/threads_controller_spec.rb +2 -1
- data/spec/app/helpers/commontator/application_helper_spec.rb +2 -1
- data/spec/app/mailers/commontator/subscriptions_mailer_spec.rb +2 -1
- data/spec/app/models/commontator/comment_spec.rb +18 -11
- data/spec/app/models/commontator/comment_spec.rb~ +74 -0
- data/spec/app/models/commontator/subscription_spec.rb +18 -8
- data/spec/app/models/commontator/thread_spec.rb +28 -42
- data/spec/dummy/README.md +1 -0
- data/spec/dummy/Rakefile +1 -0
- data/spec/dummy/app/assets/javascripts/application.js +1 -0
- data/spec/dummy/app/assets/stylesheets/application.css +1 -0
- data/spec/dummy/app/controllers/application_controller.rb +1 -0
- data/spec/dummy/app/controllers/dummy_models_controller.rb +1 -0
- data/spec/dummy/app/helpers/application_helper.rb +1 -0
- data/spec/dummy/app/models/dummy_model.rb +1 -0
- data/spec/dummy/app/models/dummy_user.rb +7 -2
- data/spec/dummy/app/models/dummy_user.rb~ +16 -0
- data/spec/dummy/app/views/dummy_model/show.html.erb +1 -0
- data/spec/dummy/app/views/layouts/application.html.erb +1 -0
- data/spec/dummy/config.ru +1 -0
- data/spec/dummy/config/boot.rb +1 -0
- data/spec/dummy/config/database.yml +1 -0
- data/spec/dummy/config/environment.rb +1 -0
- data/spec/dummy/config/environments/development.rb +1 -0
- data/spec/dummy/config/environments/production.rb +1 -0
- data/spec/dummy/config/environments/test.rb +1 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +1 -0
- data/spec/dummy/config/initializers/commontator.rb +6 -1
- data/spec/dummy/config/initializers/commontator.rb~ +15 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +1 -0
- data/spec/dummy/config/initializers/inflections.rb +1 -0
- data/spec/dummy/config/initializers/mime_types.rb +1 -0
- data/spec/dummy/config/initializers/secret_token.rb +1 -0
- data/spec/dummy/config/initializers/session_store.rb +1 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +1 -0
- data/spec/dummy/config/routes.rb +1 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/1_create_dummy_models.rb +1 -0
- data/spec/dummy/db/migrate/2_create_dummy_users.rb +1 -0
- data/spec/dummy/db/migrate/3_acts_as_votable_migration.rb +1 -0
- data/spec/dummy/db/schema.rb +10 -13
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/public/404.html +1 -0
- data/spec/dummy/public/422.html +1 -0
- data/spec/dummy/public/500.html +1 -0
- data/spec/dummy/script/rails +1 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/{72b63dddbc5c995f79af8e3c94904fd9 → 02d4b791eb831cf2057bf4703a1218d1} +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/{a77b1a9223d168112e1705c29220116f → 0f196a1a50363b0a076ec6e1ee5417f6} +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/a3fb9025f90ff05a6fd4afc7ded2692c +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/a41c8be5379abec3c0d0d98e2f0d5609 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/c69ee3cc5796188d873574179290a6ef +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/{f721383d531f067d82b071e14aed7a92 → e1f674c11941d62aac1764ef3a7134e4} +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/{d2244ccef8e05bb993f75715af0344cc → e85565206c3e5fdf9dfeb367c85557b1} +0 -0
- data/spec/lib/commontator/acts_as_commontable_spec.rb +3 -2
- data/spec/lib/commontator/acts_as_commontator_spec.rb +2 -5
- data/spec/lib/commontator/commontable_config_spec.rb +8 -5
- data/spec/lib/commontator/commontator_config_spec.rb +2 -1
- data/spec/lib/commontator/controller_includes_spec.rb +2 -1
- data/spec/lib/commontator/shared_helper_spec.rb +2 -1
- data/spec/lib/commontator_spec.rb +2 -1
- data/spec/{test_helper.rb → spec_helper.rb} +0 -0
- metadata +154 -135
- data/lib/commontator/remote_link_renderer.rb +0 -10
- data/spec/dummy/config/locales/en.yml +0 -23
- data/spec/dummy/log/development.log +0 -36
- data/spec/dummy/log/test.log +0 -22683
- data/spec/dummy/tmp/cache/assets/test/sprockets/afa63eb365bdf4f42584b17ac9176b9d +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/decb63cac838a5314aa0c22a979f5ac9 +0 -0
checksums.yaml
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
|
|
5
|
-
data.tar.gz: !binary |-
|
|
6
|
-
ZjdmMjgxN2RmNjFkNDY5MDIxZTQ1NjM1Mjk4NjU0MWVkMGZkMjQwMA==
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 4beac087c18e25ec5801db3cf8d93065820dea56
|
|
4
|
+
data.tar.gz: c7c24346e146b94fd52d52721249078b6f4da002
|
|
7
5
|
SHA512:
|
|
8
|
-
metadata.gz:
|
|
9
|
-
|
|
10
|
-
NWNlMDdjNDc4ZTkyZWU1NTQyY2IxODFjYTk1OTkwMDMyOWM2ZjRhMDNmZWJm
|
|
11
|
-
Y2Q2ZmZmNzZlZjk3MjM1M2NhOGE4MmYzMjgwZWRhOWQwOWQxZTc=
|
|
12
|
-
data.tar.gz: !binary |-
|
|
13
|
-
ZjVhOWJiZDI5MzE5YjU0OThkMTY4MmZlMWZhMmE4MTFjOGNhY2U4ZDMxMjEz
|
|
14
|
-
NmYzYzk1YTdhZDU3NzBjOTU1ZDg2OWRmMWQyODM5MDc3OTVjN2Q4YTYxZjI0
|
|
15
|
-
OTA3NDM0NjA4NDk1Y2U0ODZkYWI5MTI2YjdiZTdhMTcxYzgyYjg=
|
|
6
|
+
metadata.gz: d1e5dd9cc40f73bfa294774ed4b08e9262ab7e9d434306e6d44bf5a38647771ebf8ae9553d18935fc265c8630075aa4890672a93ce3fba0ae2118a89c6548afc
|
|
7
|
+
data.tar.gz: 775b2d53d9da20a6814f6dbcbfbff4c3314f7163120a81a8ee3f8ea95e88be049ac9706e6582b12be403033068409913e817f67397946b1c951616f702259a28
|
data/MIT-LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright 2012-
|
|
1
|
+
Copyright 2012-14 Rice University
|
|
2
2
|
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
4
|
a copy of this software and associated documentation files (the
|
|
@@ -18,3 +18,4 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
18
18
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
19
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
20
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
21
|
+
|
data/README.md
CHANGED
|
@@ -13,43 +13,35 @@ There are 4 steps you must follow to install commontator:
|
|
|
13
13
|
|
|
14
14
|
Add this line to your application's Gemfile:
|
|
15
15
|
|
|
16
|
-
```
|
|
17
|
-
gem 'commontator', '~> 4.
|
|
16
|
+
```rb
|
|
17
|
+
gem 'commontator', '~> 4.6.0'
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
And then execute:
|
|
21
21
|
|
|
22
22
|
```sh
|
|
23
|
-
$ bundle
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
Or install it yourself as:
|
|
27
|
-
|
|
28
|
-
```sh
|
|
29
|
-
$ gem install commontator
|
|
23
|
+
$ bundle install
|
|
30
24
|
```
|
|
31
25
|
|
|
32
26
|
2. Initializer and Migration
|
|
33
27
|
|
|
34
|
-
Run the following command to copy commontator's initializer and migration to your
|
|
28
|
+
Run the following command to copy commontator's initializer and migration to your app:
|
|
35
29
|
|
|
36
30
|
```sh
|
|
37
31
|
$ rake commontator:install
|
|
38
32
|
```
|
|
39
33
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
```sh
|
|
43
|
-
$ rake db:migrate
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
Or run each rake task manually:
|
|
34
|
+
Or alternatively:
|
|
47
35
|
|
|
48
36
|
```sh
|
|
49
37
|
$ rake commontator:install:initializers
|
|
50
38
|
|
|
51
39
|
$ rake commontator:install:migrations
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
And then execute:
|
|
52
43
|
|
|
44
|
+
```sh
|
|
53
45
|
$ rake db:migrate
|
|
54
46
|
```
|
|
55
47
|
|
|
@@ -57,12 +49,13 @@ There are 4 steps you must follow to install commontator:
|
|
|
57
49
|
|
|
58
50
|
Change commontator's configurations to suit your needs by editing `config/initializers/commontator.rb`.
|
|
59
51
|
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.
|
|
52
|
+
If you have deprecated options in your initializer, Commontator will issue warnings (usually printed to your console).
|
|
60
53
|
|
|
61
54
|
4. Routes
|
|
62
55
|
|
|
63
|
-
Add this line to your application's routes file:
|
|
56
|
+
Add this line to your Rails application's routes file:
|
|
64
57
|
|
|
65
|
-
```
|
|
58
|
+
```rb
|
|
66
59
|
mount Commontator::Engine => '/commontator'
|
|
67
60
|
```
|
|
68
61
|
|
|
@@ -76,43 +69,46 @@ Follow the steps below to add commontator to your models and views:
|
|
|
76
69
|
|
|
77
70
|
Add this line to your user model(s) (or any models that should be able to post comments):
|
|
78
71
|
|
|
79
|
-
```
|
|
72
|
+
```rb
|
|
80
73
|
acts_as_commontator
|
|
81
74
|
```
|
|
82
75
|
|
|
83
|
-
Add this line to any models you want to be able to comment on:
|
|
76
|
+
Add this line to any models you want to be able to comment on (i.e. models that have comment threads):
|
|
84
77
|
|
|
85
|
-
```
|
|
78
|
+
```rb
|
|
86
79
|
acts_as_commontable
|
|
87
80
|
```
|
|
88
81
|
|
|
89
82
|
2. Views
|
|
90
83
|
|
|
91
|
-
In the following instructions,
|
|
84
|
+
In the following instructions, `@commontable` is an instance of a model that `acts_as_commontable`.
|
|
85
|
+
You must supply this variable to the views that will use Commontator.
|
|
92
86
|
|
|
93
|
-
|
|
87
|
+
Wherever you would like to display comments, call `commontator_thread(@commontable)`:
|
|
94
88
|
|
|
95
89
|
```erb
|
|
96
|
-
<%= commontator_thread(commontable) %>
|
|
90
|
+
<%= commontator_thread(@commontable) %>
|
|
97
91
|
```
|
|
98
92
|
|
|
99
|
-
This will create a link
|
|
93
|
+
This will create a link that can be clicked to display the comment thread.
|
|
100
94
|
|
|
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
|
|
95
|
+
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 views.
|
|
96
|
+
We recommend you use this in the model's `show.html.erb` view or the equivalent for your app.
|
|
103
97
|
|
|
104
98
|
3. Controllers
|
|
105
99
|
|
|
106
|
-
By default, the `commontator_thread` method only
|
|
107
|
-
|
|
100
|
+
By default, the `commontator_thread` method only provides a link to the desired comment thread.
|
|
101
|
+
Sometimes it may be desirable to have the thread display right away when the corresponding page is loaded.
|
|
102
|
+
In that case, just add the following method call to the controller action that displays the page in question:
|
|
108
103
|
|
|
109
|
-
```
|
|
104
|
+
```rb
|
|
110
105
|
commontator_thread_show(commontable)
|
|
111
106
|
```
|
|
112
107
|
|
|
113
108
|
Note that the call to `commontator_thread` in the view is still necessary in either case.
|
|
114
109
|
|
|
115
|
-
The `commontator_thread_show` method checks the current user's read permission on the thread and will raise
|
|
110
|
+
The `commontator_thread_show` method checks the current user's read permission on the thread and will raise a
|
|
111
|
+
Commontator::SecurityTransgression exception if the user is not allowed to read it, according to the options in the initializer.
|
|
116
112
|
It is up to you to ensure that this method is only called if the user is authorized to read the thread.
|
|
117
113
|
|
|
118
114
|
That's it! Commontator is now ready for use.
|
|
@@ -121,13 +117,13 @@ That's it! Commontator is now ready for use.
|
|
|
121
117
|
|
|
122
118
|
You can allow users to vote on each others' comments by adding the `acts_as_votable` gem to your gemfile:
|
|
123
119
|
|
|
124
|
-
```
|
|
120
|
+
```rb
|
|
125
121
|
gem 'acts_as_votable'
|
|
126
122
|
```
|
|
127
123
|
|
|
128
124
|
And enabling the relevant option in commontator's initializer:
|
|
129
125
|
|
|
130
|
-
```
|
|
126
|
+
```rb
|
|
131
127
|
config.can_vote_on_comments = true
|
|
132
128
|
```
|
|
133
129
|
|
|
@@ -215,3 +211,4 @@ $ bundle exec rake
|
|
|
215
211
|
|
|
216
212
|
This gem is distributed under the terms of the MIT license.
|
|
217
213
|
See the MIT-LICENSE file for details.
|
|
214
|
+
|
data/Rakefile
CHANGED
|
@@ -12,11 +12,12 @@ Bundler::GemHelper.install_tasks
|
|
|
12
12
|
|
|
13
13
|
require 'rake/testtask'
|
|
14
14
|
|
|
15
|
-
Rake::TestTask.new(:
|
|
15
|
+
Rake::TestTask.new(:spec => 'app:db:test:prepare') do |t|
|
|
16
16
|
t.libs << 'lib'
|
|
17
17
|
t.libs << 'spec'
|
|
18
18
|
t.pattern = 'spec/**/*_spec.rb'
|
|
19
19
|
t.verbose = false
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
task :default => :
|
|
22
|
+
task :default => :spec
|
|
23
|
+
|
|
@@ -25,14 +25,19 @@
|
|
|
25
25
|
|
|
26
26
|
/* Modified from:
|
|
27
27
|
http://www.strangerstudios.com/sandbox/pagination/diggstyle.php */
|
|
28
|
-
.
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
.thread_page_entries_info {
|
|
29
|
+
margin-top: 10px;
|
|
30
|
+
margin-bottom: 10px;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.thread_will_paginate {
|
|
34
|
+
margin-top: 10px;
|
|
35
|
+
margin-bottom: 10px;
|
|
31
36
|
}
|
|
32
37
|
|
|
33
38
|
.thread_pagination a {
|
|
34
39
|
padding: 2px 5px 2px 5px;
|
|
35
|
-
margin:
|
|
40
|
+
margin-right: 4px;
|
|
36
41
|
border: 1px solid #999;
|
|
37
42
|
|
|
38
43
|
text-decoration: none;
|
|
@@ -48,7 +53,7 @@ http://www.strangerstudios.com/sandbox/pagination/diggstyle.php */
|
|
|
48
53
|
|
|
49
54
|
.thread_pagination em {
|
|
50
55
|
padding: 2px 5px 2px 5px;
|
|
51
|
-
margin:
|
|
56
|
+
margin-right: 4px;
|
|
52
57
|
border: 1px solid #555;
|
|
53
58
|
|
|
54
59
|
font-weight: bold;
|
|
@@ -58,8 +63,9 @@ http://www.strangerstudios.com/sandbox/pagination/diggstyle.php */
|
|
|
58
63
|
|
|
59
64
|
.thread_pagination span {
|
|
60
65
|
padding: 2px 5px 2px 5px;
|
|
61
|
-
|
|
66
|
+
margin-right: 4px;
|
|
62
67
|
border: 1px solid #EEE;
|
|
63
68
|
|
|
64
69
|
color: #DDD;
|
|
65
|
-
}
|
|
70
|
+
}
|
|
71
|
+
|
|
Binary file
|
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
module Commontator
|
|
2
2
|
class ApplicationController < ActionController::Base
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
cattr_reader :app_routes
|
|
4
|
+
|
|
5
|
+
before_filter :get_user, :ensure_user, :set_app_routes
|
|
6
6
|
|
|
7
7
|
rescue_from SecurityTransgression, :with => lambda { head(:forbidden) }
|
|
8
8
|
|
|
9
9
|
protected
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
def security_transgression_unless(check)
|
|
12
|
+
raise SecurityTransgression unless check
|
|
13
|
+
end
|
|
14
|
+
|
|
11
15
|
def get_user
|
|
12
|
-
@user = Commontator.current_user_proc.call(self)
|
|
16
|
+
@user = Commontator.current_user_proc.call(self)
|
|
13
17
|
end
|
|
14
18
|
|
|
15
19
|
def ensure_user
|
|
16
20
|
security_transgression_unless(@user && @user.is_commontator)
|
|
17
21
|
end
|
|
18
|
-
|
|
22
|
+
|
|
19
23
|
def get_thread
|
|
20
24
|
@thread = params[:thread_id].blank? ? \
|
|
21
25
|
Commontator::Thread.find(params[:id]) : \
|
|
22
26
|
Commontator::Thread.find(params[:thread_id])
|
|
23
|
-
security_transgression_unless
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def set_commontable_url
|
|
27
|
-
self.commontable_url = @thread.config.commontable_url_proc.call(
|
|
28
|
-
@thread.commontable, main_app)
|
|
27
|
+
security_transgression_unless @thread.can_be_read_by? @user
|
|
29
28
|
end
|
|
30
29
|
|
|
31
|
-
def
|
|
32
|
-
|
|
30
|
+
def set_app_routes
|
|
31
|
+
@@app_routes ||= main_app
|
|
33
32
|
end
|
|
34
33
|
end
|
|
35
34
|
end
|
|
35
|
+
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module Commontator
|
|
2
|
+
class ApplicationController < ActionController::Base
|
|
3
|
+
cattr_reader :app_routes
|
|
4
|
+
|
|
5
|
+
before_filter :get_user, :ensure_user, :set_app_routes
|
|
6
|
+
|
|
7
|
+
rescue_from SecurityTransgression, :with => lambda { head(:forbidden) }
|
|
8
|
+
|
|
9
|
+
protected
|
|
10
|
+
|
|
11
|
+
def security_transgression_unless(check)
|
|
12
|
+
raise SecurityTransgression unless check
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def get_user
|
|
16
|
+
@user = Commontator.current_user_proc.call(self)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def ensure_user
|
|
20
|
+
security_transgression_unless(@user && @user.is_commontator)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def get_thread
|
|
24
|
+
@thread = params[:thread_id].blank? ? \
|
|
25
|
+
Commontator::Thread.find(params[:id]) : \
|
|
26
|
+
Commontator::Thread.find(params[:thread_id])
|
|
27
|
+
security_transgression_unless @thread.can_be_read_by? @user
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def set_app_routes
|
|
31
|
+
@@app_routes = main_app
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
@@ -2,7 +2,6 @@ module Commontator
|
|
|
2
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
|
-
before_filter :set_commontable_url, :only => :create
|
|
6
5
|
|
|
7
6
|
# GET /threads/1/comments/new
|
|
8
7
|
def new
|
|
@@ -12,6 +11,8 @@ module Commontator
|
|
|
12
11
|
|
|
13
12
|
security_transgression_unless @comment.can_be_created_by?(@user)
|
|
14
13
|
|
|
14
|
+
@per_page = params[:per_page] || @thread.config.comments_per_page
|
|
15
|
+
|
|
15
16
|
respond_to do |format|
|
|
16
17
|
format.html { redirect_to @thread }
|
|
17
18
|
format.js
|
|
@@ -33,12 +34,11 @@ module Commontator
|
|
|
33
34
|
format.html { redirect_to @thread }
|
|
34
35
|
format.js { render :cancel }
|
|
35
36
|
elsif @comment.save
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
unless recipients.empty?
|
|
37
|
+
sub = @thread.config.thread_subscription.to_sym
|
|
38
|
+
@thread.subscribe(@user) if sub == :a || sub == :b
|
|
39
|
+
Subscription.comment_created(@comment)
|
|
40
|
+
|
|
41
|
+
@per_page = params[:per_page] || @thread.config.comments_per_page
|
|
42
42
|
|
|
43
43
|
format.html { redirect_to @thread }
|
|
44
44
|
format.js
|
|
@@ -150,3 +150,4 @@ module Commontator
|
|
|
150
150
|
end
|
|
151
151
|
end
|
|
152
152
|
end
|
|
153
|
+
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
module Commontator
|
|
2
|
+
class CommentsController < Commontator::ApplicationController
|
|
3
|
+
before_filter :get_thread, :only => [:new, :create]
|
|
4
|
+
before_filter :get_comment_and_thread, :except => [:new, :create]
|
|
5
|
+
|
|
6
|
+
# GET /threads/1/comments/new
|
|
7
|
+
def new
|
|
8
|
+
@comment = Comment.new
|
|
9
|
+
@comment.thread = @thread
|
|
10
|
+
@comment.creator = @user
|
|
11
|
+
|
|
12
|
+
security_transgression_unless @comment.can_be_created_by?(@user)
|
|
13
|
+
|
|
14
|
+
@per_page = params[:per_page] || thread.config.comments_per_page
|
|
15
|
+
|
|
16
|
+
respond_to do |format|
|
|
17
|
+
format.html { redirect_to @thread }
|
|
18
|
+
format.js
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# POST /threads/1/comments
|
|
24
|
+
def create
|
|
25
|
+
@comment = Comment.new
|
|
26
|
+
@comment.body = params[:comment].nil? ? nil : params[:comment][:body]
|
|
27
|
+
@comment.thread = @thread
|
|
28
|
+
@comment.creator = @user
|
|
29
|
+
|
|
30
|
+
security_transgression_unless @comment.can_be_created_by?(@user)
|
|
31
|
+
|
|
32
|
+
respond_to do |format|
|
|
33
|
+
if !params[:cancel].nil?
|
|
34
|
+
format.html { redirect_to @thread }
|
|
35
|
+
format.js { render :cancel }
|
|
36
|
+
elsif @comment.save
|
|
37
|
+
sub = @thread.config.thread_subscription.to_sym
|
|
38
|
+
@thread.subscribe(@user) if sub == :a || sub == :b
|
|
39
|
+
Subscription.comment_created(@comment)
|
|
40
|
+
|
|
41
|
+
@per_page = params[:per_page] || @thread.config.comments_per_page
|
|
42
|
+
|
|
43
|
+
format.html { redirect_to @thread }
|
|
44
|
+
format.js
|
|
45
|
+
else
|
|
46
|
+
format.html { redirect_to @thread }
|
|
47
|
+
format.js { render :new }
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# GET /comments/1/edit
|
|
53
|
+
def edit
|
|
54
|
+
security_transgression_unless @comment.can_be_edited_by?(@user)
|
|
55
|
+
|
|
56
|
+
respond_to do |format|
|
|
57
|
+
format.html { redirect_to @thread }
|
|
58
|
+
format.js
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# PUT /comments/1
|
|
63
|
+
def update
|
|
64
|
+
security_transgression_unless @comment.can_be_edited_by?(@user)
|
|
65
|
+
@comment.body = params[:comment].nil? ? nil : params[:comment][:body]
|
|
66
|
+
@comment.editor = @user
|
|
67
|
+
|
|
68
|
+
respond_to do |format|
|
|
69
|
+
if !params[:cancel].nil?
|
|
70
|
+
format.html { redirect_to @thread }
|
|
71
|
+
format.js { render :cancel }
|
|
72
|
+
elsif @comment.save
|
|
73
|
+
format.html { redirect_to @thread }
|
|
74
|
+
format.js
|
|
75
|
+
else
|
|
76
|
+
format.html { redirect_to @thread }
|
|
77
|
+
format.js { render :edit }
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# PUT /comments/1/delete
|
|
83
|
+
def delete
|
|
84
|
+
security_transgression_unless @comment.can_be_deleted_by?(@user)
|
|
85
|
+
|
|
86
|
+
@comment.errors.add(:base, t('commontator.comment.errors.already_deleted')) \
|
|
87
|
+
unless @comment.delete_by(@user)
|
|
88
|
+
|
|
89
|
+
respond_to do |format|
|
|
90
|
+
format.html { redirect_to @thread }
|
|
91
|
+
format.js { render :delete }
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# PUT /comments/1/undelete
|
|
96
|
+
def undelete
|
|
97
|
+
security_transgression_unless @comment.can_be_deleted_by?(@user)
|
|
98
|
+
|
|
99
|
+
@comment.errors.add(:base, t('commontator.comment.errors.not_deleted')) \
|
|
100
|
+
unless @comment.undelete_by(@user)
|
|
101
|
+
|
|
102
|
+
respond_to do |format|
|
|
103
|
+
format.html { redirect_to @thread }
|
|
104
|
+
format.js { render :delete }
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# PUT /comments/1/upvote
|
|
109
|
+
def upvote
|
|
110
|
+
security_transgression_unless @comment.can_be_voted_on_by?(@user)
|
|
111
|
+
|
|
112
|
+
@comment.upvote_from @user
|
|
113
|
+
|
|
114
|
+
respond_to do |format|
|
|
115
|
+
format.html { redirect_to @thread }
|
|
116
|
+
format.js { render :vote }
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# PUT /comments/1/downvote
|
|
121
|
+
def downvote
|
|
122
|
+
security_transgression_unless @comment.can_be_voted_on_by?(@user) &&\
|
|
123
|
+
@comment.thread.config.comment_voting.to_sym == :ld
|
|
124
|
+
|
|
125
|
+
@comment.downvote_from @user
|
|
126
|
+
|
|
127
|
+
respond_to do |format|
|
|
128
|
+
format.html { redirect_to @thread }
|
|
129
|
+
format.js { render :vote }
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
# PUT /comments/1/unvote
|
|
134
|
+
def unvote
|
|
135
|
+
security_transgression_unless @comment.can_be_voted_on_by?(@user)
|
|
136
|
+
|
|
137
|
+
@comment.unvote :voter => @user
|
|
138
|
+
|
|
139
|
+
respond_to do |format|
|
|
140
|
+
format.html { redirect_to @thread }
|
|
141
|
+
format.js { render :vote }
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
protected
|
|
146
|
+
|
|
147
|
+
def get_comment_and_thread
|
|
148
|
+
@comment = Comment.find(params[:id])
|
|
149
|
+
@thread = @comment.thread
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|