Commit 5b2ae1eaf0c1d2cbc6846e48e9ecd1bcdf29ca20
Exists in
master
and in
29 other branches
Merge branch 'fix_report_abuse' into 'master'
Fix 'Report Abuse' action See merge request !343
Showing
11 changed files
with
52 additions
and
30 deletions
Show diff stats
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
| ... | ... | @@ -1286,6 +1286,17 @@ class ProfileControllerTest < ActionController::TestCase |
| 1286 | 1286 | end |
| 1287 | 1287 | end |
| 1288 | 1288 | |
| 1289 | + should 'register abuse report with content' do | |
| 1290 | + reported = fast_create(Profile) | |
| 1291 | + content = fast_create(RawHTMLArticle, :profile_id => reported.id) | |
| 1292 | + login_as(profile.identifier) | |
| 1293 | + @controller.stubs(:verify_recaptcha).returns(true) | |
| 1294 | + | |
| 1295 | + assert_difference 'AbuseReport.count', 1 do | |
| 1296 | + post :register_report, :profile => reported.identifier, :abuse_report => {:reason => 'some reason'}, :content_type => content.class.name, :content_id => content.id | |
| 1297 | + end | |
| 1298 | + end | |
| 1299 | + | |
| 1289 | 1300 | should 'not ask admin for captcha to register abuse' do |
| 1290 | 1301 | reported = fast_create(Profile) |
| 1291 | 1302 | login_as(profile.identifier) | ... | ... |