def _basic_checks(identifier, filing_id, client_request) -> Tuple[dict, int]: """Perform basic checks to ensure put can do something.""" json_input = client_request.get_json() if client_request.method == 'POST' and not json_input: return ({ 'message': f'No filing json data in body of post for {identifier}.' }, HTTPStatus.BAD_REQUEST) if client_request.method == 'GET' and identifier.startswith('T'): filing_model = Filing.get_temp_reg_filing(identifier) business = Business.find_by_internal_id(filing_model.business_id) else: business = Business.find_by_identifier(identifier) filing = Filing.find_by_id(filing_id) if not business: return ({'message': f'{identifier} not found'}, HTTPStatus.NOT_FOUND) # check that filing belongs to this business if not filing or filing.business_id != business.id: return ({ 'message': f'Filing {filing_id} not found' }, HTTPStatus.NOT_FOUND) return (None, None)
def get_comments(identifier, comment_id=None): """Return a JSON object with meta information about the Service.""" # basic checks if identifier.startswith('T'): filing_model = FilingModel.get_temp_reg_filing(identifier) business = Business.find_by_internal_id(filing_model.business_id) else: business = Business.find_by_identifier(identifier) err_msg, err_code = _basic_checks(identifier, business, request) if err_msg: return jsonify(err_msg), err_code comments = db.session.query(Comment).filter( Comment.business_id == business.id, Comment.filing_id.is_(None)) if comment_id: comment = comments.filter(Comment.id == comment_id).one_or_none() if not comment: return jsonify({'message': f'Comment {comment_id} not found' }), HTTPStatus.NOT_FOUND return jsonify(comment.json) rv = [] for comment in comments: rv.append(comment.json) return jsonify(comments=rv)
def get_documents(identifier: str, filing_id: int, legal_filing_name: str = None): """Return a JSON object with meta information about the Service.""" # basic checks if not authorized(identifier, jwt, [ 'view', ]): return jsonify(message=get_error_message(ErrorCode.NOT_AUTHORIZED, **{ 'identifier': identifier })), HTTPStatus.UNAUTHORIZED if identifier.startswith('T'): filing_model = FilingModel.get_temp_reg_filing(identifier) business = Business.find_by_internal_id(filing_model.business_id) else: business = Business.find_by_identifier(identifier) if not business and not identifier.startswith('T'): return jsonify(message=get_error_message(ErrorCode.MISSING_BUSINESS, ** {'identifier': identifier })), HTTPStatus.NOT_FOUND if not (filing := Filing.get(identifier, filing_id)): return jsonify(message=get_error_message( ErrorCode.FILING_NOT_FOUND, **{ 'filing_id': filing_id, 'identifier': identifier })), HTTPStatus.NOT_FOUND
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