Exemplo n.º 1
0
    def delete(identifier, filing_id=None):  # pylint: disable=too-many-branches
        """Delete a filing from the business."""
        if not filing_id:
            return ({
                'message': _('No filing id provided for:') + identifier
            }, HTTPStatus.BAD_REQUEST)

        # check authorization
        if not authorized(identifier, jwt, action=['edit']):
            return jsonify({'message':
                            _('You are not authorized to delete a filing for:') + identifier}),\
                HTTPStatus.UNAUTHORIZED

        if identifier.startswith('T'):
            filing = Filing.get_temp_reg_filing(identifier, filing_id)
        else:
            filing = Business.get_filing_by_id(identifier, filing_id)

        if not filing:
            return jsonify({'message':
                            _('Filing Not Found.')}), HTTPStatus.NOT_FOUND

        if filing.deletion_locked:  # should not be deleted
            return ListFilingResource._create_deletion_locked_response(
                identifier, filing)

        try:
            ListFilingResource._delete_from_minio(filing)
            filing.delete()
        except BusinessException as err:
            return jsonify({'errors': [
                {
                    'error': err.error
                },
            ]}), err.status_code

        if identifier.startswith('T'):
            bootstrap = RegistrationBootstrap.find_by_identifier(identifier)
            if bootstrap:
                deregister_status = RegistrationBootstrapService.deregister_bootstrap(
                    bootstrap)
                delete_status = RegistrationBootstrapService.delete_bootstrap(
                    bootstrap)
                if deregister_status != HTTPStatus.OK or delete_status != HTTPStatus.OK:
                    current_app.logger.error(
                        'Unable to deregister and delete temp reg:',
                        identifier)

        return jsonify({'message': _('Filing deleted.')}), HTTPStatus.OK
Exemplo n.º 2
0
def bootstrap(account):
    """Create a IA filing for processing."""
    from legal_api.services.bootstrap import AccountService

    bootstrap = RegistrationBootstrapService.create_bootstrap(account=account)
    RegistrationBootstrapService.register_bootstrap(bootstrap,
                                                    bootstrap.identifier)
    identifier = bootstrap.identifier

    yield identifier

    try:
        rv = AccountService.delete_affiliation(account, identifier)
        print(rv)
    except Exception as err:
        print(err)
Exemplo n.º 3
0
    def post():
        """Create an Incorporation Filing, else error out."""
        json_input = request.get_json()

        try:
            filing_account_id = json_input['filing']['header']['accountId']
            filing_type = json_input['filing']['header']['name']
            if filing_type != Filing.FILINGS['incorporationApplication'][
                    'name']:
                raise TypeError
        except (TypeError, KeyError):
            return {
                'error': babel('Requires a minimal Incorporation Filing.')
            }, HTTPStatus.BAD_REQUEST

        # @TODO rollback bootstrap if there is A failure, awaiting changes in the affiliation service
        bootstrap = RegistrationBootstrapService.create_bootstrap(
            filing_account_id)
        if not isinstance(bootstrap, RegistrationBootstrap):
            return {
                'error': babel('Unable to create Incorporation Filing.')
            }, HTTPStatus.SERVICE_UNAVAILABLE

        try:
            business_name = json_input['filing']['incorporationApplication'][
                'nameRequest']['nrNumber']
        except KeyError:
            business_name = bootstrap.identifier
        rv = RegistrationBootstrapService.register_bootstrap(
            bootstrap, business_name)
        if not isinstance(rv, HTTPStatus):
            with suppress(Exception):
                bootstrap.delete()
            return {
                'error': babel('Unable to create Incorporation Filing.')
            }, HTTPStatus.SERVICE_UNAVAILABLE

        return ListFilingResource.put(bootstrap.identifier, None)
Exemplo n.º 4
0
def test_create_bootstrap_registrations(session):
    """Assert the service creates registrations."""
    r = RegistrationBootstrapService.create_bootstrap(account=28)
    assert r.identifier