From 24ba7c9762a583f3e1105162f4a43a22a17a4627 Mon Sep 17 00:00:00 2001
From: Eugen Rochko <eugen@zeonfederated.com>
Date: Thu, 16 Feb 2017 02:28:10 +0100
Subject: [PATCH] Adding index overview for reports in admin UI

---
 app/controllers/admin/reports_controller.rb | 17 +++++++++++++
 app/models/status.rb                        |  2 +-
 app/views/admin/accounts/show.html.haml     |  6 ++++-
 app/views/admin/reports/index.html.haml     | 27 +++++++++++++++++++++
 app/views/admin/reports/show.html.haml      |  2 ++
 config/navigation.rb                        |  1 +
 config/routes.rb                            |  1 +
 7 files changed, 54 insertions(+), 2 deletions(-)
 create mode 100644 app/controllers/admin/reports_controller.rb
 create mode 100644 app/views/admin/reports/index.html.haml
 create mode 100644 app/views/admin/reports/show.html.haml

diff --git a/app/controllers/admin/reports_controller.rb b/app/controllers/admin/reports_controller.rb
new file mode 100644
index 0000000000..3eb5ab5171
--- /dev/null
+++ b/app/controllers/admin/reports_controller.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class Admin::ReportsController < ApplicationController
+  before_action :require_admin!
+
+  layout 'admin'
+
+  def index
+    @reports = Report.includes(:account, :target_account).paginate(page: params[:page], per_page: 40)
+    @reports = params[:action_taken].present? ? @reports.resolved : @reports.unresolved
+  end
+
+  def show
+    @report   = Report.find(params[:id])
+    @statuses = Status.where(id: @report.status_ids)
+  end
+end
diff --git a/app/models/status.rb b/app/models/status.rb
index e440bbacab..46d92ea331 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -77,7 +77,7 @@ class Status < ApplicationRecord
 
   def permitted?(other_account = nil)
     if private_visibility?
-      (account.id == other_account&.id || other_account&.following?(account) || mentions.include?(other_account))
+      (account.id == other_account&.id || other_account&.following?(account) || mentions.where(account: other_account).exists?)
     else
       other_account.nil? || !account.blocking?(other_account)
     end
diff --git a/app/views/admin/accounts/show.html.haml b/app/views/admin/accounts/show.html.haml
index 206d6f81ea..b528e161e4 100644
--- a/app/views/admin/accounts/show.html.haml
+++ b/app/views/admin/accounts/show.html.haml
@@ -22,7 +22,11 @@
         %td= @account.user.current_sign_in_ip
       %tr
         %th Most recent activity
-        %td= l @account.user.current_sign_in_at
+        %td
+          - if @account.user.current_sign_in_at
+            = l @account.user.current_sign_in_at
+          - else
+            Never
     - else
       %tr
         %th Profile URL
diff --git a/app/views/admin/reports/index.html.haml b/app/views/admin/reports/index.html.haml
new file mode 100644
index 0000000000..8a5414cef3
--- /dev/null
+++ b/app/views/admin/reports/index.html.haml
@@ -0,0 +1,27 @@
+- content_for :page_title do
+  Reports
+
+.filters
+  .filter-subset
+    %strong Status
+    %ul
+      %li= filter_link_to 'Unresolved', action_taken: nil
+      %li= filter_link_to 'Resolved', action_taken: '1'
+
+%table.table
+  %thead
+    %tr
+      %th ID
+      %th Target
+      %th Reported by
+      %th Comment
+      %th
+  %tbody
+    - @reports.each do |report|
+      %tr
+        %td= "##{report.id}"
+        %td= link_to report.target_account.acct, admin_account_path(report.target_account.id)
+        %td= link_to report.account.acct, admin_account_path(report.account.id)
+        %td= truncate(report.comment, length: 30, separator: ' ')
+        %td= table_link_to 'circle', 'View', admin_report_path(report)
+= will_paginate @reports, pagination_options
diff --git a/app/views/admin/reports/show.html.haml b/app/views/admin/reports/show.html.haml
new file mode 100644
index 0000000000..8aeb562006
--- /dev/null
+++ b/app/views/admin/reports/show.html.haml
@@ -0,0 +1,2 @@
+- content_for :page_title do
+  = "Report ##{@report.id}"
diff --git a/config/navigation.rb b/config/navigation.rb
index b2930f62fe..0d43a9f731 100644
--- a/config/navigation.rb
+++ b/config/navigation.rb
@@ -13,6 +13,7 @@ SimpleNavigation::Configuration.run do |navigation|
     end
 
     primary.item :admin, safe_join([fa_icon('cogs fw'), 'Administration']), admin_accounts_url, if: proc { current_user.admin? } do |admin|
+      admin.item :reports, safe_join([fa_icon('flag fw'), 'Reports']), admin_reports_url, highlights_on: %r{/admin/reports}
       admin.item :accounts, safe_join([fa_icon('users fw'), 'Accounts']), admin_accounts_url, highlights_on: %r{/admin/accounts}
       admin.item :pubsubhubbubs, safe_join([fa_icon('paper-plane-o fw'), 'PubSubHubbub']), admin_pubsubhubbub_index_url
       admin.item :domain_blocks, safe_join([fa_icon('lock fw'), 'Domain Blocks']), admin_domain_blocks_url
diff --git a/config/routes.rb b/config/routes.rb
index 419b17ce1c..e3fef9d567 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -66,6 +66,7 @@ Rails.application.routes.draw do
     resources :pubsubhubbub, only: [:index]
     resources :domain_blocks, only: [:index, :create]
     resources :settings, only: [:index, :update]
+    resources :reports, only: [:index, :show]
 
     resources :accounts, only: [:index, :show] do
       member do