From 2cbd78d6fcf366764745a64bb7b36569434cb4f7 Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Mon, 20 Oct 2014 14:49:41 -0300 Subject: [PATCH] Fix report abuse --- app/controllers/public/profile_controller.rb | 2 +- app/helpers/article_helper.rb | 6 ++++++ app/models/article.rb | 7 ------- app/views/shared/reported_versions/_article.html.erb | 10 ---------- app/views/shared/reported_versions/_comment.html.erb | 10 ---------- app/views/shared/reported_versions/_folder.html.erb | 1 - app/views/shared/reported_versions/profile/_article.html.erb | 10 ++++++++++ app/views/shared/reported_versions/profile/_comment.html.erb | 10 ++++++++++ app/views/shared/reported_versions/profile/_folder.html.erb | 1 + public/javascripts/report-abuse.js | 14 +++++++++++++- test/functional/profile_controller_test.rb | 11 +++++++++++ 11 files changed, 52 insertions(+), 30 deletions(-) delete mode 100644 app/views/shared/reported_versions/_article.html.erb delete mode 100644 app/views/shared/reported_versions/_comment.html.erb delete mode 100644 app/views/shared/reported_versions/_folder.html.erb create mode 100644 app/views/shared/reported_versions/profile/_article.html.erb create mode 100644 app/views/shared/reported_versions/profile/_comment.html.erb create mode 100644 app/views/shared/reported_versions/profile/_folder.html.erb diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index 18791e7..09384fa 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -316,7 +316,7 @@ class ProfileController < PublicController abuse_report = AbuseReport.new(params[:abuse_report]) if !params[:content_type].blank? article = params[:content_type].constantize.find(params[:content_id]) - abuse_report.content = instance_eval(&article.reported_version) + abuse_report.content = article_reported_version(article) end user.register_report(abuse_report, profile) diff --git a/app/helpers/article_helper.rb b/app/helpers/article_helper.rb index 567de43..db3a768 100644 --- a/app/helpers/article_helper.rb +++ b/app/helpers/article_helper.rb @@ -3,6 +3,12 @@ module ArticleHelper include PrototypeHelper include TokenHelper + def article_reported_version(article) + search_path = Rails.root.join('app', 'views', 'shared', 'reported_versions') + partial_path = File.join('shared', 'reported_versions', 'profile', partial_for_class_in_view_path(article.class, search_path)) + render_to_string(:partial => partial_path, :locals => {:article => article}) + end + def custom_options_for_article(article, tokenized_children) @article = article diff --git a/app/models/article.rb b/app/models/article.rb index 5584325..6023bfb 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -285,13 +285,6 @@ class Article < ActiveRecord::Base end end - def reported_version(options = {}) - article = self - search_path = Rails.root.join('app', 'views', 'shared', 'reported_versions') - partial_path = File.join('shared', 'reported_versions', partial_for_class_in_view_path(article.class, search_path)) - lambda { render_to_string(:partial => partial_path, :locals => {:article => article}) } - end - # returns the data of the article. Must be overriden in each subclass to # provide the correct content for the article. def data diff --git a/app/views/shared/reported_versions/_article.html.erb b/app/views/shared/reported_versions/_article.html.erb deleted file mode 100644 index b0402c0..0000000 --- a/app/views/shared/reported_versions/_article.html.erb +++ /dev/null @@ -1,10 +0,0 @@ - - -<%= article_to_html(article) %> diff --git a/app/views/shared/reported_versions/_comment.html.erb b/app/views/shared/reported_versions/_comment.html.erb deleted file mode 100644 index 13d88b7..0000000 --- a/app/views/shared/reported_versions/_comment.html.erb +++ /dev/null @@ -1,10 +0,0 @@ - - -

<%= article_to_html(comment) %>

diff --git a/app/views/shared/reported_versions/_folder.html.erb b/app/views/shared/reported_versions/_folder.html.erb deleted file mode 100644 index 03e0008..0000000 --- a/app/views/shared/reported_versions/_folder.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= _('Reported folder') + ': ' + link_to(article.name, article.url) %> diff --git a/app/views/shared/reported_versions/profile/_article.html.erb b/app/views/shared/reported_versions/profile/_article.html.erb new file mode 100644 index 0000000..b0402c0 --- /dev/null +++ b/app/views/shared/reported_versions/profile/_article.html.erb @@ -0,0 +1,10 @@ + + +<%= article_to_html(article) %> diff --git a/app/views/shared/reported_versions/profile/_comment.html.erb b/app/views/shared/reported_versions/profile/_comment.html.erb new file mode 100644 index 0000000..13d88b7 --- /dev/null +++ b/app/views/shared/reported_versions/profile/_comment.html.erb @@ -0,0 +1,10 @@ + + +

<%= article_to_html(comment) %>

diff --git a/app/views/shared/reported_versions/profile/_folder.html.erb b/app/views/shared/reported_versions/profile/_folder.html.erb new file mode 100644 index 0000000..03e0008 --- /dev/null +++ b/app/views/shared/reported_versions/profile/_folder.html.erb @@ -0,0 +1 @@ +<%= _('Reported folder') + ': ' + link_to(article.name, article.url) %> diff --git a/public/javascripts/report-abuse.js b/public/javascripts/report-abuse.js index 45e036f..a4309ea 100644 --- a/public/javascripts/report-abuse.js +++ b/public/javascripts/report-abuse.js @@ -10,8 +10,20 @@ jQuery(function($) { return false; }); - $('#report-abuse-submit-button').click(function(){ + $('#report-abuse-submit-button').live('click', function(e) { + e.preventDefault(); loading_for_button(this); + form = $(this).parents('form'); + $.post(form.attr("action"), form.serialize(), function(data) { + data = $.parseJSON(data); + $(this).parents('#colorbox').colorbox.close(); + if(data.ok) { + display_notice(data.message); + } else { + display_notice(data.error.message); + } + }); }); + }); diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb index 964a281..62a6357 100644 --- a/test/functional/profile_controller_test.rb +++ b/test/functional/profile_controller_test.rb @@ -1260,6 +1260,17 @@ class ProfileControllerTest < ActionController::TestCase end end + should 'register abuse report with content' do + reported = fast_create(Profile) + content = fast_create(RawHTMLArticle, :profile_id => reported.id) + login_as(profile.identifier) + @controller.stubs(:verify_recaptcha).returns(true) + + assert_difference 'AbuseReport.count', 1 do + post :register_report, :profile => reported.identifier, :abuse_report => {:reason => 'some reason'}, :content_type => content.class.name, :content_id => content.id + end + end + should 'not ask admin for captcha to register abuse' do reported = fast_create(Profile) login_as(profile.identifier) -- libgit2 0.21.2