Report replies

This commit is contained in:
Evert Prants 2018-03-01 15:48:20 +02:00
parent d7e7d5dc2c
commit c3ce46b94a
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
7 changed files with 113 additions and 5 deletions

View File

@ -15,7 +15,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
from django import forms from django import forms
from LandingPage.models import DiscussionBoard, DiscussionReply from LandingPage.models import DiscussionBoard, DiscussionReply, Report
class BoardForm(forms.ModelForm): class BoardForm(forms.ModelForm):
body = forms.CharField(widget=forms.Textarea) body = forms.CharField(widget=forms.Textarea)
@ -35,3 +35,8 @@ class ReplyForm(forms.ModelForm):
help_texts = { help_texts = {
'body': 'Enter your message here' 'body': 'Enter your message here'
} }
class ReportForm(forms.ModelForm):
class Meta():
model = Report
fields = ('title','details',)

View File

@ -40,6 +40,7 @@
<p class="timestamp text-muted font-weight-light">Submitted {{board.timestamp}}</p> <p class="timestamp text-muted font-weight-light">Submitted {{board.timestamp}}</p>
<div class="user-content mb-auto">{{reply.body|markdown|safe}}</div> <div class="user-content mb-auto">{{reply.body|markdown|safe}}</div>
<div class="actions d-flex flex-row-reverse"> <div class="actions d-flex flex-row-reverse">
<a href="/show/{{show.abbr}}/discuss/board/report/{{reply.id}}" class="btn btn-secondary ml-1" title="Report" aria-label="Report"><i class="fa fa-fw fa-flag"></i></a>
<div class="vote-btns"> <div class="vote-btns">
<form method="POST" class="d-inline" action="/show/{{show.abbr}}/discuss/vote/{{reply.id}}/1"> <form method="POST" class="d-inline" action="/show/{{show.abbr}}/discuss/vote/{{reply.id}}/1">
{% csrf_token %} {% csrf_token %}

View File

@ -0,0 +1,36 @@
{% extends "base.html" %}
{% block title %}
Report a Post - {{reply.board.title}} - {{show.name}} Discussions - Episodes.Community
{% endblock %}
{% block content %}
<section class="container mb-5 mt-5">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="/show/{{show.abbr}}">{{show.name}}</a></li>
<li class="breadcrumb-item"><a href="/show/{{show.abbr}}/discuss">Discussions</a></li>
<li class="breadcrumb-item"><a href="/show/{{show.abbr}}/discuss/board/{{reply.board.pk}}-{{reply.board.title|slugify}}">{{reply.board.title}}</a></li>
<li class="breadcrumb-item active" aria-current="page">Report</li>
</ol>
</nav>
<h1>Report a Post</h1>
{% if error %}
<div class="alert alert-danger">{{error}}</div>
{% endif %}
<form action="" method="post">
<div class="bg-light p-4 mb-4">
<div class="submitter font-weight-bold">Posted by {{ reply.user.display_name }}</div>
<div class="body font-weight-light text-muted">{{ reply.body }}</div>
{% if reply.user.is_staff %}
<div class="alert alert-danger">
<b>Warning</b>
<p>This reply is made by a staff member. Unnecessary reporters <b>will</b> be banned.</p>
</div>
{% endif %}
</div>
{% include "form.html" %}
<div class="form-group">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</section>
{% endblock %}

View File

@ -22,6 +22,7 @@ urlpatterns = [
url(r'^$', views.Boards.as_view()), url(r'^$', views.Boards.as_view()),
url(r'^vote/(?P<replyid>\d+)/(?P<positive>[0-1])/?$', views.BoardVoteSubmit.as_view()), url(r'^vote/(?P<replyid>\d+)/(?P<positive>[0-1])/?$', views.BoardVoteSubmit.as_view()),
url(r'^board/new$', views.BoardForm), url(r'^board/new$', views.BoardForm),
url(r'^board/report/(?P<rid>\d{1,4})/?$', views.ReportForm),
url(r'^board/reply/(?P<bid>\d{1,4})/?$', views.BoardReplyForm), url(r'^board/reply/(?P<bid>\d{1,4})/?$', views.BoardReplyForm),
url(r'^board/(?P<bid>\d{1,4})(-[\w-]+)?/?$', views.Board.as_view()), url(r'^board/(?P<bid>\d{1,4})(-[\w-]+)?/?$', views.Board.as_view()),
] ]

View File

@ -28,7 +28,7 @@ from django.utils.text import slugify
from guardian.decorators import permission_required_or_403 from guardian.decorators import permission_required_or_403
from LandingPage.models import Show, DiscussionBoard, DiscussionReply, DiscussionVote, Ban from LandingPage.models import Show, DiscussionBoard, DiscussionReply, DiscussionVote, Ban, Report
from . import forms from . import forms
import datetime import datetime
@ -282,3 +282,56 @@ class BoardVoteSubmit(LoginRequiredMixin, View):
new_vote.save() new_vote.save()
return HttpResponseRedirect('/show/%s/discuss/board/%d-%s?findReply=%d'%(abbr, reply.board.pk, slugify(reply.board.title), reply.pk)) return HttpResponseRedirect('/show/%s/discuss/board/%d-%s?findReply=%d'%(abbr, reply.board.pk, slugify(reply.board.title), reply.pk))
@login_required
def ReportForm(req, abbr, rid):
show = get_object_or_404(Show, abbr=abbr)
reply = get_object_or_404(DiscussionReply, pk=rid,board__show=show)
user = req.user
form = forms.ReportForm()
# Get bans for this user regarding this show
bans = Ban.objects.filter(Q(expiration__gte=datetime.datetime.now()) | Q(permanent=True), user=user, site_wide=True)
if bans.count() > 0:
return HttpResponseForbidden('You are banned from the site and therefor not allowed to create reports.<br>Reason: %s'%(bans.first().reason))
# Request context
ctx = {
'form': form,
'show': show,
'reply': reply
}
url = '/show/%s/discuss/board/%d-%s?findReply=%d'%(abbr, reply.board.pk, slugify(reply.board.title), reply.pk)
# Handle POST
if req.method == 'POST':
form = forms.ReportForm(req.POST)
ctx['form'] = form
if form.is_valid():
form_data = form.cleaned_data
if not user.has_perm('LandingPage.can_moderate_board', show):
# Check if there have been many reports by this user within the last 12 hours
if Report.objects.filter(user=user,timestamp__gte=datetime.datetime.now() - datetime.timedelta(hours=12)).count() > 5:
ctx['error'] = 'You\'ve created too many reports recently!'
return render(req, "report_reply.html", ctx)
if Report.objects.filter(url=url).count() > 1:
ctx['error'] = 'This reply has already been brought to our attention! Thank you for reporting.'
return render(req, "report_reply.html", ctx)
# Save
new_report = form.save(commit=False)
new_report.reporter = user
new_report.url = url
new_report.save()
return HttpResponseRedirect('/show/%s/discuss/board/%d-%s'%(abbr, reply.board.pk, slugify(reply.board.title)))
else:
ctx['error'] = 'Invalid fields!'
return render(req, "report_reply.html", ctx)

View File

@ -449,4 +449,4 @@ class DiscussionVote(TimestampedModel):
help_text='If true, the vote is an upvote. Otherwise, it is a downvote. Neutral votes are not recorded' help_text='If true, the vote is an upvote. Otherwise, it is a downvote. Neutral votes are not recorded'
) )
def __str__(self): def __str__(self):
return "%s %s %s"%(self.user, '\U0001f592' if self.positive else '\U0001f44e', self.board.title) return "%s %s reply %d"%(self.user, '\U0001f592' if self.positive else '\U0001f44e', self.reply.pk)

View File

@ -26,7 +26,7 @@ from django.contrib.auth.mixins import LoginRequiredMixin
from guardian.decorators import permission_required_or_403 from guardian.decorators import permission_required_or_403
from LandingPage.models import User, Show, Season, Episode, Submission, SubmissionVote, Ban from LandingPage.models import User, Show, Season, Episode, Submission, SubmissionVote, Ban, Report
from . import forms from . import forms
@ -390,6 +390,8 @@ def ReportSubmission(req, abbr, submission):
'submission': submission 'submission': submission
} }
url = '/show/%s/episode/%d/%d?submission=%s'%(abbr, episode.season.number, episode.episode,submission.pk)
# Handle POST # Handle POST
if req.method == 'POST': if req.method == 'POST':
form = forms.ReportForm(req.POST) form = forms.ReportForm(req.POST)
@ -398,10 +400,20 @@ def ReportSubmission(req, abbr, submission):
if form.is_valid(): if form.is_valid():
form_data = form.cleaned_data form_data = form.cleaned_data
if not user.has_perm('LandingPage.can_moderate_show', show):
# Check if there have been many reports by this user within the last 12 hours
if Report.objects.filter(user=user,timestamp__gte=datetime.datetime.now() - datetime.timedelta(hours=12)).count() > 5:
ctx['error'] = 'You\'ve created too many reports recently!'
return render(req, "report_reply.html", ctx)
if Report.objects.filter(url=url).count() > 1:
ctx['error'] = 'This submission has already been brought to our attention! Thank you for reporting.'
return render(req, "report_reply.html", ctx)
# Save # Save
new_report = form.save(commit=False) new_report = form.save(commit=False)
new_report.reporter = user new_report.reporter = user
new_report.url = '/show/%s/episode/%d/%d?submission=%s'%(abbr, episode.season.number, episode.episode,submission.pk) new_report.url = url
new_report.save() new_report.save()
return HttpResponseRedirect('/show/%s/episode/%d/%d'%(abbr, episode.season.number, episode.episode)) return HttpResponseRedirect('/show/%s/episode/%d/%d'%(abbr, episode.season.number, episode.episode))