Commit 2cbd78d6fcf366764745a64bb7b36569434cb4f7

Authored by Victor Costa
1 parent 99fa04df

Fix report abuse

app/controllers/public/profile_controller.rb
... ... @@ -316,7 +316,7 @@ class ProfileController < PublicController
316 316 abuse_report = AbuseReport.new(params[:abuse_report])
317 317 if !params[:content_type].blank?
318 318 article = params[:content_type].constantize.find(params[:content_id])
319   - abuse_report.content = instance_eval(&article.reported_version)
  319 + abuse_report.content = article_reported_version(article)
320 320 end
321 321  
322 322 user.register_report(abuse_report, profile)
... ...
app/helpers/article_helper.rb
... ... @@ -3,6 +3,12 @@ module ArticleHelper
3 3 include PrototypeHelper
4 4 include TokenHelper
5 5  
  6 + def article_reported_version(article)
  7 + search_path = Rails.root.join('app', 'views', 'shared', 'reported_versions')
  8 + partial_path = File.join('shared', 'reported_versions', 'profile', partial_for_class_in_view_path(article.class, search_path))
  9 + render_to_string(:partial => partial_path, :locals => {:article => article})
  10 + end
  11 +
6 12 def custom_options_for_article(article, tokenized_children)
7 13 @article = article
8 14  
... ...
app/models/article.rb
... ... @@ -285,13 +285,6 @@ class Article < ActiveRecord::Base
285 285 end
286 286 end
287 287  
288   - def reported_version(options = {})
289   - article = self
290   - search_path = Rails.root.join('app', 'views', 'shared', 'reported_versions')
291   - partial_path = File.join('shared', 'reported_versions', partial_for_class_in_view_path(article.class, search_path))
292   - lambda { render_to_string(:partial => partial_path, :locals => {:article => article}) }
293   - end
294   -
295 288 # returns the data of the article. Must be overriden in each subclass to
296 289 # provide the correct content for the article.
297 290 def data
... ...
app/views/shared/reported_versions/_article.html.erb
... ... @@ -1,10 +0,0 @@
1   -<ul>
2   - <li><%= (content_tag('strong', _('Title') + ': ') + article.title) if article.title %> </li>
3   - <li><%= (content_tag('strong', _('Type') + ': ') + article.class.short_description) %> </li>
4   - <li>
5   - <%= (content_tag('strong', _('Original content') + ': ') + link_to(article.name, article.url)) %> <br />
6   - <%= content_tag('small', _('This link might be unavailable if the content is removed')) %>
7   - </li>
8   -</ul>
9   -
10   -<%= article_to_html(article) %>
app/views/shared/reported_versions/_comment.html.erb
... ... @@ -1,10 +0,0 @@
1   -<ul>
2   - <li><%= (content_tag('strong', _('Title') + ': ') + comment.title) if comment.title %> </li>
3   - <li><%= content_tag('strong', _('Type') + ': ') + _('Comment') %> </li>
4   - <li>
5   - <%= (content_tag('strong', _('Original content') + ': ') + link_to(comment.title || url_for(comment.url), comment.url)) %> <br />
6   - <%= content_tag('small', _('This link might be unavailable if the content is removed')) %>
7   - </li>
8   -</ul>
9   -
10   -<p><%= article_to_html(comment) %></p>
app/views/shared/reported_versions/_folder.html.erb
... ... @@ -1 +0,0 @@
1   -<%= _('Reported folder') + ': ' + link_to(article.name, article.url) %>
app/views/shared/reported_versions/profile/_article.html.erb 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +<ul>
  2 + <li><%= (content_tag('strong', _('Title') + ': ') + article.title) if article.title %> </li>
  3 + <li><%= (content_tag('strong', _('Type') + ': ') + article.class.short_description) %> </li>
  4 + <li>
  5 + <%= (content_tag('strong', _('Original content') + ': ') + link_to(article.name, article.url)) %> <br />
  6 + <%= content_tag('small', _('This link might be unavailable if the content is removed')) %>
  7 + </li>
  8 +</ul>
  9 +
  10 +<%= article_to_html(article) %>
... ...
app/views/shared/reported_versions/profile/_comment.html.erb 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +<ul>
  2 + <li><%= (content_tag('strong', _('Title') + ': ') + comment.title) if comment.title %> </li>
  3 + <li><%= content_tag('strong', _('Type') + ': ') + _('Comment') %> </li>
  4 + <li>
  5 + <%= (content_tag('strong', _('Original content') + ': ') + link_to(comment.title || url_for(comment.url), comment.url)) %> <br />
  6 + <%= content_tag('small', _('This link might be unavailable if the content is removed')) %>
  7 + </li>
  8 +</ul>
  9 +
  10 +<p><%= article_to_html(comment) %></p>
... ...
app/views/shared/reported_versions/profile/_folder.html.erb 0 → 100644
... ... @@ -0,0 +1 @@
  1 +<%= _('Reported folder') + ': ' + link_to(article.name, article.url) %>
... ...
public/javascripts/report-abuse.js
... ... @@ -10,8 +10,20 @@ jQuery(function($) {
10 10 return false;
11 11 });
12 12  
13   - $('#report-abuse-submit-button').click(function(){
  13 + $('#report-abuse-submit-button').live('click', function(e) {
  14 + e.preventDefault();
14 15 loading_for_button(this);
  16 + form = $(this).parents('form');
  17 + $.post(form.attr("action"), form.serialize(), function(data) {
  18 + data = $.parseJSON(data);
  19 + $(this).parents('#colorbox').colorbox.close();
  20 + if(data.ok) {
  21 + display_notice(data.message);
  22 + } else {
  23 + display_notice(data.error.message);
  24 + }
  25 + });
15 26 });
  27 +
16 28 });
17 29  
... ...
test/functional/profile_controller_test.rb
... ... @@ -1260,6 +1260,17 @@ class ProfileControllerTest &lt; ActionController::TestCase
1260 1260 end
1261 1261 end
1262 1262  
  1263 + should 'register abuse report with content' do
  1264 + reported = fast_create(Profile)
  1265 + content = fast_create(RawHTMLArticle, :profile_id => reported.id)
  1266 + login_as(profile.identifier)
  1267 + @controller.stubs(:verify_recaptcha).returns(true)
  1268 +
  1269 + assert_difference 'AbuseReport.count', 1 do
  1270 + post :register_report, :profile => reported.identifier, :abuse_report => {:reason => 'some reason'}, :content_type => content.class.name, :content_id => content.id
  1271 + end
  1272 + end
  1273 +
1263 1274 should 'not ask admin for captcha to register abuse' do
1264 1275 reported = fast_create(Profile)
1265 1276 login_as(profile.identifier)
... ...