Exemplo n.º 1
0
def do_search_deed_search():
    deed_data = lookup_deed(session['deed_token'])
    if deed_data is not None:
        if 'effective_date' in deed_data["deed"]:
            temp = datetime.datetime.strptime(deed_data["deed"]["effective_date"], "%Y-%m-%d %H:%M:%S")
            deed_data["deed"]["effective_date"] = temp.strftime("%d/%m/%Y at %H:%M:%S")

        # Akuma Check
        res = Akuma.do_check(deed_data, "borrower view", session['borrower_token'], session['deed_token'])

        if res["result"] == "Z":
            conveyancer = get_conveyancer_for_deed(session['deed_token'])
            session.clear()
            return render_template('unabletoproceed.html', conveyancer=conveyancer)

        deed_data["deed"]["property_address"] = format_address_string(deed_data["deed"]["property_address"])

        session['no_of_borrowers'] = no_of_borrowers(deed_data)

        if deed_signed():
            response = render_template('viewdeed.html', deed_data=deed_data, signed=True,
                                       conveyancer=get_conveyancer_for_deed(session['deed_token']))
        else:
            response = render_template('viewdeed.html', deed_data=deed_data, signed=False,
                                       conveyancer=get_conveyancer_for_deed(session['deed_token']))
    else:
        return render_template('searchdeed.html', error=True)

    return response
Exemplo n.º 2
0
    def test_akuma_check(self, mock_api):
        mock_api.return_value = {
            "result": "A",
            "id": "2b9115b2-d956-11e5-942f-08002719cd16"
        }

        check_result = Akuma.do_check(DeedHelper._json_doc, "Create")

        self.assertEqual(check_result["result"], "A")
Exemplo n.º 3
0
    def test_akuma_check(self, mock_api):
        mock_api.return_value = {
            "result": "A",
            "id": "2b9115b2-d956-11e5-942f-08002719cd16"
        }

        check_result = Akuma.do_check(DeedHelper._json_doc, "Create")

        self.assertEqual(check_result["result"], "A")
Exemplo n.º 4
0
    def call_akuma(self, deed_json, deed_token, organisation_name,
                   organisation_locale, deed_type):
        check_result = Akuma.do_check(deed_json, deed_type, organisation_name,
                                      organisation_locale, deed_token)
        if deed_type == "create deed":
            application.app.logger.info("Check ID: " + check_result['id'])
        elif deed_type == "modify deed":
            application.app.logger.info("Check ID - MODIFY: " +
                                        check_result['id'])

        return check_result
Exemplo n.º 5
0
def make_effective(deed_reference):
    credentials = Validation().validate_organisation_credentials()
    if credentials is None:
        return '', status.HTTP_401_UNAUTHORIZED

    deed = Deed()
    result = deed.get_deed(deed_reference)
    if result is None:
        application.app.logger.error("Deed with reference - %s not found" %
                                     str(deed_reference))
        abort(status.HTTP_404_NOT_FOUND)
    else:

        deed_status = str(result.status)

        if deed_status == "ALL-SIGNED":
            check_result = Akuma.do_check(result.deed, "make effective",
                                          credentials['organisation_name'],
                                          credentials['organisation_locale'],
                                          result.token)
            application.app.logger.info("Check ID - Make Effective: " +
                                        check_result['id'])

            signed_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')

            make_deed_effective_date(result, signed_time)

            apply_registrar_signature(result, signed_time)

            return jsonify({"path":
                            '/deed/' + str(result.token)}), status.HTTP_200_OK

        elif deed_status == "EFFECTIVE" or deed_status == "NOT-LR-SIGNED":
            errors = []
            application.app.logger.error(
                "Deed with reference - %s is in %s status and can not be registrar signed"
                % (str(deed_reference), str(deed_status)))
            errors.append("This deed has already been made effective.")
            compiled_list = send_error_list(errors)
            return compiled_list

        else:
            errors = []
            application.app.logger.error(
                "Deed with reference - %s is not fully signed and can not be registrar signed"
                % str(deed_reference))
            errors.append(
                "This deed cannot be made effective as not all borrowers have signed the deed."
            )
            compiled_list = send_error_list(errors)
            return compiled_list
Exemplo n.º 6
0
def create():
    deed_json = request.get_json()
    error_count, error_message = validate_helper(deed_json)

    if error_count > 0:
        LOGGER.error("Schema validation 400_BAD_REQUEST")
        return error_message, status.HTTP_400_BAD_REQUEST
    else:

        try:
            deed = Deed()
            deed.token = Deed.generate_token()
            check_result = Akuma.do_check(deed_json, "create deed")
            LOGGER.info("Check ID: " + check_result['id'])

            organisation_credentials = process_organisation_credentials()

            if organisation_credentials:
                deed.organisation_id = organisation_credentials["O"][1]
                deed.organisation_name = organisation_credentials["O"][0]
                success, msg = update_deed(deed, deed_json,
                                           check_result['result'])

                if not success:
                    LOGGER.error("Update deed 400_BAD_REQUEST")
                    return msg, status.HTTP_400_BAD_REQUEST
            else:
                LOGGER.error("Unable to process headers")
                return "Unable to process headers", status.HTTP_401_UNAUTHORIZED

            if check_result['result'] != "A":
                LOGGER.error("Akuma endpoint 503_SERVICE_UNAVAILABLE")
                return abort(status.HTTP_503_SERVICE_UNAVAILABLE)

            return jsonify({"path": '/deed/' + str(deed.token)
                            }), status.HTTP_201_CREATED

        except:
            msg = str(sys.exc_info())
            LOGGER.error("Database Exception - %s" % msg)
            abort(status.HTTP_500_INTERNAL_SERVER_ERROR)
Exemplo n.º 7
0
def create():
    deed_json = request.get_json()
    error_count, error_message = validate_helper(deed_json)

    if error_count > 0:
        LOGGER.error("Schema validation 400_BAD_REQUEST")
        return error_message, status.HTTP_400_BAD_REQUEST
    else:

        try:
            deed = Deed()
            deed.token = Deed.generate_token()
            check_result = Akuma.do_check(deed_json, "create deed")
            LOGGER.info("Check ID: " + check_result['id'])

            organisation_credentials = process_organisation_credentials()

            if organisation_credentials:
                deed.organisation_id = organisation_credentials["O"][1]
                deed.organisation_name = organisation_credentials["O"][0]
                success, msg = update_deed(deed, deed_json, check_result['result'])

                if not success:
                    LOGGER.error("Update deed 400_BAD_REQUEST")
                    return msg, status.HTTP_400_BAD_REQUEST
            else:
                LOGGER.error("Unable to process headers")
                return "Unable to process headers", status.HTTP_401_UNAUTHORIZED

            if check_result['result'] != "A":
                LOGGER.error("Akuma endpoint 503_SERVICE_UNAVAILABLE")
                return abort(status.HTTP_503_SERVICE_UNAVAILABLE)

            return jsonify({"path": '/deed/' + str(deed.token)}), status.HTTP_201_CREATED

        except:
            msg = str(sys.exc_info())
            LOGGER.error("Database Exception - %s" % msg)
            abort(status.HTTP_500_INTERNAL_SERVER_ERROR)
Exemplo n.º 8
0
def auth_sms(deed_reference, borrower_token, borrower_code):
    deed_instance = Deed()
    deed = deed_instance.get_deed(deed_reference)

    if deed is None:
        application.app.logger.error(
            "Database Exception 404 for deed reference - %s" % deed_reference)
        abort(status.HTTP_404_NOT_FOUND)
    else:
        application.app.logger.info(
            "Signing deed for borrower_token %s against deed reference %s" %
            (borrower_token, deed_reference))

        signing_deed_akuma = Akuma.do_check(deed.deed, "borrower sign",
                                            deed.organisation_name, "",
                                            deed.token)
        application.app.logger.info("Check ID - Borrower SIGNING: " +
                                    signing_deed_akuma['id'])

        if signing_deed_akuma["result"] == "Z":
            application.app.logger.error("Failed to sign Mortgage document")
            return "Failed to sign Mortgage document"

        # check if XML already exist
        if deed.deed_xml is None:
            application.app.logger.info("Generating DEED_XML")
            deed_XML = convert_json_to_xml(deed.deed)
            deed.deed_xml = deed_XML.encode("utf-8")

        try:
            application.app.logger.info("getting existing XML")
            borrower_pos = deed.get_borrower_position(borrower_token)
            borrower = Borrower.get_by_token(borrower_token)
            esec_id = borrower.esec_user_name

            if esec_id:
                esec_client = make_esec_client()
                response, status_code = esec_client.auth_sms(
                    deed, borrower_pos, esec_id, borrower_code, borrower_token)
                application.app.logger.info("auth_sms status code: %s",
                                            str(status_code))

                if status_code == 200:
                    return jsonify({"deed": deed.deed}), status.HTTP_200_OK

                else:
                    application.app.logger.error(
                        "Failed to authenticate sms code")
                    return jsonify({
                        "status": "Failed to authenticate sms code"
                    }), status.HTTP_401_UNAUTHORIZED

            else:
                application.app.logger.error(
                    "Failed to sign Mortgage document - unable to create user")
                abort(status.HTTP_500_INTERNAL_SERVER_ERROR)

        except:
            msg = str(sys.exc_info())
            application.app.logger.error(
                "Failed to sign Mortgage document: %s" % msg)
            abort(status.HTTP_500_INTERNAL_SERVER_ERROR)

        return jsonify({"deed": deed.deed}), status.HTTP_200_OK