Beispiel #1
0
def update_evidence(evidence_id):
    evidence = evidence_service.get_evidence_by_id(evidence_id)
    if not evidence or current_user.supplier_code != evidence.supplier_code:
        not_found("No evidence for id '%s' found" % (evidence_id))

    if evidence.status != 'draft':
        abort('Only draft submissions can be edited')

    data = get_json_from_request()

    publish = False
    if 'publish' in data and data['publish']:
        del data['publish']
        publish = True

    if 'maxDailyRate' in data:
        try:
            data['maxDailyRate'] = int(data['maxDailyRate'])
        except ValueError as e:
            data['maxDailyRate'] = 0

    # Validate the evidence request data
    errors = EvidenceDataValidator(data,
                                   evidence=evidence).validate(publish=publish)
    if len(errors) > 0:
        abort(', '.join(errors))

    if publish:
        evidence.submit()
        if current_app.config['JIRA_FEATURES']:
            create_evidence_assessment_in_jira.delay(evidence_id)
        try:
            send_evidence_assessment_requested_notification(
                evidence.domain_id, current_user.email_address)
        except Exception as e:
            current_app.logger.warn(
                'Failed to send requested assessment email for evidence id: {}, {}'
                .format(evidence_id, e))

    evidence.data = data
    evidence_service.save_evidence(evidence)

    try:
        publish_tasks.evidence.delay(publish_tasks.compress_evidence(evidence),
                                     'updated',
                                     name=current_user.name,
                                     domain=evidence.domain.name,
                                     supplier_code=current_user.supplier_code)

        if publish:
            publish_tasks.evidence.delay(
                publish_tasks.compress_evidence(evidence),
                'submitted',
                name=current_user.name,
                domain=evidence.domain.name,
                supplier_code=current_user.supplier_code)
    except Exception as e:
        pass

    return jsonify(evidence.serialize())
Beispiel #2
0
    def reject_domain(self, failed_criteria, vfm):

        data = {"failed_criteria": {}}
        if failed_criteria:
            data['failed_criteria'] = failed_criteria
        if vfm is not None:
            data['vfm'] = vfm
        # set the evidence as rejected
        self.evidence.reject()
        evidence_service.save_evidence(self.evidence, do_commit=False)

        # create the evidence assessment outcome
        evidence_assessment = evidence_assessment_service.create_assessment(
            evidence_id=self.evidence.id,
            user_id=self.actioned_by,
            status='rejected',
            data=data,
            do_commit=False)

        self.__commit()

        try:
            publish_tasks.evidence.delay(
                publish_tasks.compress_evidence(self.evidence),
                'rejected',
                actioned_by=self.actioned_by,
                evidence_assessment=evidence_assessment.serialize(),
                domain=self.evidence.domain.name,
                supplier_code=self.evidence.supplier.code)
        except Exception as e:
            pass

        return evidence_assessment
Beispiel #3
0
    def approve_domain(self):

        supplier = suppliers.get_supplier_by_code(self.evidence.supplier_code)
        if not supplier:
            raise DomainApprovalException('Invalid suppier code in evidence')

        domain = domain_service.find(id=self.evidence.domain_id).one_or_none()
        if not domain:
            raise DomainApprovalException('Invalid domain id in evidence')

        # insert the supplier_domain as assessed for this supplier and domain
        supplier_domain_service.set_supplier_domain_status(
            supplier.id,
            domain.id,
            'assessed',
            'approved',
            do_commit=False
        )

        # set the evidence as approved
        self.evidence.approve()
        evidence_service.save_evidence(self.evidence, do_commit=False)

        # update the supplier's pricing for the evidence's domain
        supplier_data = supplier.data.copy()
        if 'pricing' not in supplier_data:
            supplier_data['pricing'] = {}
        supplier_data['pricing'][domain.name] = {'maxPrice': str(self.evidence.data['maxDailyRate'])}
        supplier.data.update({'pricing': supplier_data['pricing']})
        suppliers.save_supplier(supplier, do_commit=False)

        # create the evidence assessment outcome
        evidence_assessment = evidence_assessment_service.create_assessment(
            evidence_id=self.evidence.id,
            user_id=self.actioned_by,
            status='approved',
            do_commit=False
        )

        self.__commit()

        try:
            publish_tasks.evidence.delay(
                publish_tasks.compress_evidence(self.evidence),
                'approved',
                actioned_by=self.actioned_by,
                evidence_assessment=evidence_assessment.serialize(),
                domain=domain.name,
                supplier_code=supplier.code
            )
        except Exception as e:
            pass

        return evidence_assessment
Beispiel #4
0
def create_evidence(domain_id, brief_id=None):
    """Create evidence (role=supplier)
    ---
    tags:
        - evidence
    definitions:
        EvidenceCreated:
            type: object
            properties:
                id:
                    type: number
                domain_id:
                    type: number
                supplier_code:
                    type: number
    responses:
        200:
            description: Evidence created successfully.
            schema:
                $ref: '#/definitions/EvidenceCreated'
        400:
            description: Bad request.
        403:
            description: Unauthorised to create evidence.
        500:
            description: Unexpected error.
    """
    domain = domain_service.get_by_name_or_id(domain_id, show_legacy=False)
    if not domain:
        abort('Unknown domain id')

    supplier = suppliers.get_supplier_by_code(current_user.supplier_code)
    if supplier.data.get('recruiter', '') == 'yes':
        abort('Assessment can\'t be started against a recruiter only supplier')

    existing_evidence = evidence_service.get_latest_evidence_for_supplier_and_domain(
        domain_id, current_user.supplier_code)
    if domain.name in supplier.assessed_domains:
        abort('This supplier is already assessed for this domain')

    open_assessment = assessments.get_open_assessments(
        domain_id=domain_id, supplier_code=current_user.supplier_code)
    if open_assessment or (existing_evidence and existing_evidence.status
                           in ['draft', 'submitted']):
        abort(
            'This supplier already has a draft assessment or is awaiting assessment for this domain'
        )

    if brief_id:
        brief = briefs.find(id=brief_id).one_or_none()
        if not brief or brief.status != 'live':
            abort('Brief id does not exist or is not open for responses')

    try:
        data = {}

        if existing_evidence and existing_evidence.status == 'rejected':
            data = existing_evidence.data.copy()
        else:
            # does this supplier already have a max price for this domain set? if so, pre-populate
            current_max_price = suppliers.get_supplier_max_price_for_domain(
                current_user.supplier_code, domain.name)
            if current_max_price:
                data['maxDailyRate'] = int(current_max_price)

        evidence = evidence_service.create_evidence(domain_id,
                                                    current_user.supplier_code,
                                                    current_user.id,
                                                    brief_id=brief_id,
                                                    data=data)

    except Exception as e:
        rollbar.report_exc_info()
        abort(e.message)

    publish_tasks.evidence.delay(publish_tasks.compress_evidence(evidence),
                                 'created',
                                 name=current_user.name,
                                 domain=domain.name,
                                 supplier_code=current_user.supplier_code)

    return jsonify(evidence.serialize())