Esempio n. 1
0
def revoke_invitation(request):
    """
    Revoke a user invitation.
    """
    site = get_current_site(request)

    revocation_form = RevokeInvitationForm(request.POST)

    if revocation_form.is_valid():

        user_id = revocation_form.cleaned_data['user_id']
        user = get_object_or_404(User, id=user_id)

        if user.is_invited_pending_activation \
           and user.moderator == request.user:
            messages.success(request, _(
                '{} has been uninvited from {}.'.format(
                    user.get_full_name(), site.name)))

            # Delete the user rather than deactivate it.
            # Removing the email address from the system altogether means
            # that the same email can later be used to create a new account
            # (e.g. if the user applies or is invited by another moderator).
            # Logs related to this user are also removed,
            # resulting in less junk to filter in that view.
            user.delete()
        else:
            raise PermissionDenied

        return redirect('moderation:moderators')

    else:
        return moderation_home(request, revocation_form=revocation_form)
Esempio n. 2
0
def revoke_invitation(request):
    """
    Revoke a user invitation.
    """
    site = get_current_site(request)

    revocation_form = RevokeInvitationForm(request.POST)

    if revocation_form.is_valid():

        user_id = revocation_form.cleaned_data["user_id"]
        user = get_object_or_404(User, id=user_id)

        if user.is_invited_pending_activation and user.moderator == request.user:
            messages.success(request, _("{} has been uninvited from {}.".format(user.get_full_name(), site.name)))

            # Delete the user rather than deactivate it.
            # Removing the email address from the system altogether means
            # that the same email can later be used to create a new account
            # (e.g. if the user applies or is invited by another moderator).
            # Logs related to this user are also removed,
            # resulting in less junk to filter in that view.
            user.delete()
        else:
            raise PermissionDenied

        return redirect("moderation:moderators")

    else:
        return moderation_home(request, revocation_form=revocation_form)
Esempio n. 3
0
    def test_valid_data(self):
        self.invited_user = InvitedPendingFactory(
            email='*****@*****.**', )

        form = RevokeInvitationForm(data={
            'confirm': True,
            'user_id': self.invited_user.id,
        })

        self.assertTrue(form.is_valid())
Esempio n. 4
0
    def test_valid_data(self):
        self.invited_user = InvitedPendingFactory(
            email='*****@*****.**',
        )

        form = RevokeInvitationForm(
            data={
                'confirm': True,
                'user_id': self.invited_user.id,
            }
        )

        self.assertTrue(form.is_valid())