コード例 #1
0
def upload_countersigned_agreement_file(supplier_id, framework_slug):
    agreements_bucket = s3.S3(current_app.config['DM_AGREEMENTS_BUCKET'])
    errors = {}

    if request.files.get('countersigned_agreement'):
        the_file = request.files['countersigned_agreement']
        if not file_is_pdf(the_file):
            errors['countersigned_agreement'] = 'not_pdf'

        if 'countersigned_agreement' not in errors.keys():
            filename = get_agreement_document_path(framework_slug, supplier_id, COUNTERSIGNED_AGREEMENT_FILENAME)
            agreements_bucket.save(filename, the_file)

            data_api_client.create_audit_event(
                audit_type=AuditTypes.upload_countersigned_agreement,
                user=current_user.email_address,
                object_type='suppliers',
                object_id=supplier_id,
                data={'upload_countersigned_agreement': filename})

            flash('countersigned_agreement', 'upload_countersigned_agreement')

    if len(errors) > 0:
        for category, message in errors.items():
            flash(category, message)

    return redirect(url_for(
        '.list_countersigned_agreement_file',
        supplier_id=supplier_id,
        framework_slug=framework_slug)
    )
コード例 #2
0
def upload_countersigned_agreement_file(supplier_code, framework_slug):
    agreements_bucket = s3.S3(current_app.config['DM_AGREEMENTS_BUCKET'])
    errors = {}

    if request.files.get('countersigned_agreement'):
        the_file = request.files['countersigned_agreement']
        if not file_is_pdf(the_file):
            errors['countersigned_agreement'] = 'not_pdf'

        if 'countersigned_agreement' not in errors.keys():
            filename = get_agreement_document_path(
                framework_slug, supplier_code,
                COUNTERSIGNED_AGREEMENT_FILENAME)
            agreements_bucket.save(filename, the_file)

            data_api_client.create_audit_event(
                audit_type=AuditTypes.upload_countersigned_agreement,
                user=current_user.email_address,
                object_type='suppliers',
                object_id=supplier_code,
                data={'upload_countersigned_agreement': filename})

            flash('countersigned_agreement', 'upload_countersigned_agreement')

    if len(errors) > 0:
        for category, message in errors.items():
            flash(category, message)

    return redirect(
        url_for('.list_countersigned_agreement_file',
                supplier_code=supplier_code,
                framework_slug=framework_slug))
コード例 #3
0
def signature_upload(framework_slug):
    framework = get_framework(data_api_client, framework_slug)
    return_supplier_framework_info_if_on_framework_or_abort(
        data_api_client, framework_slug)
    agreements_bucket = s3.S3(current_app.config['DM_AGREEMENTS_BUCKET'])
    signature_page = get_most_recently_uploaded_agreement_file_or_none(
        agreements_bucket, framework_slug)
    upload_error = None

    if request.method == 'POST':
        # No file chosen for upload and file already exists on s3 so can use existing and progress
        if not request.files['signature_page'].filename and signature_page:
            return redirect(
                url_for(".contract_review", framework_slug=framework_slug))

        if not file_is_image(
                request.files['signature_page']) and not file_is_pdf(
                    request.files['signature_page']):
            upload_error = "The file must be a PDF, JPG or PNG"
        elif not file_is_less_than_5mb(request.files['signature_page']):
            upload_error = "The file must be less than 5MB"
        elif file_is_empty(request.files['signature_page']):
            upload_error = "The file must not be empty"

        if not upload_error:
            upload_path = get_agreement_document_path(
                framework_slug, current_user.supplier_code, '{}{}'.format(
                    SIGNED_AGREEMENT_PREFIX,
                    get_extension(request.files['signature_page'].filename)))
            agreements_bucket.save(upload_path,
                                   request.files['signature_page'],
                                   acl='private')

            session['signature_page'] = request.files[
                'signature_page'].filename

            data_api_client.create_audit_event(
                audit_type=AuditTypes.upload_signed_agreement,
                user=current_user.email_address,
                object_type="suppliers",
                object_id=current_user.supplier_code,
                data={
                    "upload_signed_agreement":
                    request.files['signature_page'].filename,
                    "upload_path": upload_path
                })

            return redirect(
                url_for(".contract_review", framework_slug=framework_slug))

    status_code = 400 if upload_error else 200
    return render_template_with_csrf(
        "frameworks/signature_upload.html",
        status_code=status_code,
        framework=framework,
        signature_page=signature_page,
        upload_error=upload_error,
    )
コード例 #4
0
def upload_countersigned_agreement_file(supplier_id, framework_slug):
    supplier_framework = data_api_client.get_supplier_framework_info(
        supplier_id, framework_slug)['frameworkInterest']
    if not supplier_framework['onFramework'] or supplier_framework[
            'agreementStatus'] in (None, 'draft'):
        abort(404)
    agreement_id = supplier_framework['agreementId']
    agreements_bucket = s3.S3(current_app.config['DM_AGREEMENTS_BUCKET'])
    errors = {}

    if request.files.get('countersigned_agreement'):
        the_file = request.files['countersigned_agreement']
        if not file_is_pdf(the_file):
            errors['countersigned_agreement'] = 'not_pdf'
            flash(COUNTERSIGNED_AGREEMENT_NOT_PDF_MESSAGE)

        if 'countersigned_agreement' not in errors.keys():
            supplier_name = supplier_framework.get(
                'declaration', {}).get('nameOfOrganisation')
            if not supplier_name:
                supplier_name = data_api_client.get_supplier(
                    supplier_id)['suppliers']['name']
            if supplier_framework['agreementStatus'] not in [
                    'approved', 'countersigned'
            ]:
                data_api_client.approve_agreement_for_countersignature(
                    agreement_id, current_user.email_address, current_user.id)

            path = generate_timestamped_document_upload_path(
                framework_slug, supplier_id, 'agreements',
                COUNTERPART_FILENAME)
            download_filename = generate_download_filename(
                supplier_id, COUNTERPART_FILENAME, supplier_name)
            agreements_bucket.save(path,
                                   the_file,
                                   acl='bucket-owner-full-control',
                                   move_prefix=None,
                                   download_filename=download_filename)

            data_api_client.update_framework_agreement(
                agreement_id, {"countersignedAgreementPath": path},
                current_user.email_address)

            data_api_client.create_audit_event(
                audit_type=AuditTypes.upload_countersigned_agreement,
                user=current_user.email_address,
                object_type='suppliers',
                object_id=supplier_id,
                data={'upload_countersigned_agreement': path})

            flash(UPLOAD_COUNTERSIGNED_AGREEMENT_MESSAGE)

    return redirect(
        url_for('.list_countersigned_agreement_file',
                supplier_id=supplier_id,
                framework_slug=framework_slug))
コード例 #5
0
def signature_upload(framework_slug):
    framework = get_framework(data_api_client, framework_slug)
    return_supplier_framework_info_if_on_framework_or_abort(data_api_client, framework_slug)
    agreements_bucket = s3.S3(current_app.config['DM_AGREEMENTS_BUCKET'])
    signature_page = get_most_recently_uploaded_agreement_file_or_none(agreements_bucket, framework_slug)
    upload_error = None

    if request.method == 'POST':
        # No file chosen for upload and file already exists on s3 so can use existing and progress
        if not request.files['signature_page'].filename and signature_page:
            return redirect(url_for(".contract_review", framework_slug=framework_slug))

        if not file_is_image(request.files['signature_page']) and not file_is_pdf(request.files['signature_page']):
            upload_error = "The file must be a PDF, JPG or PNG"
        elif not file_is_less_than_5mb(request.files['signature_page']):
            upload_error = "The file must be less than 5MB"
        elif file_is_empty(request.files['signature_page']):
            upload_error = "The file must not be empty"

        if not upload_error:
            upload_path = get_agreement_document_path(
                framework_slug,
                current_user.supplier_code,
                '{}{}'.format(SIGNED_AGREEMENT_PREFIX, get_extension(request.files['signature_page'].filename))
            )
            agreements_bucket.save(
                upload_path,
                request.files['signature_page'],
                acl='private'
            )

            session['signature_page'] = request.files['signature_page'].filename

            data_api_client.create_audit_event(
                audit_type=AuditTypes.upload_signed_agreement,
                user=current_user.email_address,
                object_type="suppliers",
                object_id=current_user.supplier_code,
                data={
                    "upload_signed_agreement": request.files['signature_page'].filename,
                    "upload_path": upload_path
                })

            return redirect(url_for(".contract_review", framework_slug=framework_slug))

    status_code = 400 if upload_error else 200
    return render_template_with_csrf(
        "frameworks/signature_upload.html",
        status_code=status_code,
        framework=framework,
        signature_page=signature_page,
        upload_error=upload_error,
    )
コード例 #6
0
def upload_communication(framework_slug):
    communications_bucket = s3.S3(current_app.config['DM_COMMUNICATIONS_BUCKET'])
    errors = {}

    if request.files.get('communication'):
        the_file = request.files['communication']
        if not (file_is_pdf(the_file) or file_is_csv(the_file)):
            errors['communication'] = 'not_pdf_or_csv'

        if 'communication' not in errors.keys():
            filename = _get_path(framework_slug, 'updates/communications') + '/' + the_file.filename
            communications_bucket.save(filename, the_file)
            flash('communication', 'upload_communication')

    if request.files.get('clarification'):
        the_file = request.files['clarification']
        if not file_is_pdf(the_file):
            errors['clarification'] = 'not_pdf'

        if 'clarification' not in errors.keys():
            filename = _get_path(framework_slug, 'updates/clarifications') + '/' + the_file.filename
            communications_bucket.save(filename, the_file)
            flash('clarification', 'upload_communication')

    if request.files.get('itt_pack'):
        the_file = request.files['itt_pack']
        if not file_is_zip(the_file):
            errors['itt_pack'] = 'not_zip'

        if 'itt_pack' not in errors.keys():
            filename = _get_itt_pack_path(framework_slug)
            communications_bucket.save(filename, the_file)
            flash('itt_pack', 'upload_communication')

    if len(errors) > 0:
        for category, message in errors.items():
            flash(category, message)
    return redirect(url_for('.manage_communications', framework_slug=framework_slug))
コード例 #7
0
def upload_communication(framework_slug):
    communications_bucket = s3.S3(current_app.config['DM_COMMUNICATIONS_BUCKET'])
    errors = {}

    if request.files.get('communication'):
        the_file = request.files['communication']
        if not (file_is_pdf(the_file) or file_is_csv(the_file)):
            errors['communication'] = 'not_pdf_or_csv'

        if 'communication' not in list(errors.keys()):
            filename = _get_path(framework_slug, 'updates/communications') + '/' + the_file.filename
            communications_bucket.save(filename, the_file)
            flash('communication', 'upload_communication')

    if request.files.get('clarification'):
        the_file = request.files['clarification']
        if not file_is_pdf(the_file):
            errors['clarification'] = 'not_pdf'

        if 'clarification' not in list(errors.keys()):
            filename = _get_path(framework_slug, 'updates/clarifications') + '/' + the_file.filename
            communications_bucket.save(filename, the_file)
            flash('clarification', 'upload_communication')

    if request.files.get('itt_pack'):
        the_file = request.files['itt_pack']
        if not file_is_zip(the_file):
            errors['itt_pack'] = 'not_zip'

        if 'itt_pack' not in list(errors.keys()):
            filename = _get_itt_pack_path(framework_slug)
            communications_bucket.save(filename, the_file)
            flash('itt_pack', 'upload_communication')

    if len(errors) > 0:
        for category, message in list(errors.items()):
            flash(category, message)
    return redirect(url_for('.manage_communications', framework_slug=framework_slug))
コード例 #8
0
def upload_communication(framework_slug):
    communications_bucket = s3.S3(
        current_app.config['DM_COMMUNICATIONS_BUCKET'],
        endpoint_url=current_app.config.get("DM_S3_ENDPOINT_URL"))
    errors = {}

    if request.files.get('communication'):
        the_file = request.files['communication']
        if not (file_is_open_document_format(the_file)
                or file_is_csv(the_file)):
            errors['communication'] = 'not_open_document_format_or_csv'
            flash(
                'Communication file is not an open document format or a CSV.',
                'error')

        if 'communication' not in errors.keys():
            path = "{}/communications/updates/communications/{}".format(
                framework_slug, the_file.filename)
            communications_bucket.save(path,
                                       the_file,
                                       acl='bucket-owner-full-control',
                                       download_filename=the_file.filename)
            flash('New communication was uploaded.')

    if request.files.get('clarification'):
        the_file = request.files['clarification']
        if not file_is_pdf(the_file):
            errors['clarification'] = 'not_pdf'
            flash('Clarification file is not a PDF.', 'error')

        if 'clarification' not in errors.keys():
            path = "{}/communications/updates/clarifications/{}".format(
                framework_slug, the_file.filename)
            communications_bucket.save(path,
                                       the_file,
                                       acl='bucket-owner-full-control',
                                       download_filename=the_file.filename)
            flash('New clarification was uploaded.')

    return redirect(
        url_for('.manage_communications', framework_slug=framework_slug))
コード例 #9
0
def signature_upload(framework_slug, agreement_id):
    framework = get_framework(data_api_client,
                              framework_slug,
                              allowed_statuses=['standstill', 'live'])
    # if there's no frameworkAgreementVersion key it means we're pre-G-Cloud 8 and shouldn't be using this route
    if not framework.get('frameworkAgreementVersion'):
        abort(404)
    supplier_framework = return_supplier_framework_info_if_on_framework_or_abort(
        data_api_client, framework_slug)
    agreement = data_api_client.get_framework_agreement(
        agreement_id)['agreement']
    check_agreement_is_related_to_supplier_framework_or_abort(
        agreement, supplier_framework)

    agreements_bucket = s3.S3(current_app.config['DM_AGREEMENTS_BUCKET'])
    signature_page = agreements_bucket.get_key(
        agreement.get('signedAgreementPath'))
    upload_error = None

    if request.method == 'POST':
        # No file chosen for upload and file already exists on s3 so can use existing and progress
        if not request.files['signature_page'].filename and signature_page:
            return redirect(
                url_for(".contract_review",
                        framework_slug=framework_slug,
                        agreement_id=agreement_id))

        if not file_is_image(
                request.files['signature_page']) and not file_is_pdf(
                    request.files['signature_page']):
            upload_error = "The file must be a PDF, JPG or PNG"
        elif not file_is_less_than_5mb(request.files['signature_page']):
            upload_error = "The file must be less than 5MB"
        elif file_is_empty(request.files['signature_page']):
            upload_error = "The file must not be empty"

        if not upload_error:
            extension = get_extension(request.files['signature_page'].filename)
            upload_path = generate_timestamped_document_upload_path(
                framework_slug, current_user.supplier_id, 'agreements',
                '{}{}'.format(SIGNED_AGREEMENT_PREFIX, extension))
            agreements_bucket.save(
                upload_path,
                request.files['signature_page'],
                acl='private',
                download_filename='{}-{}-{}{}'.format(
                    sanitise_supplier_name(current_user.supplier_name),
                    current_user.supplier_id, SIGNED_SIGNATURE_PAGE_PREFIX,
                    extension),
                disposition_type=
                'inline'  # Embeddeding PDFs in admin pages requires 'inline' and not 'attachment'
            )

            data_api_client.update_framework_agreement(
                agreement_id, {"signedAgreementPath": upload_path},
                current_user.email_address)

            session['signature_page'] = request.files[
                'signature_page'].filename

            return redirect(
                url_for(".contract_review",
                        framework_slug=framework_slug,
                        agreement_id=agreement_id))

    return render_template(
        "frameworks/signature_upload.html",
        agreement=agreement,
        framework=framework,
        signature_page=signature_page,
        upload_error=upload_error,
    ), 400 if upload_error else 200
コード例 #10
0
 def test_file_is_pdf(self):
     self.assertTrue(file_is_pdf(mock_file('file.pdf', 1)))
     self.assertFalse(file_is_pdf(mock_file('file.doc', 1)))
コード例 #11
0
 def test_file_is_pdf(self):
     assert file_is_pdf(MockFile(open('tests/test_files/test_pdf.pdf', 'rb').read(), 'test_pdf.pdf')) is True
     assert file_is_pdf(MockFile(open('tests/test_files/test_image.jpg', 'rb').read(), 'test_pdf.pdf')) is False
     assert file_is_pdf(MockFile(open('tests/test_files/test_pdf.pdf', 'rb').read(), 'test_image.jpg')) is False
     assert file_is_pdf(MockFile(open('tests/test_files/test_image.jpg', 'rb').read(), 'test_image.jpg')) is False
コード例 #12
0
 def test_file_is_pdf(self):
     self.assertTrue(file_is_pdf(mock_file('file.pdf', 1)))
     self.assertFalse(file_is_pdf(mock_file('file.doc', 1)))
コード例 #13
0
 def test_file_is_pdf(self):
     self.assertTrue(file_is_pdf(MockFile(b"*", 'file.pdf')))
     self.assertFalse(file_is_pdf(MockFile(b"*", 'file.doc')))