예제 #1
0
    def test_anonymize_changed_owner_event(self):
        """changed owner event is anonymized by user.anonymize_content"""
        user = get_mock_user()
        request = self.get_request()

        set_owner(self.thread, self.user)
        make_participants_aware(self.user, self.thread)
        change_owner(request, self.thread, user)

        user.anonymize_content()

        event = Post.objects.get(event_type='changed_owner')
        self.assertEqual(event.event_context, {
            'user': {
                'id': None,
                'username': user.username,
                'url': reverse('misago:index'),
            },
        })
예제 #2
0
def patch_replace_owner(request, thread, value):
    try:
        user_id = int(value)
    except (ValueError, TypeError):
        user_id = 0

    for participant in thread.participants_list:
        if participant.user_id == user_id:
            if participant.is_owner:
                raise PermissionDenied(_("This user already is thread owner."))
            else:
                break
    else:
        raise PermissionDenied(_("Participant doesn't exist."))

    allow_change_owner(request.user, thread)
    change_owner(request, thread, participant.user)

    make_participants_aware(request.user, thread)
    participants = ThreadParticipantSerializer(thread.participants_list, many=True)
    return {'participants': participants.data}
예제 #3
0
def patch_replace_owner(request, thread, value):
    try:
        user_id = int(value)
    except (TypeError, ValueError):
        raise ValidationError(_("A valid integer is required."))

    for participant in thread.participants_list:
        if participant.user_id == user_id:
            if participant.is_owner:
                raise ValidationError(_("This user already is thread owner."))
            else:
                break
    else:
        raise ValidationError(_("Participant doesn't exist."))

    allow_change_owner(request.user, thread)
    change_owner(request, thread, participant.user)

    make_participants_aware(request.user, thread)
    participants = ThreadParticipantSerializer(thread.participants_list, many=True)
    return {'participants': participants.data}