Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

Commit

Permalink
Fix Bug 811751 - Hide banned user profile.
Browse files Browse the repository at this point in the history
  • Loading branch information
mediocrity committed Mar 4, 2014
1 parent bf9084a commit 131c6b8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
25 changes: 25 additions & 0 deletions apps/devmo/tests/test_views.py
Expand Up @@ -25,6 +25,8 @@
from sumo.tests import TestCase
from sumo.urlresolvers import reverse

from users.models import UserBan

from waffle.models import Flag

TESTUSER_PASSWORD = 'testpass'
Expand Down Expand Up @@ -399,6 +401,29 @@ def _break(self, url, r):
logging.debug("CONT %s" % r.content)
ok_(False)

def test_bug_811751_banned_profile(self):
"""A banned user's profile should not be viewable"""
profile = UserProfile.objects.get(user__username='testuser')
user = profile.user
url = reverse('devmo.views.profile_view',
args=(user.username,))

# Profile viewable if not banned
response = self.client.get(url, follow=True)
self.assertNotEqual(response.status_code, 403)

# Ban User
admin = User.objects.get(username='admin')
testuser = User.objects.get(username='testuser')
ban = UserBan(user=testuser, by=admin,
reason='Banned by unit test.',
is_active=True)
ban.save()

# Profile not viewable if banned
response = self.client.get(url, follow=True)
self.assertEqual(response.status_code, 403)


def get_datetime_from_string(string, string_format):
new_datetime = datetime.datetime.fromtimestamp(time.mktime(
Expand Down
4 changes: 4 additions & 0 deletions apps/devmo/views.py
Expand Up @@ -16,6 +16,7 @@
from demos.models import Submission
from teamwork.models import Team
from badger.models import Award
from users.models import UserBan

from . import INTEREST_SUGGESTIONS
from .models import Calendar, Event, UserProfile
Expand Down Expand Up @@ -48,6 +49,9 @@ def profile_view(request, username):
profile = get_object_or_404(UserProfile, user__username=username)
user = profile.user

if UserBan.objects.filter(user=user, is_active=True):
return HttpResponseForbidden()

DEMOS_PAGE_SIZE = getattr(settings, 'DEMOS_PAGE_SIZE', 12)
sort_order = request.GET.get('sort', 'created')
try:
Expand Down

0 comments on commit 131c6b8

Please sign in to comment.