From 6d6ebd297e52bcba49ce19c5d091f1b90f61b40b Mon Sep 17 00:00:00 2001 From: Lukas Matt Date: Thu, 15 May 2014 17:34:00 -0400 Subject: [PATCH] Do not try to render posts/comments which are not present refs diaspora/diaspora#4959 --- app/assets/stylesheets/report.css.scss | 3 +++ app/helpers/report_helper.rb | 15 ++++++++------- app/views/report/index.html.haml | 2 +- config/locales/diaspora/en.yml | 1 + 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/assets/stylesheets/report.css.scss b/app/assets/stylesheets/report.css.scss index 2ee1789e7..d964b55cd 100644 --- a/app/assets/stylesheets/report.css.scss +++ b/app/assets/stylesheets/report.css.scss @@ -5,6 +5,9 @@ span { display: block; } + span.text { + padding-bottom: 1em; + } } .options { float: right; diff --git a/app/helpers/report_helper.rb b/app/helpers/report_helper.rb index 370981314..10509ccfd 100644 --- a/app/helpers/report_helper.rb +++ b/app/helpers/report_helper.rb @@ -4,13 +4,14 @@ module ReportHelper def report_content(id, type) - raw case type - when 'post' - t('report.post_label', title: link_to(post_page_title(Post.find_by_id(id)), post_path(id))) - when 'comment' - # comment_message is not html_safe. To prevent - # cross-site-scripting we have to escape html - t('report.comment_label', data: h(comment_message(Comment.find_by_id(id)))) + if type == 'post' && !(post = Post.find_by_id(id)).nil? + raw t('report.post_label', title: link_to(post_page_title(post), post_path(id))) + elsif type == 'comment' && !(comment = Comment.find_by_id(id)).nil? + # comment_message is not html_safe. To prevent + # cross-site-scripting we have to escape html + raw t('report.comment_label', data: h(comment_message(comment))) + else + raw t('report.not_found') end end end diff --git a/app/views/report/index.html.haml b/app/views/report/index.html.haml index b5026c643..1268c56c7 100644 --- a/app/views/report/index.html.haml +++ b/app/views/report/index.html.haml @@ -8,7 +8,7 @@ - @reports.each do |r| - username = User.find_by_id(r.user_id).username %div.content - %span + %span.text = report_content(r.item_id, r.item_type) %span = raw t('report.reported_label', person: link_to(username, user_profile_path(username))) diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 5fc467451..44ac3630e 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -894,6 +894,7 @@ en: review_link: "Mark as reviewed" delete_link: "Delete item" confirm_deletion: "Are you sure to delete the item?" + not_found: "The post/comment was not found. It seams that it was deleted by the user!" status: marked: "The report was marked as reviewed" destroyed: "The post was destroyed"