Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empêche un membre non staff d'en bannir un autre #4047

Merged
merged 1 commit into from
Dec 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions zds/member/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,35 @@ def test_sanctions(self):
self.assertEqual(ban.text, u'Texte de test pour BAN TEMP')
self.assertEquals(len(mail.outbox), 6)

def test_sanctions_with_not_staff_user(self):
user = ProfileFactory().user

# we need staff right for update the sanction of an user, so a member who is not staff can't access to the page
self.client.logout()
self.client.login(username=user.username, password="hostel77")

# Test: LS
result = self.client.post(
reverse(
'member-modify-profile', kwargs={
'user_pk': self.staff.id}), {
'ls': '', 'ls-text': 'Texte de test pour LS'}, follow=False)

self.assertEqual(result.status_code, 403)

# if the user is staff, he can update the sanction of an user
self.client.logout()
self.client.login(username=self.staff.username, password="hostel77")

# Test: LS
result = self.client.post(
reverse(
'member-modify-profile', kwargs={
'user_pk': user.id}), {
'ls': '', 'ls-text': 'Texte de test pour LS'}, follow=False)

self.assertEqual(result.status_code, 302)

def test_failed_bot_sanctions(self):

staff = StaffProfileFactory()
Expand Down
3 changes: 3 additions & 0 deletions zds/member/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,9 @@ def unregister(request):
def modify_profile(request, user_pk):
"""Modifies sanction of a user if there is a POST request."""

if not request.user.has_perm('member.change_profile'):
raise PermissionDenied

profile = get_object_or_404(Profile, user__pk=user_pk)
if profile.is_private():
raise PermissionDenied
Expand Down