implement site reporting

This commit is contained in:
Kyle Drake 2014-06-14 16:15:47 -07:00
parent 5edeba9495
commit e546b22797
5 changed files with 84 additions and 3 deletions

25
app.rb
View file

@ -963,6 +963,31 @@ post '/comment/:comment_id/delete' do |comment_id|
return {result: 'error'}.to_json
end
post '/site/:username/report' do |username|
site = Site[username: username]
redirect request.referer if site.nil?
report = Report.new site_id: site.id, type: params[:type], comments: params[:comments]
if current_site
report.reporting_site_id = current_site.id
else
report.ip = request.ip
end
report.save
EmailWorker.perform_async({
from: 'web@neocities.org',
to: 'report@neocities.org',
subject: "[Neocities Report] #{site.username} has been reported for #{report.type}",
body: "Reported by #{report.reporting_site_id ? report.reporting_site.username : report.ip}: #{report.comments}"
})
redirect request.referer
end
def require_admin
redirect '/' unless signed_in? && current_site.is_admin
end

View file

@ -0,0 +1,18 @@
Sequel.migration do
up {
DB.create_table! :reports do
primary_key :id
Integer :site_id
Integer :reporting_site_id
String :type
Text :comments
Text :action_taken
String :ip
DateTime :created_at
end
}
down {
DB.drop_table :reports
}
end

4
models/report.rb Normal file
View file

@ -0,0 +1,4 @@
class Report < Sequel::Model
many_to_one :site
many_to_one :reporting_site, class: :Site
end

View file

@ -78,6 +78,9 @@ class Site < Sequel::Model
one_to_many :blocks
one_to_many :blockings, key: :actioning_site_id, class: :Block
one_to_many :reports
one_to_many :reportings, key: :reporting_site_id, class: :Report
one_to_many :stats
one_to_many :events

View file

@ -102,9 +102,40 @@
<%== erb :'_tags', layout: false, locals: {site: site, is_current_site: site == current_site} %>
<% if site != current_site %>
<div class="report">
<a href="">Report</a> | <a href="">Block</a>
<a href="#report" data-toggle="modal">Report</a> | <a href="">Block</a>
</div>
<% end %>
</div>
</div></div>
</div>
<div class="modal hide fade" id="report" tabindex="-1" role="dialog" aria-labelledby="reportLabel" aria-hidden="true">
<form method="POST" action="/site/<%= site.username %>/report">
<input type="hidden" value="<%= csrf_token %>" name="csrf_token">
<div class="modal-header">
<button class="close" type="button" data-dismiss="modal" aria-hidden="true">x</button>
<h3 id="removeTagLabel">Report Site</h3>
</div>
<div class="modal-body">
<p>
What is the reason you are reporting this site?
<select name="type" class="input-Area">
<option value="spam">Site is spamming</option>
<option value="phishing">Site is being used for a phishing attack</option>
<option value="abusive">Site is abusive or threatening</option>
<option value="harassment">Site is harassing other sites</option>
<option value="content">Site contains inappropriate/illegal content</option>
<option value="other">Other</option>
</select>
</p>
<p>Comments:</p>
<textarea name="comments" type="text" style="width: 400px"></textarea>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
<button type="submit" class="btn btn-Action">Report</button>
</div>
</form>
</div>