Skip to content

Commit

Permalink
Inactive user profiles are 404s.
Browse files Browse the repository at this point in the history
  • Loading branch information
James Socol committed Oct 28, 2011
1 parent 33d3c72 commit 4524ce8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
26 changes: 25 additions & 1 deletion apps/users/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,4 +395,28 @@ def test_create_setting(self):
res = self.client.post(url, {'forums_watch_new_thread': True},
follow=True)
eq_(200, res.status_code)
eq_(Setting.get_for_user(self.user, 'forums_watch_new_thread'), True)
assert Setting.get_for_user(self.user, 'forums_watch_new_thread')


class UserProfileTests(TestCase):
def setUp(self):
self.user = user()
self.user.save()
self.profile = profile(self.user)
self.url = reverse('users.profile', args=[self.user.pk],
locale='en-US')

def test_profile(self):
res = self.client.get(self.url)
self.assertContains(res, self.user.username)

def test_profile_inactive(self):
"""Inactive users don't have a public profile."""
self.user.is_active = False
self.user.save()
res = self.client.get(self.url)
eq_(404, res.status_code)

def test_profile_post(self):
res = self.client.post(self.url)
eq_(405, res.status_code)
4 changes: 3 additions & 1 deletion apps/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,10 @@ def confirm_change_email(request, activation_key):
'username': u.username, 'duplicate': duplicate})


@require_GET
def profile(request, user_id):
user_profile = get_object_or_404(Profile, user__id=user_id)
user_profile = get_object_or_404(Profile, user__id=user_id,
user__is_active=True)
groups = user_profile.user.groups.all()
return jingo.render(request, 'users/profile.html',
{'profile': user_profile, 'groups': groups})
Expand Down

0 comments on commit 4524ce8

Please sign in to comment.