mirror of
https://github.com/Retrospring/retrospring.git
synced 2025-03-21 22:17:48 +01:00
Merge pull request #15 from skiprope/report-reason
Add support for report reasons (fixes Retrospring/bugs#7)
This commit is contained in:
commit
e306d36b10
10 changed files with 61 additions and 73 deletions
|
@ -2,25 +2,4 @@ $(document).on "click", "a[data-action=ab-comment-report]", (ev) ->
|
||||||
ev.preventDefault()
|
ev.preventDefault()
|
||||||
btn = $(this)
|
btn = $(this)
|
||||||
cid = btn[0].dataset.cId
|
cid = btn[0].dataset.cId
|
||||||
swal
|
reportDialog "comment", cid, -> btn.button "reset"
|
||||||
title: "Really report?"
|
|
||||||
text: "A moderator will review this comment and decide what happens."
|
|
||||||
type: "warning"
|
|
||||||
showCancelButton: true
|
|
||||||
confirmButtonColor: "#DD6B55"
|
|
||||||
confirmButtonText: "Report"
|
|
||||||
closeOnConfirm: true
|
|
||||||
, ->
|
|
||||||
$.ajax
|
|
||||||
url: '/ajax/report'
|
|
||||||
type: 'POST'
|
|
||||||
data:
|
|
||||||
id: cid
|
|
||||||
type: 'comment'
|
|
||||||
success: (data, status, jqxhr) ->
|
|
||||||
showNotification data.message, data.success
|
|
||||||
error: (jqxhr, status, error) ->
|
|
||||||
console.log jqxhr, status, error
|
|
||||||
showNotification "An error occurred, a developer should check the console for details", false
|
|
||||||
complete: (jqxhr, status) ->
|
|
||||||
btn.button "reset"
|
|
||||||
|
|
|
@ -2,25 +2,4 @@ $(document).on "click", "a[data-action=ab-report]", (ev) ->
|
||||||
ev.preventDefault()
|
ev.preventDefault()
|
||||||
btn = $(this)
|
btn = $(this)
|
||||||
aid = btn[0].dataset.aId
|
aid = btn[0].dataset.aId
|
||||||
swal
|
reportDialog "answer", aid, -> btn.button "reset"
|
||||||
title: "Really report?"
|
|
||||||
text: "A moderator will review this answer and decide what happens."
|
|
||||||
type: "warning"
|
|
||||||
showCancelButton: true
|
|
||||||
confirmButtonColor: "#DD6B55"
|
|
||||||
confirmButtonText: "Report"
|
|
||||||
closeOnConfirm: true
|
|
||||||
, ->
|
|
||||||
$.ajax
|
|
||||||
url: '/ajax/report' # TODO: find a way to use rake routes instead of hardcoding them here
|
|
||||||
type: 'POST'
|
|
||||||
data:
|
|
||||||
id: aid
|
|
||||||
type: 'answer'
|
|
||||||
success: (data, status, jqxhr) ->
|
|
||||||
showNotification data.message, data.success
|
|
||||||
error: (jqxhr, status, error) ->
|
|
||||||
console.log jqxhr, status, error
|
|
||||||
showNotification "An error occurred, a developer should check the console for details", false
|
|
||||||
complete: (jqxhr, status) ->
|
|
||||||
btn.button "reset"
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#= require question
|
#= require question
|
||||||
#= require settings
|
#= require settings
|
||||||
#= require user
|
#= require user
|
||||||
|
#= require report
|
||||||
# not required:
|
# not required:
|
||||||
# _tree ./moderation
|
# _tree ./moderation
|
||||||
|
|
||||||
|
|
28
app/assets/javascripts/report.coffee
Normal file
28
app/assets/javascripts/report.coffee
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
window.reportDialog = (type, target, callback) ->
|
||||||
|
swal
|
||||||
|
title: "Really report #{target}?"
|
||||||
|
text: "A moderator will review this #{type} and decide what happens.\nIf you'd like, you can also specify a reason."
|
||||||
|
type: "input"
|
||||||
|
showCancelButton: true
|
||||||
|
confirmButtonColor: "#DD6B55"
|
||||||
|
confirmButtonText: "Report"
|
||||||
|
closeOnConfirm: true
|
||||||
|
inputPlaceholder: "Specify a reason..."
|
||||||
|
, (value) ->
|
||||||
|
if typeof value == "boolean" && value == false
|
||||||
|
return false
|
||||||
|
|
||||||
|
$.ajax
|
||||||
|
url: '/ajax/report'
|
||||||
|
type: 'POST'
|
||||||
|
data:
|
||||||
|
id: target
|
||||||
|
type: type
|
||||||
|
reason: value
|
||||||
|
success: (data, status, jqxhr) ->
|
||||||
|
showNotification data.message, data.success
|
||||||
|
error: (jqxhr, status, error) ->
|
||||||
|
console.log jqxhr, status, error
|
||||||
|
showNotification "An error occurred, a developer should check the console for details", false
|
||||||
|
complete: (jqxhr, status) ->
|
||||||
|
callback type, target, jqxhr, status
|
|
@ -50,26 +50,4 @@ $(document).on "click", "a[data-action=report-user]", (ev) ->
|
||||||
ev.preventDefault()
|
ev.preventDefault()
|
||||||
btn = $(this)
|
btn = $(this)
|
||||||
target = btn[0].dataset.target
|
target = btn[0].dataset.target
|
||||||
|
reportDialog "user", target, -> btn.button "reset"
|
||||||
swal
|
|
||||||
title: "Really report #{target}?"
|
|
||||||
text: "A moderator will review this user and decide what happens."
|
|
||||||
type: "warning"
|
|
||||||
showCancelButton: true
|
|
||||||
confirmButtonColor: "#DD6B55"
|
|
||||||
confirmButtonText: "Report"
|
|
||||||
closeOnConfirm: true
|
|
||||||
, ->
|
|
||||||
$.ajax
|
|
||||||
url: '/ajax/report'
|
|
||||||
type: 'POST'
|
|
||||||
data:
|
|
||||||
id: target
|
|
||||||
type: 'user'
|
|
||||||
success: (data, status, jqxhr) ->
|
|
||||||
showNotification data.message, data.success
|
|
||||||
error: (jqxhr, status, error) ->
|
|
||||||
console.log jqxhr, status, error
|
|
||||||
showNotification "An error occurred, a developer should check the console for details", false
|
|
||||||
complete: (jqxhr, status) ->
|
|
||||||
btn.button "reset"
|
|
||||||
|
|
|
@ -22,13 +22,12 @@ class Ajax::ReportController < ApplicationController
|
||||||
params[:type].strip.capitalize.constantize.find params[:id]
|
params[:type].strip.capitalize.constantize.find params[:id]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
if object.nil?
|
if object.nil?
|
||||||
@message = "Could not find #{params[:type]}"
|
@message = "Could not find #{params[:type]}"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
current_user.report object
|
current_user.report object, params[:reason]
|
||||||
|
|
||||||
@status = :okay
|
@status = :okay
|
||||||
@message = "#{params[:type].capitalize} reported. A moderator will decide what happens with the #{params[:type]}."
|
@message = "#{params[:type].capitalize} reported. A moderator will decide what happens with the #{params[:type]}."
|
||||||
|
|
|
@ -149,8 +149,19 @@ class User < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
# region stuff used for reporting/moderation
|
# region stuff used for reporting/moderation
|
||||||
def report(object)
|
def report(object, reason = nil)
|
||||||
Report.create(type: "Reports::#{object.class}", target_id: object.id, user_id: self.id)
|
existing = Report.find_by(target_id: object.id, user_id: self.id, deleted: false)
|
||||||
|
if existing.nil?
|
||||||
|
Report.create(type: "Reports::#{object.class}", target_id: object.id, user_id: self.id, reason: reason)
|
||||||
|
elsif not reason.nil? and reason.length > 0
|
||||||
|
if existing.reason.nil?
|
||||||
|
existing.update(reason: reason)
|
||||||
|
else
|
||||||
|
existing.update(reason: [existing.reason || "", reason].join("\n"))
|
||||||
|
end
|
||||||
|
else
|
||||||
|
existing
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# @param upvote [Boolean]
|
# @param upvote [Boolean]
|
||||||
|
|
|
@ -13,6 +13,14 @@
|
||||||
= user_screen_name report.target
|
= user_screen_name report.target
|
||||||
- else
|
- else
|
||||||
= report.target.content
|
= report.target.content
|
||||||
|
%p
|
||||||
|
%b
|
||||||
|
Reason:
|
||||||
|
%br
|
||||||
|
- (report.reason || "No reason provided.").lines.each do |reason|
|
||||||
|
- next unless reason.strip.length > 0
|
||||||
|
= reason.strip
|
||||||
|
%br
|
||||||
.row
|
.row
|
||||||
.col-md-6.col-sm-4.col-xs-6.text-left
|
.col-md-6.col-sm-4.col-xs-6.text-left
|
||||||
%a.btn.btn-primary{href: content_url(report)}
|
%a.btn.btn-primary{href: content_url(report)}
|
||||||
|
@ -32,4 +40,4 @@
|
||||||
%button.btn.btn-default.btn-sm{type: :button, name: "mod-delete-report", data: { id: report.id }}
|
%button.btn.btn-default.btn-sm{type: :button, name: "mod-delete-report", data: { id: report.id }}
|
||||||
%i.fa.fa-trash-o
|
%i.fa.fa-trash-o
|
||||||
.panel-footer{id: "mod-comments-section-#{report.id}", style: 'display: none'}
|
.panel-footer{id: "mod-comments-section-#{report.id}", style: 'display: none'}
|
||||||
%div{id: "mod-comments-#{report.id}"}= render 'moderation/discussion', report: report
|
%div{id: "mod-comments-#{report.id}"}= render 'moderation/discussion', report: report
|
||||||
|
|
|
@ -4,4 +4,4 @@
|
||||||
= render 'moderation/moderation_tabs'
|
= render 'moderation/moderation_tabs'
|
||||||
.col-md-9.col-sm-9.col-xs-12
|
.col-md-9.col-sm-9.col-xs-12
|
||||||
- @reports.each do |r|
|
- @reports.each do |r|
|
||||||
= render 'moderation/moderationbox', report: r
|
= render 'moderation/moderationbox', report: r
|
||||||
|
|
5
db/migrate/20150422024104_add_reason_to_report.rb
Normal file
5
db/migrate/20150422024104_add_reason_to_report.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
class AddReasonToReport < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :reports, :reason, :string, default: nil
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue