Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 20 additions & 21 deletions app/controllers/reports_controller.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
class ReportsController < ApplicationController

layout "backstage", only: [ :index, :show ]

before_action :authenticate_user!, only: [ :index, :show, :dismiss, :undismiss ]
before_action :ensure_staff, only: [ :index, :show, :dismiss, :undismiss ]
before_action :find_report, only: [ :show, :dismiss, :undismiss ]
before_action :find_reported_twitch_user, only: [ :show ]
around_action :display_timezone

def index
# f is used to filter reports by scope
if params[:f].present? && Report::AVAILABLE_SCOPES.key?(params[:f].to_sym)
@reports = eval("Report."+params[:f]+".all.order(created_at: :desc)")
# TODO add: paginate(page: params[:page], per_page: 30)
@reports = eval("Report."+params[:f]+".all.order(created_at: :desc).paginate(page: params[:page], per_page: 30)")
@filter_category = params[:f]
else
@reports = Report.unresolved.all.order(created_at: :desc)
@reports = Report.unresolved.all.order(created_at: :desc).paginate(page: params[:page], per_page: 30)
@filter_category = "unresolved"
end
end

def show
# Create keybot advice message
if @reported_twitch_user == nil
Expand All @@ -29,30 +28,30 @@ def show
else
@message = "The reported Twitch user did not sign the pledge."
end

# TODO: check if reporter has pledged (lookup email/Twitch name) and add info to keybot message
# TODO: check if incident stream owner has pledged (Twitch name) and add info to keybot message

end

def new
@report = Report.new
end

def create
@report = Report.new(report_params)

if @report.save
# Email notification to staff
StaffMailer.notify_staff_new_report(@report).deliver_now

flash[:notice] = "You've successfully submitted the report. Thank you."
redirect_to root_path
else
else
flash.now[:alert] ||= ""
@report.errors.full_messages.each do |message|
flash.now[:alert] << message + ". "
end
end
render(action: :new)
end
end
Expand All @@ -65,14 +64,14 @@ def dismiss
end
redirect_to reports_path
end

def undismiss
@report.dismissed = false
@report.reviewer = nil
if @report.save
flash[:notice] = "You undismissed the report about #{@report.reported_twitch_name}. It can now be reviewed again."
redirect_to report_path(@report)
else
else
redirect_to reports_path
end
end
Expand All @@ -83,32 +82,32 @@ def find_report
rescue ActiveRecord::RecordNotFound
redirect_to staff_index_path
end

def find_reported_twitch_user
# Check if reported_twitch_name exists on Twitch
response = HTTParty.get(URI.escape("#{ENV['TWITCH_API_BASE_URL']}/users?login=#{@report.reported_twitch_name}"), headers: {"Client-ID": ENV['TWITCH_CLIENT_ID'], "Authorization": "Bearer #{TwitchToken.first.valid_token!}"})

if response["data"].blank?
@reported_twitch_user = nil
else
@reported_twitch_user = response["data"][0]["id"]
end
end

private
private
def ensure_staff
unless current_user.is_moderator? || current_user.is_admin?
redirect_to root_url
end
end

def display_timezone
timezone = Time.find_zone( cookies[:browser_timezone] )
Time.use_zone(timezone) { yield }
end

def report_params
params.require(:report).permit(:reporter_email, :reporter_twitch_name, :reported_twitch_name, :incident_stream, :incident_occurred, :incident_description, :recommended_response, :image)
end

end
6 changes: 5 additions & 1 deletion app/views/reports/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="panel-filters flexbox horizontal center wrap">
<% Report::AVAILABLE_SCOPES.each do |filter| %>
<% if @filter_category.to_s == filter[0].to_s %>
<%= link_to("#{filter[1]} [#{@reports.count}]", reports_path(f: filter[0]), class: "filter selected") %>
<%= link_to("#{filter[1]} [#{@reports.total_entries}]", reports_path(f: filter[0]), class: "filter selected") %>
<% else %>
<%= link_to(filter[1], reports_path(f: filter[0]), class: "filter") %>
<% end %>
Expand All @@ -16,6 +16,10 @@
<div class="records-list flexbox vertical stretch">
<% if @reports.present? %>
<%= render(partial: "reports/row", collection: @reports, as: :report) %>
<div class="flexbox vertical center">
<%= will_paginate @reports, class: "pagination full flexbox horizontal", previous_label: "« PREV", next_label: "NEXT »", inner_window: 3, outer_window: 0 %>
<%= will_paginate @reports, class: "pagination mini flexbox horizontal justify-space-between", previous_label: "« PREV", next_label: "NEXT »", page_links: false %>
</div>
<% else %>
<div class="empty">
No reports found.
Expand Down