Пример #1
0
    def test_anonymous_user_can_not_approve_pending_invitation(self):
        self.project_invitation.state = models.Invitation.State.PENDING
        self.project_invitation.save()
        response = self.client.post(
            factories.InvitationBaseFactory.get_list_url('approve'), {
                'token': get_invitation_token(self.project_invitation,
                                              self.staff)
            })

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Пример #2
0
    def test_anonymous_user_can_not_reject_rejected_invitation(self):
        self.project_invitation.state = models.Invitation.State.REJECTED
        self.project_invitation.save()

        response = self.client.post(
            factories.InvitationBaseFactory.get_list_url('reject'),
            {
                'token': get_invitation_token(self.project_invitation,
                                              self.staff)
            },
        )

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Пример #3
0
    def test_anonymous_user_can_reject_requested_invitation(self):
        self.project_invitation.state = models.Invitation.State.REQUESTED
        self.project_invitation.save()

        response = self.client.post(
            factories.InvitationBaseFactory.get_list_url('reject'), {
                'token': get_invitation_token(self.project_invitation,
                                              self.staff)
            })

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.project_invitation.refresh_from_db()
        self.assertEqual(self.project_invitation.state,
                         models.Invitation.State.REJECTED)
Пример #4
0
def send_invitation_requested(invitation_uuid, sender):
    """
    Invitation request is sent to staff users so that they can approve or reject invitation.
    """
    invitation = models.Invitation.objects.get(uuid=invitation_uuid)
    base_context = utils.get_invitation_context(invitation, sender)

    staff_users = core_models.User.objects.filter(
        is_staff=True, is_active=True
    ).exclude(email='')
    for user in staff_users:
        token = utils.get_invitation_token(invitation, user)
        approve_link = format_homeport_link('invitation_approve/{token}/', token=token)
        reject_link = format_homeport_link('invitation_reject/{token}/', token=token)
        context = dict(
            approve_link=approve_link, reject_link=reject_link, **base_context
        )
        broadcast_mail('users', 'invitation_requested', context, [user.email])
Пример #5
0
def send_invitation_requested(invitation_uuid, sender):
    """
    Invitation request is sent to staff users so that they can approve or reject invitation.
    """
    invitation = models.Invitation.objects.get(uuid=invitation_uuid)
    base_context = utils.get_invitation_context(invitation, sender)

    staff_users = core_models.User.objects.filter(
        is_staff=True, is_active=True).exclude(email='')
    for user in staff_users:
        token = utils.get_invitation_token(invitation, user)
        approve_link = settings.WALDUR_CORE['INVITATION_APPROVE_URL'].format(
            token=token)
        reject_link = settings.WALDUR_CORE['INVITATION_REJECT_URL'].format(
            token=token)
        context = dict(approve_link=approve_link,
                       reject_link=reject_link,
                       **base_context)
        broadcast_mail('users', 'invitation_requested', context, [user.email])