diff --git a/app/controllers/my_profile/spam_controller.rb b/app/controllers/my_profile/spam_controller.rb new file mode 100644 index 0000000..16818c5 --- /dev/null +++ b/app/controllers/my_profile/spam_controller.rb @@ -0,0 +1,40 @@ +class SpamController < MyProfileController + + protect :moderate_comments, :profile + + def index + if request.post? + begin + # FIXME duplicated logic + # + # This logic more or less replicates what is already in + # ContentViewerController#view_page, + # ContentViewerController#remove_comment and + # ContentViewerController#mark_comment_as_spam + if params[:remove_comment] + profile.comments_received.find(params[:remove_comment]).destroy + end + if params[:mark_comment_as_ham] + profile.comments_received.find(params[:mark_comment_as_ham]).ham! + end + if request.xhr? + json_response(true) + else + redirect_to :action => :index + end + rescue + json_response(false) + end + return + end + + @spam = profile.comments_received.spam.paginate({:page => params[:page]}) + end + + protected + + def json_response(status) + render :text => {'ok' => status }.to_json, :content_type => 'application/json' + end + +end diff --git a/app/controllers/public/content_viewer_controller.rb b/app/controllers/public/content_viewer_controller.rb index ce5f222..0569b44 100644 --- a/app/controllers/public/content_viewer_controller.rb +++ b/app/controllers/public/content_viewer_controller.rb @@ -155,7 +155,7 @@ class ContentViewerController < ApplicationController @comment.destroy session[:notice] = _('Comment succesfully deleted') end - redirect_to :action => 'view_page', :profile => params[:profile], :page => @page.explode_path, :view => params[:view] + finish_comment_handling end def mark_comment_as_spam @@ -164,7 +164,15 @@ class ContentViewerController < ApplicationController @comment.spam! session[:notice] = _('Comment succesfully marked as SPAM') end - redirect_to :action => 'view_page', :profile => params[:profile], :page => @page.explode_path, :view => params[:view] + finish_comment_handling + end + + def finish_comment_handling + if request.xhr? + render :text => {'ok' => true}.to_json, :content_type => 'application/json' + else + redirect_to :action => 'view_page', :profile => params[:profile], :page => @page.explode_path, :view => params[:view] + end end def per_page diff --git a/app/models/profile.rb b/app/models/profile.rb index 4c1a6bd..336780e 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -101,6 +101,8 @@ class Profile < ActiveRecord::Base has_many :scraps_received, :class_name => 'Scrap', :foreign_key => :receiver_id, :order => "updated_at DESC", :dependent => :destroy belongs_to :template, :class_name => 'Profile', :foreign_key => 'template_id' + has_many :comments_received, :class_name => 'Comment', :through => :articles, :source => :comments + # FIXME ugly workaround def self.human_attribute_name(attrib) _(self.superclass.human_attribute_name(attrib)) diff --git a/app/views/content_viewer/_comment.rhtml b/app/views/content_viewer/_comment.rhtml index 3f1009f..d89bbbd 100644 --- a/app/views/content_viewer/_comment.rhtml +++ b/app/views/content_viewer/_comment.rhtml @@ -1,7 +1,7 @@
<%= _('Manage SPAM') %>
+ +<% button_bar do %> + <%= button :back, _('Back to control panel'), :controller => :profile_editor %> +<% end %> + +<%# FIXME should not need to replicate the article structure like this to be able to use the same formatting as the comments listing %> ++ <%= render :partial => 'content_viewer/comment', :collection => @spam %> +
+