Index: test/functional/admin/comments_controller_test.rb
===================================================================
--- test/functional/admin/comments_controller_test.rb (revision 2838)
+++ test/functional/admin/comments_controller_test.rb (working copy)
@@ -10,7 +10,7 @@
@controller = Admin::CommentsController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
- login_as :ben
+ login_as :quentin
end
def test_should_disable_comments_on_article
@@ -18,4 +18,60 @@
assert_equal -1, contents(:welcome).reload.comment_age
assert_response :success
end
+
+ def test_should_destroy_comment
+ comment = contents(:welcome_comment)
+
+ delete :destroy, :id => '3', :article_id => '1'
+ assert_response :success
+ assert_equal [comment], assigns(:comments)
+ assert_raise(ActiveRecord::RecordNotFound) { comment.reload }
+ end
+
+ def test_should_destroy_comments
+ comment = contents(:welcome_comment)
+
+ delete :destroy, :comment => ['3'], :article_id => '1'
+ assert_response :success
+ assert_equal [comment], assigns(:comments)
+ assert_raise(ActiveRecord::RecordNotFound) { comment.reload }
+ end
+
+ def test_should_list_comments_on_article
+ get :index, :article_id => '1'
+ assert_response :success
+ end
+
+ def test_should_list_approved_comments_on_article
+ get :index, :article_id => '1', :filter => 'approved'
+ assert_response :success
+ end
+
+ def test_should_list_unapproved_comments_on_article
+ get :index, :article_id => '1', :filter => 'unapproved'
+ assert_response :success
+ end
+
+ def test_should_create_comment
+ post :create, :article_id => '1', :comment => {}
+ assert_response :success
+ end
+
+ def test_should_edit_comment
+ get :edit, :article_id => '1', :id => '3'
+ assert_response :success
+ end
+
+ def test_should_approve_comment
+ contents(:welcome_comment).update_attribute(:approved, false)
+ get :approve, :article_id => '1', :id => '3'
+ assert_response :success
+ end
+
+ def test_should_unapprove_comment
+ get :unapprove, :article_id => '1', :id => '3'
+ assert_response :success
+ assert_template 'approve'
+ end
+
end
Index: test/functional/admin/articles_controller_test.rb
===================================================================
--- test/functional/admin/articles_controller_test.rb (revision 2838)
+++ test/functional/admin/articles_controller_test.rb (working copy)
@@ -125,7 +125,7 @@
def test_should_show_default_checked_sections
get :new
assert_response :success
- assert_tag 'form', :attributes => { :action => '/admin/articles/create' }
+ assert_tag 'form', :attributes => { :action => '/admin/articles', :method => 'post' }
assert_tag 'input', :attributes => { :id => "article_section_ids_#{sections(:home).id.to_s}" }
assert_no_tag 'input', :attributes => { :id => "article_section_ids_#{sections(:about).id.to_s}", :checked => 'checked' }
end
@@ -182,7 +182,9 @@
def test_edit_form_should_have_correct_post_action
get :edit, :id => contents(:welcome).id
assert_response :success
- assert_tag :tag => 'form', :attributes => { :action => "/admin/articles/update/#{contents(:welcome).id}" }
+ assert_tag :tag => 'form', :attributes => { :action => "/admin/articles/#{contents(:welcome).id}" } do
+ assert_tag :tag => 'input', :attributes => { :name => "_method", :value => "put" }
+ end
end
def test_should_update_article_with_correct_time
Index: app/controllers/admin/comments_controller.rb
===================================================================
--- app/controllers/admin/comments_controller.rb (revision 2838)
+++ app/controllers/admin/comments_controller.rb (working copy)
@@ -1,8 +1,71 @@
class Admin::CommentsController < Admin::BaseController
+
+ member_actions.push(*%w(index unapproved create edit update approve unapprove destroy close ))
+
+private
+
+ before_filter :find_site_article, :except => [ :close ]
+ def find_site_article
+ @article = site.articles.find params[:article_id]
+ end
+
+ cache_sweeper :comment_sweeper, :only => [:approve, :unapprove, :destroy_comment, :create]
+
+public
+
def index
- @comments = site.unapproved_comments.find(:all, :include => :article)
+ @comments = if params[:article_id]
+ @articles = site.unapproved_comments.count :all, :group => :article, :order => '1 desc'
+ @article.send case params[:filter]
+ when 'approved' then :comments
+ when 'unapproved' then :unapproved_comments
+ else :all_comments
+ end
+ end
end
+ def unapproved
+ site.unapproved_comments.find(:all, :include => :article)
+ end
+
+ def create
+ @comment = @article.comments.build(params[:comment].merge(
+ :user_id => session[:user],
+ :author_ip => request.remote_ip,
+ :user_agent => request.env['HTTP_USER_AGENT'],
+ :referrer => request.env['HTTP_REFERER'])
+ )
+ @comment.approved = true
+ @comment.save
+ end
+
+ def edit
+ @comment = @article.all_comments.find params[:id]
+ end
+
+ def update
+ @comment = @article.all_comments.find params[:id]
+ @comment.update_attributes(params[:comment])
+ end
+
+ # xhr baby
+ # needs some restful lovin'
+ def approve
+ @comment = @article.unapproved_comments.approve(params[:comment] || params[:id])
+ @comment.mark_as_ham(site, request)
+ end
+
+ def unapprove
+ @comment = @article.comments.unapprove(params[:comment] || params[:id])
+ @comment.mark_as_spam(site, request)
+ render :action => 'approve'
+ end
+
+ def destroy
+ @comments = site.all_comments.find :all, :conditions => ['id in (?)', [ (params[:comment] || params[:id])].flatten] # rescue []
+ Comment.transaction { @comments.each(&:destroy) } if @comments.any?
+ end
+
# ajax action, called from _page_nav
def close
@article = site.articles.find(params[:id])
Index: app/controllers/admin/articles_controller.rb
===================================================================
--- app/controllers/admin/articles_controller.rb (revision 2838)
+++ app/controllers/admin/articles_controller.rb (working copy)
@@ -3,7 +3,6 @@
with_options :only => [:create, :update, :destroy, :upload] do |c|
c.before_filter :set_default_section_ids
c.cache_sweeper :article_sweeper, :assigned_section_sweeper
- cache_sweeper :comment_sweeper, :only => [:approve, :unapprove, :destroy_comment]
end
before_filter :convert_times_to_utc, :only => [:create, :update, :upload]
@@ -71,34 +70,9 @@
end
def comments
- @comments =
- case params[:filter]
- when 'approved' then :comments
- when 'unapproved' then :unapproved_comments
- else :all_comments
- end
- @comments = @article.send @comments
- @articles = @site.unapproved_comments.count :all, :group => :article, :order => '1 desc'
+ redirect_to comments_path(@article)
end
- # xhr baby
- # needs some restful lovin'
- def approve
- @comment = @article.unapproved_comments.approve(params[:comment])
- @comment.mark_as_ham(site, request)
- end
-
- def unapprove
- @comment = @article.comments.unapprove(params[:comment])
- @comment.mark_as_spam(site, request)
- render :action => 'approve'
- end
-
- def destroy_comment
- @comments = site.all_comments.find :all, :conditions => ['id in (?)', [params[:comment]].flatten] rescue []
- Comment.transaction { @comments.each(&:destroy) } if @comments.any?
- end
-
def upload
@asset = site.assets.build(params[:asset])
@asset.save!
Index: app/views/admin/comments/_new_comment.rhtml
===================================================================
--- app/views/admin/comments/_new_comment.rhtml (revision 0)
+++ app/views/admin/comments/_new_comment.rhtml (revision 0)
@@ -0,0 +1,5 @@
+ <%= error_messages_for :comment %>
+ <% remote_form_for :comment, :url => comment_path(@article) do |form| %>
+ <%= render :partial => 'form', :object => form %>
+ <%= submit_tag "Create" %>
+ <% end # form %>
Index: app/views/admin/comments/update.rjs
===================================================================
--- app/views/admin/comments/update.rjs (revision 0)
+++ app/views/admin/comments/update.rjs (revision 0)
@@ -0,0 +1,3 @@
+
+ page.replace "comment-#{@comment.id}", :partial => 'comment', :object => @comment
+ page.remove "edit-comment-#{@comment.id}"
\ No newline at end of file
Index: app/views/admin/comments/create.rjs
===================================================================
--- app/views/admin/comments/create.rjs (revision 0)
+++ app/views/admin/comments/create.rjs (revision 0)
@@ -0,0 +1,6 @@
+ if @comment.valid? # saved?
+ # @comment.mark_as_ham(site, request)
+ page.insert_html :top, 'comment-list', :partial => 'comment', :object => @comment
+ else
+ page.replace_html 'new-comment-form', :partial => 'new_comment'
+ end
Index: app/views/admin/comments/edit.rjs
===================================================================
--- app/views/admin/comments/edit.rjs (revision 0)
+++ app/views/admin/comments/edit.rjs (revision 0)
@@ -0,0 +1,3 @@
+
+ page.insert_html :after, "comment-#{@comment.id}", :partial => 'edit_comment', :locals => { :comment => @comment }
+ page.hide "comment-#{@comment.id}"
Index: app/views/admin/comments/_comment.rhtml
===================================================================
--- app/views/admin/comments/_comment.rhtml (revision 0)
+++ app/views/admin/comments/_comment.rhtml (revision 0)
@@ -0,0 +1,16 @@
+
+
Index: app/views/admin/comments/_form.rhtml
===================================================================
--- app/views/admin/comments/_form.rhtml (revision 0)
+++ app/views/admin/comments/_form.rhtml (revision 0)
@@ -0,0 +1,16 @@
+
+ Name (required)
+ <%= form.text_field :author %>
+
+
+ Mail (will not be published
+ <%= form.text_field :author_email %>
+
+
+ Website
+ <%= form.text_field :author_url %>
+
+
+ <%= form.text_area :body, { :rows => '10' } %>
+
+
Index: app/views/admin/comments/unapproved.rhtml
===================================================================
--- app/views/admin/comments/unapproved.rhtml (revision 0)
+++ app/views/admin/comments/unapproved.rhtml (revision 0)
@@ -0,0 +1,20 @@
+<% content_for :action_nav do %>
+
+
+
+ <%= link_to_remote 'Delete these comments', :confirm => "Are you sure you wish to delete all of these comments?",
+ :url => { :controller => 'articles', :action => 'destroy_comment' },
+ :with => "ArticleForm.getAvailableComments().toQueryString('comment')"
+ %>
+
+
+
+<% end %>
+
+<%= pluralize(@comments.size, 'Unapproved Comment') %>
+
+
Index: app/views/admin/comments/_edit_comment.rhtml
===================================================================
--- app/views/admin/comments/_edit_comment.rhtml (revision 0)
+++ app/views/admin/comments/_edit_comment.rhtml (revision 0)
@@ -0,0 +1,9 @@
+
\ No newline at end of file
Index: app/views/admin/comments/index.rhtml
===================================================================
--- app/views/admin/comments/index.rhtml (revision 2838)
+++ app/views/admin/comments/index.rhtml (working copy)
@@ -1,33 +1,57 @@
-<% content_for :action_nav do %>
-
-
-
- <%= link_to_remote 'Delete these comments', :confirm => "Are you sure you wish to delete all of these comments?",
- :url => { :controller => 'articles', :action => 'destroy_comment' },
- :with => "ArticleForm.getAvailableComments().toQueryString('comment')"
- %>
-
-
-
-<% end %>
+<%= render :partial => "admin/articles/page_nav" %>
-<%= pluralize(@comments.size, 'Unapproved Comment') %>
+Comments on <%= link_to @article.title, edit_article_path(@article), :style => 'border:none' %> <%= @article.published? ? link_to(image_tag('/images/mephisto/icons/24-zoom-in.png', :style => 'vertical-align: middle'), @site.permalink_for(@article), :style => 'border:none;') : ' ' %>
-
<%= published_at_for article %>
Index: app/views/admin/articles/destroy_comment.rjs
===================================================================
--- app/views/admin/articles/destroy_comment.rjs (revision 2838)
+++ app/views/admin/articles/destroy_comment.rjs (working copy)
@@ -1,3 +0,0 @@
-@comments.each do |comment|
- page["comment-#{comment.id}"].add_class_name 'disabled'
-end
\ No newline at end of file
Index: app/views/admin/articles/approve.rjs
===================================================================
--- app/views/admin/articles/approve.rjs (revision 2838)
+++ app/views/admin/articles/approve.rjs (working copy)
@@ -1 +0,0 @@
-page["comment-#{@comment.id}"].add_class_name 'disabled'
\ No newline at end of file
Index: app/views/admin/articles/edit.rhtml
===================================================================
--- app/views/admin/articles/edit.rhtml (revision 2838)
+++ app/views/admin/articles/edit.rhtml (working copy)
@@ -1,23 +1,24 @@
<%= render :partial => "page_nav" %>
<% fields_for :article, @version do |f| -%>
-<% content_for :sidebar do %>
- <%= render :partial => 'shared_options', :locals => { :form => f } %>
+ <% content_for :sidebar do %>
+ <%= render :partial => 'shared_options', :locals => { :form => f } %>
+ <% end %>
<% end %>
-<% end %>
<%= error_messages_for :article %>
<% content_for :form do -%>
- <%= form_tag({:action => 'update', :id => @article}, {:id => 'article-form', :multipart => true}) %>
+ <%= form_tag({:action => 'update', :id => @article}, {:id => 'article-form', :multipart => true, :method => :put}) %>
<% end -%>
<% fields_for :article, @version do |f| -%>
-<%= render :partial => 'form', :object => f %>
-
- <%= submit_tag 'Apply Changes' %>
- <%= submit_tag 'Save without Revision' %>
- <%= link_to "cancel", :controller => "articles" %>
+ <%= render :partial => 'form', :object => f %>
+
+ <%= submit_tag 'Apply Changes' %>
+ <%= submit_tag 'Save without Revision' %>
+ <%= link_to "cancel", :controller => "articles" %>
+
<% end -%>
Index: app/views/admin/articles/comments.rhtml
===================================================================
--- app/views/admin/articles/comments.rhtml (revision 2838)
+++ app/views/admin/articles/comments.rhtml (working copy)
@@ -1,57 +0,0 @@
-<%= render :partial => "page_nav" %>
-
-
-Comments on <%= link_to @article.title, { :action => 'edit', :id => @article }, :style => 'border:none' %> <%= @article.published? ? link_to(image_tag('/images/mephisto/icons/24-zoom-in.png', :style => 'vertical-align: middle'), @site.permalink_for(@article), :style => 'border:none;') : ' ' %>
-
-
-
-
-<% content_for :sidebar do %>
- <% if @articles.size > 1 -%>
-
-
Comments awaiting your approval
-
- <% @articles.each do |article, count| -%>
- <% if article.title != @article.title -%>
- <%= link_to "(#{count}) #{h(article.title)}", :controller => 'articles', :action => 'comments', :id => article.id, :filter => :unapproved %>
- <% end -%>
- <% end -%>
-
-
- <% end -%>
-<% end %>
-
-
-
\ No newline at end of file
Index: db/schema.rb
===================================================================
--- db/schema.rb (revision 2838)
+++ db/schema.rb (working copy)
@@ -90,8 +90,8 @@
t.column "author_email", :string
t.column "author_ip", :string, :limit => 100
t.column "comments_count", :integer, :default => 0
+ t.column "version", :integer
t.column "updater_id", :integer
- t.column "version", :integer
t.column "site_id", :integer
t.column "approved", :boolean, :default => false
t.column "comment_age", :integer, :default => 0
@@ -103,11 +103,11 @@
create_table "events", :force => true do |t|
t.column "mode", :string
- t.column "user_id", :integer
t.column "article_id", :integer
t.column "title", :text
t.column "body", :text
t.column "created_at", :datetime
+ t.column "user_id", :integer
t.column "author", :string, :limit => 100
t.column "comment_id", :integer
t.column "site_id", :integer
Index: lib/mephisto/routing.rb
===================================================================
--- lib/mephisto/routing.rb (revision 2838)
+++ lib/mephisto/routing.rb (working copy)
@@ -14,7 +14,11 @@
m.js 'javascripts/:path.:ext', :dir => 'javascripts'
m.images 'images/:path.:ext', :dir => 'images'
end
-
+
+ map.resources :articles, :path_prefix => 'admin', :controller => 'admin/articles' do |r|
+ r.resources :comments, :controller => 'admin/comments', :member => { :unapprove => :post, :approve => :post, :edit => :get }
+ end
+
map.overview 'admin/overview.xml', :controller => 'admin/overview', :action => 'feed'
map.admin 'admin', :controller => 'admin/overview', :action => 'index'
map.resources :assets, :path_prefix => '/admin', :controller => 'admin/assets', :member => { :add_bucket => :post },
@@ -22,8 +26,10 @@
map.connect 'xmlrpc', :controller => 'backend', :action => 'xmlrpc'
+
map.connect ':controller/:action/:id/:version', :version => nil, :controller => /routing_navigator|account|(admin\/\w+)/, :id => /[^\/]*/
+
yield if block_given?
Mephisto::Plugin.custom_routes.each do |path, options|
map.connect path, options