Esempio n. 1
0
def patch_add_participant(request, thread, value):
    allow_add_participants(request.user, thread)

    try:
        username = six.text_type(value).strip().lower()
        if not username:
            raise PermissionDenied(
                _("You have to enter new participant's username."))
        participant = UserModel.objects.get(slug=username)
    except UserModel.DoesNotExist:
        raise PermissionDenied(_("No user with such name exists."))

    if participant in [p.user for p in thread.participants_list]:
        raise PermissionDenied(_("This user is already thread participant."))

    allow_add_participant(request.user, participant)
    add_participant(request, thread, participant)

    make_participants_aware(request.user, thread)
    participants = ThreadParticipantSerializer(
        thread.participants_list, many=True)

    return {
        'participants': participants.data
    }
Esempio n. 2
0
def patch_add_participant(request, thread, value):
    allow_add_participants(request.user, thread)

    try:
        username = six.text_type(value).strip().lower()
        if not username:
            raise ValidationError(
                _("You have to enter new participant's username."))
        participant = UserModel.objects.get(slug=username)
    except UserModel.DoesNotExist:
        raise ValidationError(_("No user with such name exists."))

    if participant in [p.user for p in thread.participants_list]:
        raise ValidationError(_("This user is already thread participant."))

    max_participants = request.user.acl_cache[
        'max_private_thread_participants']
    if max_participants:
        current_participants = len(thread.participants_list)
        if current_participants >= max_participants:
            raise ValidationError(
                _("You can't add any more new users to this thread."))

    try:
        allow_add_participant(request.user, participant)
    except PermissionDenied as e:
        raise ValidationError(six.text_type(e))

    add_participant(request, thread, participant)
    make_participants_aware(request.user, thread)
    participants = ThreadParticipantSerializer(thread.participants_list,
                                               many=True)

    return {'participants': participants.data}
Esempio n. 3
0
    def test_anonymize_added_participant_event(self):
        """added participant 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)
        add_participant(request, self.thread, user)

        user.anonymize_content()

        event = Post.objects.get(event_type='added_participant')
        self.assertEqual(event.event_context, {
            'user': {
                'id': None,
                'username': user.username,
                'url': reverse('misago:index'),
            },
        })
Esempio n. 4
0
    def action(self, request, thread, kwargs):
        form = ThreadParticipantsForm(request.POST, user=request.user)
        if not form.is_valid():
            errors = []
            for field_errors in form.errors.as_data().values():
                errors.extend([unicode(e[0]) for e in field_errors])
            return JsonResponse({'message': errors[0], 'is_error': True})

        event_message = _("%(user)s added %(participant)s to this thread.")
        participants_list = [p.user for p in thread.participants_list]
        for user in form.users_cache:
            if user not in participants_list:
                participants.add_participant(request, thread, user)
                record_event(request.user, thread, 'user', event_message, {
                    'user': request.user,
                    'participant': user
                })
                thread.save(update_fields=['has_events'])

        participants_qs = thread.threadparticipant_set
        participants_qs = participants_qs.select_related('user', 'user__rank')
        participants_qs = participants_qs.order_by('-is_owner', 'user__slug')

        participants_list = [p for p in participants_qs]

        participants_list_html = self.render(
            request, {
                'forum': thread.forum,
                'thread': thread,
                'participants': participants_list,
            }).content

        message = ungettext("%(users)s participant", "%(users)s participants",
                            len(participants_list))
        message = message % {'users': len(participants_list)}

        return JsonResponse({
            'is_error': False,
            'message': message,
            'list_html': participants_list_html
        })
Esempio n. 5
0
    def action(self, request, thread, kwargs):
        form = ThreadParticipantsForm(request.POST, user=request.user)
        if not form.is_valid():
            errors = []
            for field_errors in form.errors.as_data().values():
                errors.extend([unicode(e[0]) for e in field_errors])
            return JsonResponse({'message': errors[0], 'is_error': True})

        event_message = _("%(user)s added %(participant)s to this thread.")
        participants_list = [p.user for p in thread.participants_list]
        for user in form.users_cache:
            if user not in participants_list:
                participants.add_participant(request, thread, user)
                record_event(request.user, thread, 'user', event_message, {
                    'user': request.user,
                    'participant': user
                })
                thread.save(update_fields=['has_events'])

        participants_qs = thread.threadparticipant_set
        participants_qs = participants_qs.select_related('user', 'user__rank')
        participants_qs = participants_qs.order_by('-is_owner', 'user__slug')

        participants_list = [p for p in participants_qs]

        participants_list_html = self.render(request, {
            'forum': thread.forum,
            'thread': thread,
            'participants': participants_list,
        }).content

        message = ungettext("%(users)s participant",
                            "%(users)s participants",
                            len(participants_list))
        message = message % {'users': len(participants_list)}

        return JsonResponse({
            'is_error': False,
            'message': message,
            'list_html': participants_list_html
        })
Esempio n. 6
0
def patch_add_participant(request, thread, value):
    allow_add_participants(request.user, thread)

    try:
        username = six.text_type(value).strip().lower()
        if not username:
            raise PermissionDenied(_("You have to enter new participant's username."))
        participant = UserModel.objects.get(slug=username)
    except UserModel.DoesNotExist:
        raise PermissionDenied(_("No user with such name exists."))

    if participant in [p.user for p in thread.participants_list]:
        raise PermissionDenied(_("This user is already thread participant."))

    allow_add_participant(request.user, participant)
    add_participant(request, thread, participant)

    make_participants_aware(request.user, thread)
    participants = ThreadParticipantSerializer(thread.participants_list, many=True)

    return {'participants': participants.data}
Esempio n. 7
0
 def save(self, form):
     add_owner(self.thread, self.user)
     for user in form.users_cache:
         add_participant(self.request, self.thread, user)
Esempio n. 8
0
 def save(self, form):
     add_owner(self.thread, self.user)
     for user in form.users_cache:
         add_participant(self.request, self.thread, user)