Skip to content

Commit 474cf04

Browse files
committed
Fix report protip
1 parent f335d7b commit 474cf04

File tree

4 files changed

+18
-26
lines changed

4 files changed

+18
-26
lines changed

app/controllers/application_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def current_user
4646
@current_user
4747
end
4848

49+
#TODO remove this
4950
def viewing_user
5051
@viewing_user ||= current_user || begin
5152
if cookies[:identity]

app/controllers/protips_controller.rb

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -257,25 +257,16 @@ def unsubscribe
257257
end
258258

259259
def report_inappropriate
260-
261-
report_inappropriate_params = params.permit(:id)
262-
263-
264-
protip_public_id = params.permit(:id)
265-
266-
logger.info "Report Inappropriate: protip_public_id => '#{protip_public_id}', reporting_user => '#{viewing_user.inspect}', ip_address => '#{request.remote_ip}'"
267-
260+
protip_public_id = params[:id]
268261
if cookies["report_inappropriate-#{protip_public_id}"].nil?
269-
opts = { reporting_user: viewing_user, ip_address: request.remote_ip, protip_public_id: protip_public_id }
270-
report_inappropriate_mailer = ::AbuseMailer.report_inappropriate(opts)
271-
report_inappropriate_mailer.deliver
262+
opts = { user_id: current_user,
263+
ip: request.remote_ip}
264+
::AbuseMailer.report_inappropriate(protip_public_id,opts).deliver
272265

273266
cookies["report_inappropriate-#{protip_public_id}"] = true
274267
end
275268

276-
respond_to do |format|
277-
format.json { head :ok }
278-
end
269+
render nothing: true
279270
end
280271

281272
def flag

app/mailers/abuse_mailer.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
class AbuseMailer < ActionMailer::Base
2-
include ActionView::Helpers::TextHelper
3-
include ActiveSupport::Benchmarkable
4-
52
default_url_options[:host] = 'coderwall.com'
63
default_url_options[:only_path] = false
74

8-
default to: Proc.new { User.admins.map(&:email) },
5+
default to: -> { User.admins.pluck(:email) },
96
from: '"Coderwall" <support@coderwall.com>'
107

11-
def report_inappropriate(opts)
8+
def report_inappropriate(public_id, opts={})
129
headers['X-Mailgun-Campaign-Id'] = 'coderwall-abuse-report_inappropriate'
13-
14-
@ip_address = opts[:ip_address]
15-
@reporting_user = opts[:reporting_user]
16-
protip_public_id = (opts[:protip_public_id] || opts['protip_public_id'])
17-
@protip = Protip.find_by_public_id(protip_public_id)
10+
begin
11+
@protip = Protip.find_by_public_id!(public_id)
12+
@reporting_user = opts[:user_id]
13+
@ip_address = opts[:ip]
1814

1915
mail subject: "Spam Report for Protip: \"#{@protip.title}\" (#{@protip.id})"
16+
rescue ActiveRecord::RecordNotFound
17+
#Protip was probably deleted
18+
true
19+
end
2020
end
2121
end

spec/mailers/abuse_mailer_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
RSpec.describe AbuseMailer, :type => :mailer do
22
describe 'report_inappropriate' do
33

4-
let(:mail) { AbuseMailer.report_inappropriate({ protip_public_id: protip.to_param }) }
4+
let(:mail) { AbuseMailer.report_inappropriate(protip.to_param) }
55

6-
let(:current_user) { Fabricate(:user, admin: true) }
6+
let!(:current_user) { Fabricate(:user, admin: true) }
77

88
let(:protip) {
99
Protip.create!(

0 commit comments

Comments
 (0)