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
23 changes: 16 additions & 7 deletions app/assets/stylesheets/backstage.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
border: solid 5px var(--black-color);
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
box-sizing: border-box;
}

#backstage-container .panel-title {
Expand Down Expand Up @@ -74,7 +74,7 @@

#backstage-container .panel-menu a:focus {
cursor: pointer;
background-color: var(--bright-blue-color);
background-color: var(--bright-blue-color);
outline: none;
}

Expand All @@ -92,7 +92,7 @@

#backstage-container .panel-filters a.selected {
font-weight: 700;
color: var(--light-black-color);
color: var(--light-black-color);
}

#backstage-container .panel-filters a:hover {
Expand All @@ -119,12 +119,21 @@

#backstage-container .record-row:hover {
cursor: pointer;
background: var(--orange-overlay);
background: var(--orange-overlay);
}

#backstage-container .record-row:active {
cursor: pointer;
background: var(--blue-overlay);
background: var(--blue-overlay);
}

#backstage-container .record-row .icons-space {
width: 5.5em;
}

#backstage-container .record-row .icons-space .icon {
font-family: var(--icon-font);
margin-right: 0.3em;
}

#backstage-container .record-row .row-title {
Expand Down Expand Up @@ -160,12 +169,12 @@
width: auto;
padding: 2em 2em 2em 2em;
}

#backstage-container .control-panel {
min-width: 16em;
padding: 2em 2em 2em 2em;
}

#backstage-container .panel-descriptor {
text-align: left;
}
Expand Down
22 changes: 20 additions & 2 deletions app/assets/stylesheets/reports.css
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,24 @@
font-size: 0.9em;
}

#backstage-container .record-row .row-status {
font-weight: 500;
width: 7em;
text-align: right;
}

#backstage-container .record-row .row-status.revoked {
color: var(--alert-red-color);
}

#backstage-container .record-row .row-status.warned {
color: var(--bright-orange-color);
}

#backstage-container .record-row .row-status.dismissed {
color: var(--bright-green-color);
}

#backstage-container .report-buttons {
margin-top: 2em;
}
Expand Down Expand Up @@ -99,7 +117,7 @@

#backstage-container .report-buttons .button:focus {
cursor: pointer;
background-color: var(--bright-blue-color);
background-color: var(--bright-blue-color);
outline: none;
}

Expand All @@ -118,7 +136,7 @@
margin-left: 0em;
margin-top: 2em;
}

#backstage-container .report-buttons a.stealth {
margin-left: auto;
margin-right: auto;
Expand Down
56 changes: 30 additions & 26 deletions app/controllers/reports_controller.rb
Original file line number Diff line number Diff line change
@@ -1,58 +1,62 @@
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)")
@reports = eval("Report.includes(:pledge)."+params[:f]+".all.order(created_at: :desc)")
# TODO add: paginate(page: params[:page], per_page: 30)
@filter_category = params[:f]
else
@reports = Report.unresolved.all.order(created_at: :desc)
@reports = Report.includes(:pledge).unresolved.all.order(created_at: :desc)
@filter_category = "unresolved"
end
end

def show
# Create keybot advice message
if @reported_twitch_user == nil
if !@report.twitch_id
@message = "The reported Twitch user does not exist."
elsif @pledge = Pledge.find_by(twitch_id: @reported_twitch_user)
elsif @pledge = Pledge.find_by(twitch_id: @report.twitch_id)
@message = "The reported Twitch user signed the pledge as " + @pledge.twitch_display_name + " on " + @pledge.signed_on.strftime('%b. %-d, %Y.')
else
@message = "The reported Twitch user did not sign the pledge."
end

if @report.twitch_id
@other_reports = Report.where(twitch_id: @report.twitch_id).where.not(id: @report.id)
else
@other_reports = nil
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

set_twitch_id

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 +69,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 +87,32 @@ def find_report
rescue ActiveRecord::RecordNotFound
redirect_to staff_index_path
end
def find_reported_twitch_user

def set_twitch_id
# 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
@report.update_attribute(:twitch_id, nil)
else
@reported_twitch_user = response["data"][0]["id"]
@report.update_attribute(:twitch_id, 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
50 changes: 19 additions & 31 deletions app/controllers/revocations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,52 +1,51 @@
class RevocationsController < ApplicationController

layout "backstage"

before_action :authenticate_user!
before_action :ensure_staff
before_action :find_report
before_action :ensure_sane_review
before_action :find_reported_twitch_user
around_action :display_timezone

def new
if @reported_twitch_user == nil
if @report.twitch_id == nil
redirect_to staff_index_path
elsif @pledge = Pledge.find_by(twitch_id: @reported_twitch_user)
elsif @pledge = Pledge.find_by(twitch_id: @report.twitch_id)
@revocation = Revocation.new
else
redirect_to staff_index_path
end
end

def create
if @reported_twitch_user == nil
if @report.twitch_id == nil
redirect_to staff_index_path
elsif @pledge = Pledge.find_by(twitch_id: @reported_twitch_user)
elsif @pledge = Pledge.find_by(twitch_id: @report.twitch_id)
@revocation = Revocation.new(revocation_params)
@revocation.report = @report
@revocation.pledge = @pledge
@revocation.reviewer = current_user

if @revocation.save
# Email revocation to pledger
PledgeMailer.revoke_pledger(@revocation).deliver_now

# Email reporter that action has been taken
PledgeMailer.notify_reporter_revocation(@revocation).deliver_now

# Revoke badge on Twitch
# TODO: Roll over to Helix v6 API endpoint when they are built
badge_result = HTTParty.delete(URI.escape("#{ENV['TWITCH_API_V5_BASE_URL']}/users/#{@pledge.twitch_id}/chat/badges/pledge?secret=#{ENV['TWITCH_PLEDGE_SECRET']}"), headers: {Accept: 'application/vnd.twitchtv.v5+json', "Client-ID": ENV['TWITCH_CLIENT_ID']})

@pledge.badge_revoked = true
@pledge.revoked_on = Time.now
@pledge.save

@report.revoked = true
@report.reviewer = current_user
@report.save

flash[:notice] = "You revoked the badge from #{@report.reported_twitch_name} and sent them a notification at #{@pledge.email}."
redirect_to reports_path
else
Expand All @@ -60,49 +59,38 @@ def create
redirect_to staff_index_path
end
end

protected
def find_report
@report = Report.find(params[:report_id])
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
def ensure_staff
unless current_user.is_moderator? || current_user.is_admin?
redirect_to root_url
end
end

def ensure_sane_review
unless !@report.dismissed && !@report.warned && !@report.revoked
redirect_to staff_index_path
end
end

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

def conduct_warning_params
params.require(:conduct_warning).permit(:reason)
end

def revocation_params
params.require(:revocation).permit(:reason)
end

end
Loading