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)
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)
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())
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())
def moderation_home(request, invitation_form=None, reinvitation_form=None, revocation_form=None): """ Show forms that allow a moderator to: - Issue a membership invitation - Resend a membership invitation - Revoke a membership invitation """ # Show pending invitations pending = User.objects.filter(moderator=request.user, registration_method=User.INVITED, auth_token_is_used=False, is_active=False) if not invitation_form: invitation_form = InviteMemberForm() if not reinvitation_form: reinvitation_form = ReInviteMemberForm(moderator=request.user) if not revocation_form: revocation_form = RevokeInvitationForm() context = { 'invitation_form': invitation_form, 'reinvitation_form': reinvitation_form, 'revocation_form': revocation_form, 'pending': pending, } return render(request, 'moderation/invite_member.html', context)