Exemplo n.º 1
0
    def test_delete_other_and_owned_warnings(self):
        """delete everyone's warnings"""
        warning = warn_user(self.test_user, self.test_user)

        self.allow_delete_all_warnings()
        response = self.client.post(
            reverse('misago:delete_warning', kwargs={
                'user_slug': 'bob',
                'user_id': self.test_user.pk,
                'warning_id': warning.pk
            }))
        self.assertEqual(response.status_code, 302)
        self.assertEqual(self.test_user.warnings.count(), 0)

        warning = warn_user(self.user, self.test_user)

        self.allow_delete_all_warnings()
        response = self.client.post(
            reverse('misago:delete_warning', kwargs={
                'user_slug': 'bob',
                'user_id': self.test_user.pk,
                'warning_id': warning.pk
            }))
        self.assertEqual(response.status_code, 302)
        self.assertEqual(self.test_user.warnings.count(), 0)
Exemplo n.º 2
0
    def test_no_permission_other(self):
        """can't cancel other mod warnings"""
        warning = warn_user(self.test_user, self.test_user)

        self.allow_cancel_owned_warning()
        response = self.client.post(
            reverse('misago:cancel_warning', kwargs={
                'user_slug': 'bob',
                'user_id': self.test_user.pk,
                'warning_id': warning.pk
            }))
        self.assertEqual(response.status_code, 403)
        self.assertFalse(
            self.test_user.warnings.get(id=warning.pk).is_canceled)

        warning = warn_user(self.user, self.test_user)
        self.allow_cancel_owned_warning()
        response = self.client.post(
            reverse('misago:cancel_warning', kwargs={
                'user_slug': 'bob',
                'user_id': self.test_user.pk,
                'warning_id': warning.pk
            }))
        self.assertEqual(response.status_code, 302)

        warning = self.test_user.warnings.get(id=warning.pk)
        self.assertTrue(self.test_user.warnings.get(id=warning.pk).is_canceled)
Exemplo n.º 3
0
    def test_no_permission_other(self):
        """can't delete other mod warnings"""
        warning = warn_user(self.test_user, self.test_user)

        self.allow_delete_owned_warning()
        response = self.client.post(
            reverse('misago:delete_warning', kwargs={
                'user_slug': 'bob',
                'user_id': self.test_user.pk,
                'warning_id': warning.pk
            }))
        self.assertEqual(response.status_code, 403)
        self.assertEqual(self.test_user.warnings.count(), 1)

        warning = warn_user(self.user, self.test_user)

        self.allow_delete_owned_warning()
        response = self.client.post(
            reverse('misago:delete_warning', kwargs={
                'user_slug': 'bob',
                'user_id': self.test_user.pk,
                'warning_id': warning.pk
            }))
        self.assertEqual(response.status_code, 302)
        self.assertEqual(self.test_user.warnings.count(), 1)
Exemplo n.º 4
0
    def test_cancel_other_and_owned_warnings(self):
        """cancel everyone's warnings"""
        warning = warn_user(self.test_user, self.test_user)

        self.allow_cancel_all_warnings()
        response = self.client.post(
            reverse('misago:cancel_warning', kwargs={
                'user_slug': 'bob',
                'user_id': self.test_user.pk,
                'warning_id': warning.pk
            }))
        self.assertEqual(response.status_code, 302)
        self.assertTrue(self.test_user.warnings.get(id=warning.pk).is_canceled)

        warning = warn_user(self.user, self.test_user)

        self.allow_cancel_all_warnings()
        response = self.client.post(
            reverse('misago:cancel_warning', kwargs={
                'user_slug': 'bob',
                'user_id': self.test_user.pk,
                'warning_id': warning.pk
            }))
        self.assertEqual(response.status_code, 302)
        self.assertTrue(self.test_user.warnings.get(id=warning.pk).is_canceled)
Exemplo n.º 5
0
    def test_no_permission_other(self):
        """can't delete other mod warnings"""
        warning = warn_user(self.test_user, self.test_user)

        self.allow_delete_owned_warning()
        response = self.client.post(
            reverse('misago:delete_warning',
                    kwargs={
                        'user_slug': 'bob',
                        'user_id': self.test_user.pk,
                        'warning_id': warning.pk
                    }))
        self.assertEqual(response.status_code, 403)
        self.assertEqual(self.test_user.warnings.count(), 1)

        warning = warn_user(self.user, self.test_user)

        self.allow_delete_owned_warning()
        response = self.client.post(
            reverse('misago:delete_warning',
                    kwargs={
                        'user_slug': 'bob',
                        'user_id': self.test_user.pk,
                        'warning_id': warning.pk
                    }))
        self.assertEqual(response.status_code, 302)
        self.assertEqual(self.test_user.warnings.count(), 1)
Exemplo n.º 6
0
    def test_delete_other_and_owned_warnings(self):
        """delete everyone's warnings"""
        warning = warn_user(self.test_user, self.test_user)

        self.allow_delete_all_warnings()
        response = self.client.post(
            reverse('misago:delete_warning',
                    kwargs={
                        'user_slug': 'bob',
                        'user_id': self.test_user.pk,
                        'warning_id': warning.pk
                    }))
        self.assertEqual(response.status_code, 302)
        self.assertEqual(self.test_user.warnings.count(), 0)

        warning = warn_user(self.user, self.test_user)

        self.allow_delete_all_warnings()
        response = self.client.post(
            reverse('misago:delete_warning',
                    kwargs={
                        'user_slug': 'bob',
                        'user_id': self.test_user.pk,
                        'warning_id': warning.pk
                    }))
        self.assertEqual(response.status_code, 302)
        self.assertEqual(self.test_user.warnings.count(), 0)
Exemplo n.º 7
0
    def test_cancel_other_and_owned_warnings(self):
        """cancel everyone's warnings"""
        warning = warn_user(self.test_user, self.test_user)

        self.allow_cancel_all_warnings()
        response = self.client.post(
            reverse('misago:cancel_warning',
                    kwargs={
                        'user_slug': 'bob',
                        'user_id': self.test_user.pk,
                        'warning_id': warning.pk
                    }))
        self.assertEqual(response.status_code, 302)
        self.assertTrue(self.test_user.warnings.get(id=warning.pk).is_canceled)

        warning = warn_user(self.user, self.test_user)

        self.allow_cancel_all_warnings()
        response = self.client.post(
            reverse('misago:cancel_warning',
                    kwargs={
                        'user_slug': 'bob',
                        'user_id': self.test_user.pk,
                        'warning_id': warning.pk
                    }))
        self.assertEqual(response.status_code, 302)
        self.assertTrue(self.test_user.warnings.get(id=warning.pk).is_canceled)
Exemplo n.º 8
0
    def test_no_permission_other(self):
        """can't cancel other mod warnings"""
        warning = warn_user(self.test_user, self.test_user)

        self.allow_cancel_owned_warning()
        response = self.client.post(
            reverse('misago:cancel_warning',
                    kwargs={
                        'user_slug': 'bob',
                        'user_id': self.test_user.pk,
                        'warning_id': warning.pk
                    }))
        self.assertEqual(response.status_code, 403)
        self.assertFalse(
            self.test_user.warnings.get(id=warning.pk).is_canceled)

        warning = warn_user(self.user, self.test_user)
        self.allow_cancel_owned_warning()
        response = self.client.post(
            reverse('misago:cancel_warning',
                    kwargs={
                        'user_slug': 'bob',
                        'user_id': self.test_user.pk,
                        'warning_id': warning.pk
                    }))
        self.assertEqual(response.status_code, 302)

        warning = self.test_user.warnings.get(id=warning.pk)
        self.assertTrue(self.test_user.warnings.get(id=warning.pk).is_canceled)
Exemplo n.º 9
0
def warn(request, user, reason=None):
    return_path = moderation_return_path(request, user)

    if warnings.is_user_warning_level_max(user):
        message = _("%(user)s has maximum warning "
                    "level and can't be warned.")
        message = message % {'user': user.username}
        messages.info(request, message)

        return redirect(return_path)

    form = WarnUserForm(initial={'reason': reason})
    if request.method == 'POST':
        form = WarnUserForm(request.POST)
        if form.is_valid():
            warnings.warn_user(request.user, user, form.cleaned_data['reason'])

            notify_user(user,
                        _("%(user)s has given you an warning."),
                        reverse('misago:user_warnings',
                                kwargs={
                                    'user_slug': user.slug,
                                    'user_id': user.pk
                                }),
                        "warnings_%s" % user.pk,
                        formats={'user': request.user.username},
                        sender=request.user)

            message = _("%(user)s has been warned.")
            message = message % {'user': user.username}
            messages.success(request, message)

            return redirect(return_path)

    warning_levels = warnings.get_warning_levels()
    current_level = warning_levels[user.warning_level]
    next_level = warning_levels[user.warning_level + 1]

    return render(
        request, 'misago/modusers/warn.html', {
            'profile': user,
            'form': form,
            'return_path': return_path,
            'current_level': current_level,
            'next_level': next_level
        })
Exemplo n.º 10
0
    def test_warnings(self):
        """user warning levels is obtained"""
        threadstore.clear()
        cache.clear()

        self.assertTrue(warnings.is_user_warning_level_max(self.test_user))

        levels = (
            WarningLevel.objects.create(name="Level 1"),
            WarningLevel.objects.create(name="Level 2"),
            WarningLevel.objects.create(name="Level 3"),
            WarningLevel.objects.create(name="Level 4"),
            WarningLevel.objects.create(name="Level 5"),
            WarningLevel.objects.create(name="Level 6"),
            WarningLevel.objects.create(name="Level 7"),
            WarningLevel.objects.create(name="Level 8"),
        )

        self.assertEqual(WarningLevel.objects.count(), 8)

        threadstore.clear()
        cache.clear()

        for level, warning in enumerate(levels):
            warnings.warn_user(self.test_mod, self.test_user, "bawww")

            user_level = warnings.get_user_warning_level(self.test_user)
            user_level_obj = warnings.get_user_warning_obj(self.test_user)

            self.assertEqual(user_level, level + 1)
            self.assertEqual(user_level_obj.name, levels[level].name)
            self.assertEqual(self.test_user.warning_level, level + 1)

        self.assertTrue(warnings.is_user_warning_level_max(self.test_user))

        previous_level = user_level
        for warning in self.test_user.warnings.all():
            warnings.cancel_warning(self.test_mod, self.test_user, warning)
            user_level = warnings.get_user_warning_level(self.test_user)
            self.assertEqual(user_level + 1, previous_level)
            previous_level = user_level

        self.assertEqual(0, warnings.get_user_warning_level(self.test_user))
Exemplo n.º 11
0
def warn(request, user, reason=None):
    return_path = moderation_return_path(request, user)

    if warnings.is_user_warning_level_max(user):
        message = _("%(user)s has maximum warning "
                    "level and can't be warned.")
        message = message % {'user': user.username}
        messages.info(request, message)

        return redirect(return_path)

    form = WarnUserForm(initial={'reason': reason})
    if request.method == 'POST':
        form = WarnUserForm(request.POST)
        if form.is_valid():
            warnings.warn_user(request.user, user, form.cleaned_data['reason'])

            notify_user(user,
                _("%(user)s has given you an warning."),
                reverse('misago:user_warnings', kwargs={
                    'user_slug': user.slug, 'user_id': user.pk
                }),
                "warnings_%s" % user.pk,
                formats={'user': request.user.username},
                sender=request.user)

            message = _("%(user)s has been warned.")
            message = message % {'user': user.username}
            messages.success(request, message)

            return redirect(return_path)

    warning_levels = warnings.get_warning_levels()
    current_level = warning_levels[user.warning_level]
    next_level = warning_levels[user.warning_level + 1]

    return render(request, 'misago/modusers/warn.html', {
        'profile': user,
        'form': form,
        'return_path': return_path,
        'current_level': current_level,
        'next_level': next_level
    })
Exemplo n.º 12
0
    def test_warnings(self):
        """user warning levels is obtained"""
        threadstore.clear()
        cache.clear()

        self.assertTrue(warnings.is_user_warning_level_max(self.test_user))

        levels = (WarningLevel.objects.create(name="Level 1"),
                  WarningLevel.objects.create(name="Level 2"),
                  WarningLevel.objects.create(name="Level 3"),
                  WarningLevel.objects.create(name="Level 4"),
                  WarningLevel.objects.create(name="Level 5"),
                  WarningLevel.objects.create(name="Level 6"),
                  WarningLevel.objects.create(name="Level 7"),
                  WarningLevel.objects.create(name="Level 8"))

        self.assertEqual(WarningLevel.objects.count(), 8)

        threadstore.clear()
        cache.clear()

        for level, warning in enumerate(levels):
            warnings.warn_user(self.test_mod, self.test_user, "bawww")

            user_level = warnings.get_user_warning_level(self.test_user)
            user_level_obj = warnings.get_user_warning_obj(self.test_user)

            self.assertEqual(user_level, level + 1)
            self.assertEqual(user_level_obj.name, levels[level].name)
            self.assertEqual(self.test_user.warning_level, level + 1)

        self.assertTrue(warnings.is_user_warning_level_max(self.test_user))

        previous_level = user_level
        for warning in self.test_user.warnings.all():
            warnings.cancel_warning(self.test_mod, self.test_user, warning)
            user_level = warnings.get_user_warning_level(self.test_user)
            self.assertEqual(user_level + 1, previous_level)
            previous_level = user_level

        self.assertEqual(0, warnings.get_user_warning_level(self.test_user))
Exemplo n.º 13
0
    def test_no_permission(self):
        """can't delete warnings"""
        override_acl(self.user, {
            'can_warn_users': 1,
            'can_see_other_users_warnings': 1,
            'can_delete_warnings': 0,
        })

        warning = warn_user(self.user, self.test_user)
        response = self.client.post(
            reverse('misago:delete_warning', kwargs={
                'user_slug': 'bob',
                'user_id': self.test_user.pk,
                'warning_id': warning.pk
            }))
        self.assertEqual(response.status_code, 403)
        self.assertEqual(self.test_user.warnings.count(), 1)
Exemplo n.º 14
0
    def test_no_permission(self):
        """can't delete warnings"""
        override_acl(
            self.user, {
                'can_warn_users': 1,
                'can_see_other_users_warnings': 1,
                'can_delete_warnings': 0,
            })

        warning = warn_user(self.user, self.test_user)
        response = self.client.post(
            reverse('misago:delete_warning',
                    kwargs={
                        'user_slug': 'bob',
                        'user_id': self.test_user.pk,
                        'warning_id': warning.pk
                    }))
        self.assertEqual(response.status_code, 403)
        self.assertEqual(self.test_user.warnings.count(), 1)