the_comments 1.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. data/.rvmrc.example +1 -0
  2. data/.travis.yml +5 -0
  3. data/README.md +105 -425
  4. data/app/assets/javascripts/the_comments.js.coffee +12 -9
  5. data/app/assets/javascripts/the_comments_manage.js.coffee +19 -49
  6. data/app/assets/stylesheets/the_comments.css.scss +20 -29
  7. data/app/controllers/_templates_/comments_controller.rb +44 -0
  8. data/app/controllers/concerns/controller.rb +216 -0
  9. data/app/helpers/render_comments_tree_helper.rb +4 -7
  10. data/app/models/_templates_/comment.rb +38 -0
  11. data/app/models/concerns/comment.rb +103 -0
  12. data/app/models/concerns/comment_states.rb +80 -0
  13. data/app/models/concerns/commentable.rb +69 -0
  14. data/app/models/concerns/user.rb +52 -0
  15. data/app/views/the_comments/_tree.html.erb +3 -0
  16. data/app/views/the_comments/haml/_additional_info.html.haml +13 -0
  17. data/app/views/the_comments/{_comment.html.haml → haml/_comment.html.haml} +0 -0
  18. data/app/views/the_comments/haml/_comment_body.html.haml +20 -0
  19. data/app/views/the_comments/haml/_comment_edit.html.haml +26 -0
  20. data/app/views/the_comments/{_form.html.haml → haml/_form.html.haml} +8 -6
  21. data/app/views/the_comments/haml/_manage_controls.html.haml +27 -0
  22. data/app/views/the_comments/haml/_sidebar.html.haml +28 -0
  23. data/app/views/the_comments/haml/_tree.html.haml +4 -0
  24. data/app/views/the_comments/haml/index.html.haml +18 -0
  25. data/app/views/the_comments/haml/manage.html.haml +25 -0
  26. data/app/views/the_comments/haml/my_comments.html.haml +28 -0
  27. data/app/views/the_comments/slim/_additional_info.html.slim +13 -0
  28. data/app/views/the_comments/slim/_comment.html.slim +1 -0
  29. data/app/views/the_comments/slim/_comment_body.html.slim +20 -0
  30. data/app/views/the_comments/slim/_comment_edit.html.slim +26 -0
  31. data/app/views/the_comments/slim/_form.html.slim +27 -0
  32. data/app/views/the_comments/slim/_manage_controls.html.slim +27 -0
  33. data/app/views/the_comments/slim/_sidebar.html.slim +28 -0
  34. data/app/views/the_comments/slim/_tree.html.slim +4 -0
  35. data/app/views/the_comments/slim/index.html.slim +18 -0
  36. data/app/views/the_comments/slim/manage.html.slim +25 -0
  37. data/app/views/the_comments/slim/my_comments.html.slim +28 -0
  38. data/{lib/generators/the_comments/templates → config/initializers}/the_comments.rb +3 -0
  39. data/config/locales/en.yml +39 -14
  40. data/config/locales/ru.yml +67 -0
  41. data/config/routes.rb +17 -13
  42. data/db/migrate/20130101010101_change_user.rb +18 -0
  43. data/db/migrate/20130101010102_create_comments.rb +50 -0
  44. data/db/migrate/20130101010103_change_commentable.rb +13 -0
  45. data/docs/admin_ui_installation.md +145 -0
  46. data/docs/advanced_installation.md +182 -0
  47. data/docs/comment_api.md +58 -0
  48. data/docs/commentable_api.md +59 -0
  49. data/docs/config_file.md +27 -0
  50. data/docs/content_preprocessors.md +73 -0
  51. data/docs/customazation_of_views.md +30 -0
  52. data/docs/denormalization_and_recent_comments.md +40 -0
  53. data/docs/documentation.md +28 -0
  54. data/docs/mountable_routes.md +80 -0
  55. data/docs/pagination.md +123 -0
  56. data/docs/screencast.jpg +0 -0
  57. data/docs/user_api.md +75 -0
  58. data/docs/what_is_comcoms.md +63 -0
  59. data/docs/whats_wrong_with_other_gems.md +18 -0
  60. data/docs/where_is_example_application.md +37 -0
  61. data/gem_version.rb +3 -0
  62. data/lib/generators/the_comments/USAGE +31 -20
  63. data/lib/generators/the_comments/the_comments_generator.rb +35 -18
  64. data/lib/generators/the_comments/views_generator.rb +52 -16
  65. data/lib/the_comments/config.rb +14 -1
  66. data/lib/the_comments/version.rb +1 -3
  67. data/lib/the_comments.rb +10 -0
  68. data/spec/dummy_app/.gitignore +17 -0
  69. data/spec/dummy_app/.rspec +1 -0
  70. data/spec/dummy_app/.ruby-gemset +1 -0
  71. data/spec/dummy_app/.ruby-version +1 -0
  72. data/spec/dummy_app/Gemfile +43 -0
  73. data/spec/dummy_app/README.md +50 -0
  74. data/spec/dummy_app/Rakefile +6 -0
  75. data/spec/dummy_app/app/assets/images/.keep +0 -0
  76. data/spec/dummy_app/app/assets/javascripts/admin_panel.js +5 -0
  77. data/spec/dummy_app/app/assets/javascripts/application.js +16 -0
  78. data/spec/dummy_app/app/assets/stylesheets/admin_panel.css +3 -0
  79. data/spec/dummy_app/app/assets/stylesheets/app.css.scss +4 -0
  80. data/spec/dummy_app/app/assets/stylesheets/application.css +16 -0
  81. data/spec/dummy_app/app/controllers/application_controller.rb +7 -0
  82. data/{lib/generators/the_comments/templates → spec/dummy_app/app/controllers}/comments_controller.rb +3 -1
  83. data/spec/dummy_app/app/controllers/concerns/.keep +0 -0
  84. data/spec/dummy_app/app/controllers/posts_controller.rb +13 -0
  85. data/spec/dummy_app/app/controllers/users_controller.rb +7 -0
  86. data/spec/dummy_app/app/helpers/application_helper.rb +2 -0
  87. data/spec/dummy_app/app/mailers/.keep +0 -0
  88. data/spec/dummy_app/app/models/.keep +0 -0
  89. data/spec/dummy_app/app/models/comment.rb +32 -0
  90. data/spec/dummy_app/app/models/concerns/.keep +0 -0
  91. data/spec/dummy_app/app/models/post.rb +17 -0
  92. data/spec/dummy_app/app/models/user.rb +21 -0
  93. data/spec/dummy_app/app/views/layouts/admin.html.haml +25 -0
  94. data/spec/dummy_app/app/views/layouts/application.html.haml +20 -0
  95. data/spec/dummy_app/app/views/posts/index.html.haml +22 -0
  96. data/spec/dummy_app/app/views/posts/show.html.haml +7 -0
  97. data/spec/dummy_app/bin/bundle +3 -0
  98. data/spec/dummy_app/bin/rails +4 -0
  99. data/spec/dummy_app/bin/rake +4 -0
  100. data/spec/dummy_app/config/application.rb +23 -0
  101. data/spec/dummy_app/config/boot.rb +4 -0
  102. data/spec/dummy_app/config/database.yml +11 -0
  103. data/spec/dummy_app/config/environment.rb +5 -0
  104. data/spec/dummy_app/config/environments/development.rb +29 -0
  105. data/spec/dummy_app/config/environments/production.rb +80 -0
  106. data/spec/dummy_app/config/environments/test.rb +36 -0
  107. data/spec/dummy_app/config/initializers/backtrace_silencers.rb +7 -0
  108. data/spec/dummy_app/config/initializers/filter_parameter_logging.rb +4 -0
  109. data/spec/dummy_app/config/initializers/inflections.rb +16 -0
  110. data/spec/dummy_app/config/initializers/mime_types.rb +5 -0
  111. data/spec/dummy_app/config/initializers/secret_token.rb +12 -0
  112. data/spec/dummy_app/config/initializers/session_store.rb +3 -0
  113. data/spec/dummy_app/config/initializers/sorcery.rb +437 -0
  114. data/spec/dummy_app/config/initializers/the_comments.rb +13 -0
  115. data/spec/dummy_app/config/initializers/wrap_parameters.rb +14 -0
  116. data/spec/dummy_app/config/locales/en.yml +23 -0
  117. data/spec/dummy_app/config/routes.rb +15 -0
  118. data/spec/dummy_app/config.ru +4 -0
  119. data/spec/dummy_app/db/migrate/20130712061503_sorcery_core.rb +16 -0
  120. data/spec/dummy_app/db/migrate/20130712065951_create_posts.rb +11 -0
  121. data/spec/dummy_app/db/migrate/20131027185332_change_user.the_comments_engine.rb +19 -0
  122. data/spec/dummy_app/db/migrate/20131027185333_create_comments.the_comments_engine.rb +51 -0
  123. data/spec/dummy_app/db/migrate/20131027185334_change_commentable.the_comments_engine.rb +14 -0
  124. data/spec/dummy_app/db/schema.rb +74 -0
  125. data/spec/dummy_app/db/seeds.rb +42 -0
  126. data/spec/dummy_app/lib/assets/.keep +0 -0
  127. data/spec/dummy_app/lib/tasks/.keep +0 -0
  128. data/spec/dummy_app/lib/tasks/app_bootstrap.rake +15 -0
  129. data/spec/dummy_app/log/.keep +0 -0
  130. data/spec/dummy_app/public/404.html +58 -0
  131. data/spec/dummy_app/public/422.html +58 -0
  132. data/spec/dummy_app/public/500.html +57 -0
  133. data/spec/dummy_app/public/favicon.ico +0 -0
  134. data/spec/dummy_app/public/robots.txt +5 -0
  135. data/spec/dummy_app/spec/factories/post.rb +6 -0
  136. data/spec/dummy_app/spec/factories/user.rb +6 -0
  137. data/spec/dummy_app/spec/models/user_counters_spec.rb +339 -0
  138. data/spec/dummy_app/spec/spec_helper.rb +29 -0
  139. data/spec/dummy_app/test/controllers/.keep +0 -0
  140. data/spec/dummy_app/test/fixtures/.keep +0 -0
  141. data/spec/dummy_app/test/helpers/.keep +0 -0
  142. data/spec/dummy_app/test/integration/.keep +0 -0
  143. data/spec/dummy_app/test/mailers/.keep +0 -0
  144. data/spec/dummy_app/test/models/.keep +0 -0
  145. data/spec/dummy_app/test/test_helper.rb +15 -0
  146. data/spec/dummy_app/vendor/assets/javascripts/.keep +0 -0
  147. data/spec/dummy_app/vendor/assets/stylesheets/.keep +0 -0
  148. data/views_converter.rb +16 -0
  149. metadata +223 -45
  150. data/app/controllers/concerns/the_comments_controller.rb +0 -229
  151. data/app/controllers/concerns/the_comments_ip_controller.rb +0 -17
  152. data/app/controllers/concerns/the_comments_user_agent_controller.rb +0 -15
  153. data/app/models/concerns/the_comments_base.rb +0 -69
  154. data/app/models/concerns/the_comments_black_ip.rb +0 -9
  155. data/app/models/concerns/the_comments_black_user_agent.rb +0 -9
  156. data/app/models/concerns/the_comments_commentable.rb +0 -66
  157. data/app/models/concerns/the_comments_states.rb +0 -65
  158. data/app/models/concerns/the_comments_user.rb +0 -32
  159. data/app/views/ip_black_lists/index.html.haml +0 -17
  160. data/app/views/the_comments/_comment_body.html.haml +0 -30
  161. data/app/views/the_comments/_manage_controls.html.haml +0 -4
  162. data/app/views/the_comments/_tree.html.haml +0 -4
  163. data/app/views/the_comments/index.html.haml +0 -19
  164. data/app/views/the_comments/manage.html.haml +0 -29
  165. data/app/views/user_agent_black_lists/index.html.haml +0 -17
  166. data/db/migrate/20130101010101_create_comments.rb +0 -90
  167. data/lib/generators/the_comments/templates/ip_black_list.rb +0 -3
  168. data/lib/generators/the_comments/templates/ip_black_lists_controller.rb +0 -10
  169. data/lib/generators/the_comments/templates/the_comments_black_ip.rb +0 -9
  170. data/lib/generators/the_comments/templates/the_comments_black_user_agent.rb +0 -9
  171. data/lib/generators/the_comments/templates/user_agent_black_list.rb +0 -3
  172. data/lib/generators/the_comments/templates/user_agent_black_lists_controller.rb +0 -10
@@ -1,69 +0,0 @@
1
- module TheCommentsBase
2
- extend ActiveSupport::Concern
3
-
4
- included do
5
- # attr_accessible :parent_id
6
- # attr_accessible :ip, :referer, :user_agent, :tolerance_time
7
- # attr_accessible :user, :title, :contacts, :raw_content, :view_token, :state
8
-
9
- # Nested Set
10
- acts_as_nested_set scope: [:commentable_type, :commentable_id]
11
-
12
- # Comments State Machine
13
- include TheCommentsStates
14
-
15
- # TheSortableTree
16
- include TheSortableTree::Scopes
17
-
18
- validates :raw_content, presence: true
19
-
20
- # relations
21
- belongs_to :user
22
- belongs_to :holder, class_name: :User
23
- belongs_to :commentable, polymorphic: true
24
-
25
- # callbacks
26
- before_create :define_holder, :define_default_state, :define_anchor, :denormalize_commentable
27
- after_create :update_cache_counters
28
- before_save :prepare_content
29
- end
30
-
31
- def avatar_url
32
- src = id.to_s
33
- src = title unless title.blank?
34
- src = contacts if !contacts.blank? && /@/ =~ contacts
35
- hash = Digest::MD5.hexdigest(src)
36
- "http://www.gravatar.com/avatar/#{hash}?s=40&d=identicon"
37
- end
38
-
39
- private
40
-
41
- def define_anchor
42
- self.anchor = SecureRandom.hex[0..5]
43
- end
44
-
45
- def define_holder
46
- c = self.commentable
47
- self.holder = c.is_a?(User) ? c : c.try(:user)
48
- end
49
-
50
- def define_default_state
51
- self.state = TheComments.config.default_owner_state if user && user == holder
52
- end
53
-
54
- def denormalize_commentable
55
- self.commentable_title = self.commentable.try :commentable_title
56
- self.commentable_url = self.commentable.try :commentable_url
57
- self.commentable_state = self.commentable.try :state
58
- end
59
-
60
- def prepare_content
61
- self.content = self.raw_content
62
- end
63
-
64
- def update_cache_counters
65
- user.try :recalculate_my_comments_counter!
66
- commentable.try :increment!, "#{state}_comments_count"
67
- holder.try :increment!, "#{state}_comcoms_count"
68
- end
69
- end
@@ -1,9 +0,0 @@
1
- module TheCommentsBlackIp
2
- extend ActiveSupport::Concern
3
-
4
- included do
5
- # attr_accessible :ip, :state
6
- validates :ip, presence: true
7
- validates :ip, uniqueness: true
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- module TheCommentsBlackUserAgent
2
- extend ActiveSupport::Concern
3
-
4
- included do
5
- # attr_accessible :ip, :state
6
- validates :user_agent, presence: true
7
- validates :user_agent, uniqueness: true
8
- end
9
- end
@@ -1,66 +0,0 @@
1
- module TheCommentsCommentable
2
- extend ActiveSupport::Concern
3
-
4
- included do
5
- has_many :comments, as: :commentable
6
-
7
- # *define_denormalize_flags* - should be placed before title or url builder filters
8
- before_validation :define_denormalize_flags
9
- after_save :denormalize_for_comments
10
- end
11
-
12
- # Default Denormalization methods
13
- # Overwrite it with your Application
14
- def commentable_title
15
- # My first blog post
16
- try(:title) || TheComments.config.default_title
17
- end
18
-
19
- def commentable_url
20
- # /pages/1
21
- ['', self.class.to_s.tableize, self.to_param].join('/')
22
- end
23
-
24
- def commentable_state
25
- # 'draft'
26
- try(:state)
27
- end
28
-
29
- # Helper methods
30
- def comments_sum
31
- published_comments_count + draft_comments_count
32
- end
33
-
34
- def recalculate_comments_counters!
35
- self.draft_comments_count = comments.with_state(:draft).count
36
- self.published_comments_count = comments.with_state(:published).count
37
- self.deleted_comments_count = comments.with_state(:deleted).count
38
- save
39
- end
40
-
41
- private
42
-
43
- def define_denormalize_flags
44
- @trackable_commentable_title = commentable_title
45
- @trackable_commentable_state = commentable_state
46
- @trackable_commentable_url = commentable_url
47
- end
48
-
49
- # Can you make it better? I don't know how.
50
- def denormalization_fields_changed?
51
- @title_field_changed = @trackable_commentable_title != commentable_title
52
- @state_field_changed = @trackable_commentable_state != commentable_state
53
- @url_field_changed = @trackable_commentable_url != commentable_url
54
- @title_field_changed || @url_field_changed || @state_field_changed
55
- end
56
-
57
- def denormalize_for_comments
58
- if denormalization_fields_changed?
59
- comments.update_all({
60
- commentable_title: commentable_title,
61
- commentable_state: commentable_state,
62
- commentable_url: commentable_url
63
- })
64
- end
65
- end
66
- end
@@ -1,65 +0,0 @@
1
- module TheCommentsStates
2
- extend ActiveSupport::Concern
3
-
4
- included do
5
- # :draft | :published | :deleted
6
- state_machine :state, :initial => TheComments.config.default_state do
7
-
8
- # events
9
- event :to_draft do
10
- transition all - :draft => :draft
11
- end
12
-
13
- event :to_published do
14
- transition all - :published => :published
15
- end
16
-
17
- event :to_deleted do
18
- transition any - :deleted => :deleted
19
- end
20
-
21
- # transition callbacks
22
- after_transition any => any do |comment|
23
- @comment = comment
24
- @owner = comment.user
25
- @holder = comment.holder
26
- @commentable = comment.commentable
27
- end
28
-
29
- # between draft and published
30
- after_transition [:draft, :published] => [:draft, :published] do |comment, transition|
31
- from = transition.from_name
32
- to = transition.to_name
33
-
34
- @holder.try :increment!, "#{to}_comcoms_count"
35
- @holder.try :decrement!, "#{from}_comcoms_count"
36
-
37
- @commentable.try :increment!, "#{to}_comments_count"
38
- @commentable.try :decrement!, "#{from}_comments_count"
39
- end
40
-
41
- # to deleted (cascade like query)
42
- after_transition [:draft, :published] => :deleted do |comment|
43
- ids = comment.self_and_descendants.map(&:id)
44
- Comment.where(id: ids).update_all(state: :deleted)
45
-
46
- @owner.try :recalculate_my_comments_counter!
47
- @holder.try :recalculate_comcoms_counters!
48
- @commentable.try :recalculate_comments_counters!
49
- end
50
-
51
- # from deleted
52
- after_transition :deleted => [:draft, :published] do |comment, transition|
53
- to = transition.to_name
54
-
55
- @owner.try :recalculate_my_comments_counter!
56
-
57
- @holder.try :decrement!, :deleted_comcoms_count
58
- @holder.try :increment!, "#{to}_comcoms_count"
59
-
60
- @commentable.try :decrement!, :deleted_comments_count
61
- @commentable.try :increment!, "#{to}_comments_count"
62
- end
63
- end
64
- end
65
- end
@@ -1,32 +0,0 @@
1
- module TheCommentsUser
2
- extend ActiveSupport::Concern
3
-
4
- included do
5
- has_many :posted_comments, class_name: :Comment, foreign_key: :user_id
6
- has_many :comcoms, class_name: :Comment, foreign_key: :holder_id
7
- end
8
-
9
- def my_comments
10
- posted_comments.with_state([:draft,:published])
11
- end
12
-
13
- def recalculate_my_comments_counter!
14
- self.my_comments_count = my_comments.count
15
- save
16
- end
17
-
18
- def recalculate_comcoms_counters!
19
- self.draft_comcoms_count = comcoms.with_state(:draft).count
20
- self.published_comcoms_count = comcoms.with_state(:published).count
21
- self.deleted_comcoms_count = comcoms.with_state(:deleted).count
22
- save
23
- end
24
-
25
- def comments_sum
26
- published_comments_count + draft_comments_count
27
- end
28
-
29
- def comcoms_sum
30
- published_comcoms_count + draft_comcoms_count
31
- end
32
- end
@@ -1,17 +0,0 @@
1
- - unless @ip_black_lists.blank?
2
- %ol.black_list
3
- - @ip_black_lists.each do |black|
4
- %li{ class: black.state }
5
- %p
6
- %b ip:
7
- = black.ip
8
- %b count:
9
- = black.count
10
- %b state:
11
- %span.state= black.state
12
- %p
13
- %b action:
14
- = link_to :warning, ip_black_list_to_state_path(black, state: :warning), remote: true, method: :patch, class: :to_warning
15
- = link_to :banned, ip_black_list_to_state_path(black, state: :banned), remote: true, method: :patch, class: :to_banned
16
- - else
17
- %p= t('the_comments.item_not_found')
@@ -1,30 +0,0 @@
1
- .comment
2
- .commentable
3
- = comment.commentable_type
4
- →
5
- = link_to comment.commentable_title, comment.commentable_url
6
- = comment.try(:commentable_state) ? "(#{comment.try(:commentable_state)})" : nil
7
- .title
8
- %label from:
9
- = comment.title.blank? ? t('the_comments.guest_name') : comment.title
10
- .contacts
11
- %label contacts:
12
- = comment.contacts
13
- .content
14
- = comment.content
15
- .params
16
- %b tolerance time:
17
- = comment.tolerance_time || 'none'
18
- \|
19
- %b ip:
20
- = link_to(comment.ip, ip_black_lists_url(ip: comment.ip)) || 'none'
21
- \|
22
- %b UA:
23
- = link_to(comment.user_agent, user_agent_black_lists_url(agent: comment.user_agent)) || 'none'
24
- \|
25
- %b referer:
26
- = comment.referer || 'none'
27
-
28
- .controls
29
- = link_to :Edit, '#', class: :edit
30
- = render partial: 'the_comments/manage_controls', locals: { comment: comment }
@@ -1,4 +0,0 @@
1
- = link_to t('the_comments.to_published'), to_published_comment_url(comment), remote: true, class: :to_published, method: :post
2
- = link_to t('the_comments.to_draft'), to_draft_comment_url(comment), remote: true, class: :to_draft, method: :post
3
- = link_to t('the_comments.to_spam'), to_spam_comment_url(comment), remote: true, class: :to_spam, method: :post
4
- = link_to t('the_comments.to_deleted'), to_trash_comment_url(comment), remote: true, class: :to_deleted, method: :delete, data: { confirm: t('the_comments.delete_confirm') }
@@ -1,4 +0,0 @@
1
- .comments#comments
2
- %ol.comments_tree{ data: { comments: { tolarance_time: TheComments.config.tolerance_time } } }
3
- = render partial: 'the_comments/comment', locals: { tree: comments_tree }
4
- = render partial: 'the_comments/form', locals: { commentable: commentable }
@@ -1,19 +0,0 @@
1
- = paginate @comments
2
-
3
- %ol.comments_list
4
- - @comments.each do |comment|
5
- %li
6
- .item{ class: comment.state }
7
- .body
8
- .commentable
9
- = comment.commentable_type
10
- \:
11
- = link_to comment.commentable_title, comment.commentable_url
12
- .comment
13
- .title
14
- %b from:
15
- = comment.title.blank? ? t('the_comments.guest_name') : comment.title
16
- .content
17
- = comment.content
18
-
19
- = paginate @comments
@@ -1,29 +0,0 @@
1
- = paginate @comments
2
-
3
- %ol.comments_list
4
- - @comments.each do |comment|
5
- %li
6
- .item{ class: comment.state }
7
- .body
8
- = render partial: 'the_comments/comment_body', locals: { comment: comment }
9
- .form.comment{ style: 'display:none' }
10
- = form_for comment, remote: true do |f|
11
- .commentable
12
- = comment.commentable_type
13
- →
14
- = link_to comment.commentable_title, comment.commentable_url
15
- .title
16
- %label from:
17
- = f.text_field :title
18
- .contacts
19
- %label contacts:
20
- = f.text_field :contacts
21
- .content
22
- = f.text_area :raw_content
23
- .submit
24
- = f.submit
25
- .controls
26
- = link_to :View, '#', class: :view
27
- = render partial: 'the_comments/manage_controls', locals: { comment: comment }
28
-
29
- = paginate @comments
@@ -1,17 +0,0 @@
1
- - unless @ip_black_lists.blank?
2
- %ol.black_list
3
- - @ip_black_lists.each do |black|
4
- %li{ class: black.state }
5
- %p
6
- %b user_agent:
7
- = black.user_agent
8
- %b count:
9
- = black.count
10
- %b state:
11
- %span.state= black.state
12
- %p
13
- %b action:
14
- = link_to :warning, user_agent_black_list_to_state_path(black, state: :warning), remote: true, method: :patch, class: :to_warning
15
- = link_to :banned, user_agent_black_list_to_state_path(black, state: :banned), remote: true, method: :patch, class: :to_banned
16
- - else
17
- %p= t('the_comments.item_not_found')
@@ -1,90 +0,0 @@
1
- # null: false => de-facto db-level validation
2
- class CreateComments < ActiveRecord::Migration
3
- def change
4
- create_table :comments do |t|
5
- # relations
6
- t.integer :user_id
7
- t.integer :holder_id
8
-
9
- # polymorphic, commentable object
10
- t.integer :commentable_id
11
- t.string :commentable_type
12
-
13
- # denormalization
14
- t.string :commentable_url
15
- t.string :commentable_title
16
- t.string :commentable_state
17
-
18
- # comment
19
- t.string :anchor
20
-
21
- t.string :title
22
- t.string :contacts
23
-
24
- t.text :raw_content
25
- t.text :content
26
-
27
- # moderation token
28
- t.string :view_token
29
-
30
- # state machine => :draft | :published | :deleted
31
- t.string :state, default: :draft
32
-
33
- # base user data (BanHammer power)
34
- t.string :ip, default: :undefined
35
- t.string :referer, default: :undefined
36
- t.string :user_agent, default: :undefined
37
- t.integer :tolerance_time
38
-
39
- # unusable: for future versions
40
- t.boolean :spam, default: false
41
-
42
- # nested set
43
- t.integer :parent_id
44
- t.integer :lft
45
- t.integer :rgt
46
- t.integer :depth, default: 0
47
-
48
- t.timestamps
49
- end
50
-
51
- # Black Lists
52
- create_table :ip_black_lists do |t|
53
- t.string :ip
54
- t.integer :count, default: 0
55
- t.string :state, default: :warning
56
- end
57
-
58
- create_table :user_agent_black_lists do |t|
59
- t.string :user_agent
60
- t.integer :count, default: 0
61
- t.string :state, default: :warning
62
- end
63
-
64
- # Add fields to User Model
65
- change_table :users do |t|
66
- # posted_comments.with_state([:draft,:published])
67
- t.integer :my_comments_count, default: 0
68
-
69
- # commentable's comments => comcoms (cache)
70
- # Relation through Comment#holder_id field
71
- t.integer :draft_comcoms_count, default: 0
72
- t.integer :published_comcoms_count, default: 0
73
- t.integer :deleted_comcoms_count, default: 0
74
-
75
- # unusable: for future versions
76
- t.integer :spam_comcoms_count, default: 0
77
- end
78
-
79
- # Uncomment this. Add fields to Commentable Models
80
- #
81
- # [:posts, :blogs, :articles, :pages].each do |table_name|
82
- # change_table table_name do |t|
83
- # t.integer :draft_comments_count, default: 0
84
- # t.integer :published_comments_count, default: 0
85
- # t.integer :deleted_comments_count, default: 0
86
- # end
87
- # end
88
- end
89
-
90
- end
@@ -1,3 +0,0 @@
1
- class IpBlackList < ActiveRecord::Base
2
- include TheCommentsBlackIp
3
- end
@@ -1,10 +0,0 @@
1
- class IpBlackListsController < ApplicationController
2
- # Define your restrict methods and use them like this:
3
- #
4
- # before_action :user_required
5
- # before_action :admin_required
6
- #
7
- # Only Admin should have an access to following methods
8
- # Methods: [:index, :to_state]
9
- include TheCommentsIpController
10
- end
@@ -1,9 +0,0 @@
1
- module TheCommentsBlackIp
2
- extend ActiveSupport::Concern
3
-
4
- included do
5
- # attr_accessible :ip, :state
6
- validates :ip, presence: true
7
- validates :ip, uniqueness: true
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- module TheCommentsBlackUserAgent
2
- extend ActiveSupport::Concern
3
-
4
- included do
5
- # attr_accessible :ip, :state
6
- validates :user_agent, presence: true
7
- validates :user_agent, uniqueness: true
8
- end
9
- end
@@ -1,3 +0,0 @@
1
- class UserAgentBlackList < ActiveRecord::Base
2
- include TheCommentsBlackUserAgent
3
- end
@@ -1,10 +0,0 @@
1
- class UserAgentBlackListsController < ApplicationController
2
- # Define your restrict methods and use them like this:
3
- #
4
- # before_action :user_required
5
- # before_action :admin_required
6
- #
7
- # Only Admin should have an access to following methods
8
- # Methods: [:index, :to_state]
9
- include TheCommentsUserAgentController
10
- end