Пример #1
0
def test_client_creates_invite(
    app_,
    mocker,
    fake_uuid,
    sample_invite,
):

    mocker.patch('app.notify_client.current_user')

    mock_post = mocker.patch(
        'app.invite_api_client.post',
        return_value={'data': dict.fromkeys({
            'id', 'service', 'from_user', 'email_address',
            'permissions', 'status', 'created_at', 'auth_type'
        })}
    )

    invite_api_client.create_invite(
        '12345', '67890', '*****@*****.**', {'send_messages'}, 'sms_auth'
    )

    mock_post.assert_called_once_with(
        url='/service/{}/invite'.format('67890'),
        data={
            'auth_type': 'sms_auth',
            'email_address': '*****@*****.**',
            'from_user': '******',
            'service': '67890',
            'created_by': ANY,
            'permissions': 'send_emails,send_letters,send_texts',
            'invite_link_host': 'http://localhost:6012',
        }
    )
Пример #2
0
def invite_user(service_id):

    form = InviteUserForm(invalid_email_address=current_user.email_address)

    if form.validate_on_submit():
        email_address = form.email_address.data
        # view_activity is a default role to be added to all users.
        # All users will have at minimum view_activity to allow users to see notifications,
        # templates, team members but no update privileges
        selected_permissions = [permissions for role, permissions in roles.items() if request.form.get(role) == 'y']
        selected_permissions = list(chain.from_iterable(selected_permissions))
        selected_permissions.append('view_activity')
        selected_permissions.sort()
        permissions = ','.join(selected_permissions)
        invited_user = invite_api_client.create_invite(
            current_user.id,
            service_id,
            email_address,
            permissions
        )

        flash('Invite sent to {}'.format(invited_user.email_address), 'default_with_tick')
        return redirect(url_for('.manage_users', service_id=service_id))

    return render_template(
        'views/invite-user.html',
        form=form
    )
Пример #3
0
def invite_user(service_id):

    form = InviteUserForm(invalid_email_address=current_user.email_address)

    if form.validate_on_submit():
        email_address = form.email_address.data
        # view_activity is a default role to be added to all users.
        # All users will have at minimum view_activity to allow users to see notifications,
        # templates, team members but no update privileges
        selected_permissions = [
            permissions for role, permissions in roles.items()
            if request.form.get(role) == 'y'
        ]
        selected_permissions = list(chain.from_iterable(selected_permissions))
        selected_permissions.append('view_activity')
        selected_permissions.sort()
        permissions = ','.join(selected_permissions)
        invited_user = invite_api_client.create_invite(current_user.id,
                                                       service_id,
                                                       email_address,
                                                       permissions)

        flash('Invite sent to {}'.format(invited_user.email_address),
              'default_with_tick')
        return redirect(url_for('.manage_users', service_id=service_id))

    return render_template('views/invite-user.html', form=form)
def invite_user(service_id):

    form = InviteUserForm(
        invalid_email_address=current_user.email_address,
        all_template_folders=current_service.all_template_folders,
        folder_permissions=[
            f['id'] for f in current_service.all_template_folders
        ])

    service_has_email_auth = current_service.has_permission('email_auth')
    if not service_has_email_auth:
        form.login_authentication.data = 'sms_auth'

    if form.validate_on_submit():
        email_address = form.email_address.data
        invited_user = invite_api_client.create_invite(
            current_user.id,
            service_id,
            email_address,
            form.permissions,
            form.login_authentication.data,
            form.folder_permissions.data,
        )

        flash('Invite sent to {}'.format(invited_user.email_address),
              'default_with_tick')
        return redirect(url_for('.manage_users', service_id=service_id))

    return render_template(
        'views/invite-user.html',
        form=form,
        service_has_email_auth=service_has_email_auth,
        mobile_number=True,
    )
def invite_user(service_id):

    if 'caseworking' in current_service['permissions']:
        form = CaseworkingInviteUserForm
    else:
        form = AdminInviteUserForm

    form = form(invalid_email_address=current_user.email_address)

    service_has_email_auth = 'email_auth' in current_service['permissions']
    if not service_has_email_auth:
        form.login_authentication.data = 'sms_auth'

    if form.validate_on_submit():
        email_address = form.email_address.data
        invited_user = invite_api_client.create_invite(
            current_user.id, service_id, email_address, form.permissions,
            form.login_authentication.data)

        flash('Invite sent to {}'.format(invited_user.email_address),
              'default_with_tick')
        return redirect(url_for('.manage_users', service_id=service_id))

    return render_template('views/invite-user.html',
                           form=form,
                           service_has_email_auth=service_has_email_auth)
def test_client_creates_invite(
    app_,
    mocker,
    fake_uuid,
    sample_invite,
):

    mocker.patch("app.notify_client.current_user")

    mock_post = mocker.patch(
        "app.invite_api_client.post",
        return_value={
            "data":
            dict.fromkeys({
                "id",
                "service",
                "from_user",
                "email_address",
                "permissions",
                "status",
                "created_at",
                "auth_type",
                "folder_permissions",
            })
        },
    )

    invite_api_client.create_invite("12345", "67890", "*****@*****.**",
                                    {"send_messages"}, "sms_auth", [fake_uuid])

    mock_post.assert_called_once_with(
        url="/service/{}/invite".format("67890"),
        data={
            "auth_type": "sms_auth",
            "email_address": "*****@*****.**",
            "from_user": "******",
            "service": "67890",
            "created_by": ANY,
            "permissions": "send_emails,send_letters,send_texts",
            "invite_link_host": "http://localhost:6012",
            "folder_permissions": [fake_uuid],
        },
    )
def invite_user(service_id):

    form = InviteUserForm(invalid_email_address=current_user.email_address)

    service_has_email_auth = 'email_auth' in current_service['permissions']
    if not service_has_email_auth:
        form.login_authentication.data = 'sms_auth'

    if form.validate_on_submit():
        email_address = form.email_address.data
        permissions = ','.join(sorted(get_permissions_from_form(form)))
        invited_user = invite_api_client.create_invite(
            current_user.id, service_id, email_address, permissions,
            form.login_authentication.data)

        flash('Invite sent to {}'.format(invited_user.email_address),
              'default_with_tick')
        return redirect(url_for('.manage_users', service_id=service_id))

    return render_template('views/invite-user.html',
                           form=form,
                           service_has_email_auth=service_has_email_auth)