Skip to content

Commit

Permalink
bye REPORT_ABUSE flag, I barely knew you (bug 668346)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy McKay committed Jun 30, 2011
1 parent 4cc7d04 commit 47bafe1
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 82 deletions.
23 changes: 1 addition & 22 deletions apps/addons/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import amo
from amo.helpers import absolutify
from amo.urlresolvers import reverse
from amo.tests.test_helpers import AbuseBase, AbuseDisabledBase
from amo.tests.test_helpers import AbuseBase
from addons.models import Addon, AddonUser, Charity
from files.models import File
from paypal.tests import other_error
Expand Down Expand Up @@ -1205,7 +1205,6 @@ class TestReportAbuse(AbuseBase, test_utils.TestCase):
'base/users']

def setUp(self):
settings.REPORT_ABUSE = True
settings.RECAPTCHA_PRIVATE_KEY = 'something'
self.full_page = reverse('addons.abuse', args=['a3615'])

Expand Down Expand Up @@ -1233,26 +1232,6 @@ def test_abuse_persona(self):
assert 'spammy' in mail.outbox[0].body


class TestReportAbuseDisabled(AbuseDisabledBase, test_utils.TestCase):
fixtures = ['addons/persona',
'base/apps',
'base/addon_3615',
'base/users']

def setUp(self):
settings.REPORT_ABUSE = False
self.full_page = reverse('addons.abuse', args=['a3615'])
self.inline_page = reverse('addons.detail', args=['a3615'])

def tearDown(self):
settings.REPORT_ABUSE = True

def test_abuse_persona(self):
r = self.client.get(reverse('addons.detail', args=['a15663']))
doc = pq(r.content)
assert not doc("fieldset.abuse")


class TestMobile(test_utils.TestCase):
fixtures = ['addons/featured', 'base/apps', 'base/addon_3615',
'base/featured', 'bandwagon/featured_collections']
Expand Down
20 changes: 8 additions & 12 deletions apps/addons/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,8 @@ def extension_detail(request, addon):
'get_replies': Review.get_replies,

'collections': collections.order_by('-subscribers')[:3],
'abuse_form': AbuseForm(request=request),
}
if settings.REPORT_ABUSE:
data['abuse_form'] = AbuseForm(request=request)

return jingo.render(request, 'addons/details.html', data)

Expand Down Expand Up @@ -212,9 +211,8 @@ def impala_extension_detail(request, addon):
'reviews': Review.objects.latest().filter(addon=addon),
'get_replies': Review.get_replies,
'collections': collections.order_by('-subscribers')[:3],
'abuse_form': AbuseForm(request=request),
}
if settings.REPORT_ABUSE:
ctx['abuse_form'] = AbuseForm(request=request)

return jingo.render(request, 'addons/impala/details.html', ctx)

Expand Down Expand Up @@ -268,10 +266,10 @@ def persona_detail(request, addon, template=None):
'review_form': ReviewForm(),
'reviews': Review.objects.latest().filter(addon=addon),
'get_replies': Review.get_replies,
'search_cat': 'personas'
'search_cat': 'personas',
'abuse_form': AbuseForm(request=request),
})
if settings.REPORT_ABUSE:
data['abuse_form'] = AbuseForm(request=request)

return jingo.render(request, template, data)


Expand Down Expand Up @@ -431,8 +429,9 @@ def home(request):
# Get some featured add-ons with randomness.
featured = Addon.featured_random(request.APP, request.LANG)
# Get 10 popular add-ons, then pick 3 at random.
qs = list(Addon.objects.listed(request.APP).order_by('-average_daily_users')
.values_list('id', flat=True)[:10])
qs = list(Addon.objects.listed(request.APP)
.order_by('-average_daily_users')
.values_list('id', flat=True)[:10])
popular = rand(qs)
# Do one query and split up the add-ons.
addons = Addon.objects.filter(id__in=featured + popular)
Expand Down Expand Up @@ -752,9 +751,6 @@ def license_redirect(request, version):
@session_csrf.anonymous_csrf_exempt
@addon_view
def report_abuse(request, addon):
if not settings.REPORT_ABUSE:
raise http.Http404()

form = AbuseForm(request.POST or None, request=request)
if request.method == "POST" and form.is_valid():
url = reverse('addons.detail', args=[addon.slug])
Expand Down
21 changes: 1 addition & 20 deletions apps/amo/tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def test_url(mock_reverse):
mock_reverse.assert_called_with('viewname', args=(1,), kwargs={'z': 2},
add_prefix=True)

s = render('{{ url("viewname", 1, z=2, host="myhost") }}')
render('{{ url("viewname", 1, z=2, host="myhost") }}')
mock_reverse.assert_called_with('viewname', args=(1,), kwargs={'z': 2},
add_prefix=True)

Expand Down Expand Up @@ -323,25 +323,6 @@ def test_abuse_logged_in(self):
assert 'spammy' in mail.outbox[0].body


class AbuseDisabledBase:
def test_abuse_fails_anonymous(self):
r = self.client.get(self.inline_page)
doc = PyQuery(r.content)
assert not doc("fieldset.abuse")

res = self.client.post(self.full_page, {'text': 'spammy'})
eq_(res.status_code, 404)

def test_abuse_fails_logged_in(self):
self.client.login(username='regular@mozilla.com', password='password')
r = self.client.get(self.inline_page)
doc = PyQuery(r.content)
assert not doc("fieldset.abuse")

res = self.client.post(self.full_page)
eq_(res.status_code, 404)


def get_image_path(name):
return os.path.join(settings.ROOT, 'apps', 'amo', 'tests', 'images', name)

Expand Down
15 changes: 1 addition & 14 deletions apps/users/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from amo.helpers import urlparams
from amo.pyquery_wrapper import PyQuery
from amo.urlresolvers import reverse
from amo.tests.test_helpers import AbuseBase, AbuseDisabledBase
from amo.tests.test_helpers import AbuseBase
from users.models import BlacklistedPassword, UserProfile
from users.utils import EmailResetCode

Expand Down Expand Up @@ -374,18 +374,5 @@ class TestReportAbuse(AbuseBase, test_utils.TestCase):
fixtures = ['base/users']

def setUp(self):
settings.REPORT_ABUSE = True
settings.RECAPTCHA_PRIVATE_KEY = 'something'
self.full_page = reverse('users.abuse', args=[10482])


class TestReportAbuseDisabled(AbuseDisabledBase, test_utils.TestCase):
fixtures = ['base/users']

def setUp(self):
settings.REPORT_ABUSE = False
self.inline_page = reverse('users.profile', args=[10482])
self.full_page = reverse('users.abuse', args=[10482])

def tearDown(self):
settings.REPORT_ABUSE = True
18 changes: 7 additions & 11 deletions apps/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def _clean_next_url(request):

gets['to'] = url

domain = gets.get('domain',None)
domain = gets.get('domain', None)
if domain in settings.VALID_LOGIN_REDIRECTS.keys():
gets['to'] = "%s%s" % (settings.VALID_LOGIN_REDIRECTS[domain], url)

Expand All @@ -251,16 +251,17 @@ def login(request):

if isinstance(r, http.HttpResponseRedirect):
# Django's auth.views.login has security checks to prevent someone from
# redirecting to another domain. Since we want to allow this in certain
# cases, we have to make a new response object here to replace the above
# redirecting to another domain. Since we want to allow this in
# certain cases, we have to make a new response object here to replace
# the above.
if 'domain' in request.GET:
request.GET = get_copy
request = _clean_next_url(request)
r = http.HttpResponseRedirect(request.GET['to'])

# Succsesful log in according to django. Now we do our checks. I do
# the checks here instead of the form's clean() because I want to use
# the messages framework and it's not available in the request there
# the messages framework and it's not available in the request there.
user = request.user.get_profile()

if user.deleted:
Expand Down Expand Up @@ -362,10 +363,8 @@ def get_addons(reviews):

data = {'profile': user, 'own_coll': own_coll, 'reviews': reviews,
'fav_coll': fav_coll, 'edit_any_user': edit_any_user,
'addons': addons, 'own_profile': own_profile}

if settings.REPORT_ABUSE:
data['abuse_form'] = AbuseForm(request=request)
'addons': addons, 'own_profile': own_profile,
'abuse_form': AbuseForm(request=request)}

return jingo.render(request, 'users/profile.html', data)

Expand Down Expand Up @@ -423,9 +422,6 @@ def register(request):

@anonymous_csrf_exempt
def report_abuse(request, user_id):
if not settings.REPORT_ABUSE:
raise http.Http404()

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():
Expand Down
3 changes: 0 additions & 3 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -919,9 +919,6 @@ def read_only_mode(env):

PERF_THRESHOLD = 25

# flag to turn on or off Abuse reports
REPORT_ABUSE = True

REDIS_BACKENDS = {'master': 'redis://localhost:6379?socket_timeout=0.5'}

# Directory of JavaScript test files for django_qunit to run
Expand Down

0 comments on commit 47bafe1

Please sign in to comment.