Example #1
0
def send_invitation(request: HttpRequest, project_name: str, user: User):
    """Send invitation to user to join project."""
    fake = HttpRequest()
    fake.user = get_anonymous()
    fake.method = "POST"
    fake.session = create_session()
    fake.session["invitation_context"] = {
        "from_user": request.user.full_name,
        "project_name": project_name,
    }
    fake.POST["email"] = user.email
    fake.META = request.META
    store_userid(fake, invite=True)

    # Make sure the email backend is there for the invitation
    email_auth = "social_core.backends.email.EmailAuth"
    has_email = email_auth in settings.AUTHENTICATION_BACKENDS
    backup_backends = settings.AUTHENTICATION_BACKENDS
    backup_cache = social_core.backends.utils.BACKENDSCACHE
    backup_social = social_django.utils.BACKENDS
    if not has_email:
        social_core.backends.utils.BACKENDSCACHE["email"] = EmailAuth
        settings.AUTHENTICATION_BACKENDS += (email_auth,)

    # Send invitation
    complete(fake, "email")

    # Revert temporary settings override
    if not has_email:
        social_core.backends.utils.BACKENDSCACHE = backup_cache
        settings.AUTHENTICATION_BACKENDS = backup_backends
        social_django.utils.BACKENDS = backup_social
Example #2
0
def send_invitation(request, project, user):
    fake = HttpRequest()
    fake.user = get_anonymous()
    fake.method = 'POST'
    fake.session = create_session()
    fake.session['invitation_context'] = {
        'from_user': request.user.full_name,
        'project_name': project.name,
    }
    fake.POST['email'] = user.email
    fake.META = request.META
    store_userid(fake, invite=True)
    complete(fake, 'email')
Example #3
0
def send_invitation(request, project, user):
    fake = HttpRequest()
    fake.user = get_anonymous()
    fake.method = "POST"
    fake.session = create_session()
    fake.session["invitation_context"] = {
        "from_user": request.user.full_name,
        "project_name": project.name,
    }
    fake.POST["email"] = user.email
    fake.META = request.META
    store_userid(fake, invite=True)
    complete(fake, "email")
Example #4
0
def invite_user(request, project):
    """Invite user to a project."""
    obj, form = check_user_form(request,
                                project,
                                True,
                                form_class=InviteUserForm)

    if form is not None:
        try:
            user = form.save()
            obj.add_user(user)
            Change.objects.create(
                project=obj,
                action=Change.ACTION_INVITE_USER,
                user=request.user,
                details={'username': user.username},
            )
            fake = HttpRequest()
            fake.user = get_anonymous()
            fake.method = 'POST'
            fake.session = create_session()
            fake.session['invitation_context'] = {
                'from_user': request.user.full_name,
                'project_name': obj.name,
            }
            fake.POST['email'] = form.cleaned_data['email']
            fake.META = request.META
            store_userid(fake, invite=True)
            complete(fake, 'email')
            messages.success(request,
                             _('User has been invited to this project.'))
        except Group.DoesNotExist:
            messages.error(request, _('Failed to find group to add a user!'))

    return redirect(
        'manage-access',
        project=obj.slug,
    )