add in user abuse page (bug 775883)
This commit is contained in:
Родитель
d04d0c072c
Коммит
c10166dbb4
|
@ -0,0 +1,33 @@
|
|||
{% extends 'mkt/base.html' %}
|
||||
|
||||
{% set title = _('Report Abuse') %}
|
||||
{% block title %}
|
||||
{# L10n: {0} is the name of the user. #}
|
||||
{{ mkt_page_title(_('Report abuse for {0}')|f(user.name)) }}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{{ mkt_breadcrumbs(product, [(None, title)]) }}
|
||||
<section id="abuse" class="friendly">
|
||||
<div>
|
||||
<h1>{{ title }}</h1>
|
||||
<p>
|
||||
<label id="recap-label" for="{{ abuse_form.text.auto_id }}">
|
||||
{% trans %}
|
||||
If you suspect this user violates our policies, please use the
|
||||
form below to describe your concerns. Please do not use this form
|
||||
for any other reason.
|
||||
{% endtrans %}
|
||||
</label>
|
||||
</p>
|
||||
<form method="post">
|
||||
{% include 'site/helpers/abuse.html' %}
|
||||
<p class="form-footer">
|
||||
<button type="submit">{{ _('Send Report') }}</button> {{ _('or') }}
|
||||
{# TODO: bounce to somewhere more useful #}
|
||||
<a href="/">{{ _('Cancel') }}</a>
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
</section>
|
||||
{% endblock %}
|
|
@ -12,6 +12,7 @@ from nose.tools import eq_
|
|||
from pyquery import PyQuery as pq
|
||||
import waffle
|
||||
|
||||
from abuse.models import AbuseReport
|
||||
from access.models import Group, GroupUser
|
||||
import amo
|
||||
import amo.tests
|
||||
|
@ -829,3 +830,33 @@ class TestPurchases(PurchaseBase):
|
|||
"Expected '.item' to have 'reversed' class")
|
||||
assert not item.find('a.request-support'), (
|
||||
"Unexpected 'Request Support' link")
|
||||
|
||||
|
||||
class TestAbuse(amo.tests.TestCase):
|
||||
fixtures = ['base/users']
|
||||
|
||||
def setUp(self):
|
||||
self.user = UserProfile.objects.get(email='regular@mozilla.com')
|
||||
self.url = reverse('users.abuse', args=[self.user.pk])
|
||||
|
||||
def test_add(self):
|
||||
self.client.login(username='editor@mozilla.com', password='password')
|
||||
res = self.client.post(self.url, data={'text':'test'})
|
||||
eq_(res.status_code, 302)
|
||||
eq_(AbuseReport.objects.filter(user=self.user).count(), 1)
|
||||
|
||||
@mock.patch.object(settings, 'RECAPTCHA_PRIVATE_KEY', 'something')
|
||||
def test_no_recaptcha(self):
|
||||
res = self.client.post(self.url, data={'text':'test'})
|
||||
eq_(res.status_code, 200)
|
||||
self.assertFormError(res, 'abuse_form', 'recaptcha',
|
||||
'This field is required.')
|
||||
|
||||
@mock.patch.object(settings, 'RECAPTCHA_PRIVATE_KEY', 'something')
|
||||
@mock.patch('captcha.fields.ReCaptchaField.clean')
|
||||
def test_recaptcha(self, clean):
|
||||
clean.return_value = ''
|
||||
res = self.client.post(self.url, data={'text':'test', 'recaptcha': '',
|
||||
'recaptcha_shown': ''})
|
||||
eq_(res.status_code, 302)
|
||||
eq_(AbuseReport.objects.filter(user=self.user).count(), 1)
|
||||
|
|
|
@ -39,3 +39,7 @@ users_patterns = patterns('',
|
|||
url(r'''(?P<username>[^/<>"']+)$''', views.profile,
|
||||
name='users.profile'),
|
||||
)
|
||||
|
||||
abuse_patterns = patterns('',
|
||||
url(r'^abuse$', views.abuse, name='users.abuse')
|
||||
)
|
||||
|
|
|
@ -6,13 +6,16 @@ from django.shortcuts import get_object_or_404, redirect
|
|||
import commonware.log
|
||||
from commonware.response.decorators import xframe_allow
|
||||
import jingo
|
||||
from session_csrf import anonymous_csrf_exempt
|
||||
from tower import ugettext as _
|
||||
import waffle
|
||||
|
||||
from abuse.models import send_abuse_report
|
||||
from access import acl
|
||||
import amo
|
||||
from amo.decorators import (login_required, permission_required, post_required,
|
||||
write)
|
||||
from amo.forms import AbuseForm
|
||||
from amo.helpers import absolutify
|
||||
from amo.urlresolvers import reverse
|
||||
from amo.utils import paginate
|
||||
|
@ -286,3 +289,20 @@ def activity_log(request, userid):
|
|||
all_apps = request.amo_user.addons.filter(type=amo.ADDON_WEBAPP)
|
||||
return jingo.render(request, 'account/activity.html',
|
||||
{'log': _get_items(None, all_apps)})
|
||||
|
||||
|
||||
@anonymous_csrf_exempt
|
||||
def abuse(request, user_id):
|
||||
user = get_object_or_404(UserProfile, pk=user_id)
|
||||
form = AbuseForm(request.POST or None, request=request)
|
||||
if request.method == 'POST' and form.is_valid():
|
||||
send_abuse_report(request, user, form.cleaned_data['text'])
|
||||
messages.success(request, _('Abuse reported.'))
|
||||
# We don't have a profile page to redirect back to. Once the abuse
|
||||
# is reported, that would be the place I'd recommend redirecting
|
||||
# back to.
|
||||
return redirect('/')
|
||||
else:
|
||||
return jingo.render(request, 'account/abuse.html',
|
||||
{'user': user, 'abuse_form': form})
|
||||
|
||||
|
|
|
@ -23,32 +23,7 @@
|
|||
</label>
|
||||
</p>
|
||||
<form method="post">
|
||||
{{ csrf() }}
|
||||
{{ form_field(abuse_form.text, req=False, label=None, tag='p') }}
|
||||
{% if abuse_form.has_recaptcha %}
|
||||
{% from 'includes/forms.html' import required %}
|
||||
<div id="recap-container">
|
||||
<label for="recaptcha_response_field">
|
||||
{{ _('Are you human?') }} {{ required() }}
|
||||
<a href="#" id="recaptcha_help">{{ _("What's this?") }}</a>
|
||||
</label>
|
||||
<div class="recaptcha-container">
|
||||
{% trans %}
|
||||
<p>
|
||||
Please enter <strong>both words</strong> below,
|
||||
<strong>separated by a space</strong>.
|
||||
</p>
|
||||
<p>
|
||||
If this is hard to read, you can
|
||||
<a href="#" id="recaptcha_different">try different words</a> or
|
||||
<a href="#" id="recaptcha_audio">listen to something</a> instead.
|
||||
</p>
|
||||
{% endtrans %}
|
||||
<div id="recaptcha_div"></div>
|
||||
</div>
|
||||
</div>
|
||||
{{ abuse_form.recaptcha.errors }}
|
||||
{% endif %}
|
||||
{% include 'site/helpers/abuse.html' %}
|
||||
<p class="form-footer">
|
||||
<button type="submit">{{ _('Send Report') }}</button> {{ _('or') }}
|
||||
<a href="{{ product.get_detail_url() }}">{{ _('Cancel') }}</a>
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
{{ csrf() }}
|
||||
{{ form_field(abuse_form.text, req=False, label=None, tag='p') }}
|
||||
{% if abuse_form.has_recaptcha %}
|
||||
{% from 'includes/forms.html' import required %}
|
||||
<div id="recap-container">
|
||||
<label for="recaptcha_response_field">
|
||||
{{ _('Are you human?') }} {{ required() }}
|
||||
<a href="#" id="recaptcha_help">{{ _("What's this?") }}</a>
|
||||
</label>
|
||||
<div class="recaptcha-container">
|
||||
{% trans %}
|
||||
<p>
|
||||
Please enter <strong>both words</strong> below,
|
||||
<strong>separated by a space</strong>.
|
||||
</p>
|
||||
<p>
|
||||
If this is hard to read, you can
|
||||
<a href="#" id="recaptcha_different">try different words</a> or
|
||||
<a href="#" id="recaptcha_audio">listen to something</a> instead.
|
||||
</p>
|
||||
{% endtrans %}
|
||||
<div id="recaptcha_div"></div>
|
||||
</div>
|
||||
</div>
|
||||
{{ abuse_form.recaptcha.errors }}
|
||||
{% endif %}
|
|
@ -9,7 +9,8 @@ import amo
|
|||
from apps.users.views import logout
|
||||
from apps.users.urls import (detail_patterns as user_detail_patterns,
|
||||
users_patterns as users_users_patterns)
|
||||
from mkt.account.urls import (purchases_patterns, settings_patterns,
|
||||
from mkt.account.urls import (abuse_patterns, purchases_patterns,
|
||||
settings_patterns,
|
||||
users_patterns as mkt_users_patterns)
|
||||
from mkt.developers.views import login
|
||||
from mkt.purchase.urls import bluevia_services_patterns
|
||||
|
@ -66,6 +67,8 @@ urlpatterns = patterns('',
|
|||
# Support (e.g., refunds, FAQs).
|
||||
('^support/', include('mkt.support.urls')),
|
||||
|
||||
# Override the legacy abuse page for one that works.
|
||||
('^user/(?P<user_id>\d+)/', include(abuse_patterns)),
|
||||
# Users (Legacy).
|
||||
('^user/(?P<user_id>\d+)/', include(user_detail_patterns)),
|
||||
('^users/', include(users_users_patterns)),
|
||||
|
|
Загрузка…
Ссылка в новой задаче