diff --git a/alice/onboarding/onboarding.py b/alice/onboarding/onboarding.py index 80616e6..e479a61 100644 --- a/alice/onboarding/onboarding.py +++ b/alice/onboarding/onboarding.py @@ -406,7 +406,7 @@ def delete_document( ) -> Result[bool, OnboardingError]: """ - Delete all the information stored extracted from a document + Delete all the stored/extracted information from a document Parameters @@ -437,6 +437,42 @@ def delete_document( ) ) + def void_document( + self, user_id: str, document_id: str, verbose: bool = False + ) -> Result[bool, OnboardingError]: + """ + + Mark a document as invalid. + + + Parameters + ---------- + user_id + User identifier + document_id + Document identifier + verbose + Used for print service response as well as the time elapsed + + + Returns + ------- + A Result where if the operation is successful it returns True. + Otherwise, it returns an OnboardingError. + """ + response = self.onboarding_client.void_document( + user_id=user_id, document_id=document_id, verbose=verbose + ) + + if response.status_code == 200: + return isSuccess + else: + return Failure( + OnboardingError.from_response( + operation="void_document", response=response + ) + ) + def add_document( self, user_id: str, diff --git a/alice/onboarding/onboarding_client.py b/alice/onboarding/onboarding_client.py index 6432440..6024590 100644 --- a/alice/onboarding/onboarding_client.py +++ b/alice/onboarding/onboarding_client.py @@ -19,12 +19,15 @@ def __init__(self, auth: Auth, url: str = DEFAULT_URL): self.url = url def _auth_headers(self, token: str): - auth_headers = {"Authorization": "Bearer {}".format(token), - "Alice-User-Agent": "onboarding-python/{} ({}; {}) python {}" - .format(alice.__version__, - platform.system(), - platform.release(), - platform.python_version())} + auth_headers = { + "Authorization": "Bearer {}".format(token), + "Alice-User-Agent": "onboarding-python/{} ({}; {}) python {}".format( + alice.__version__, + platform.system(), + platform.release(), + platform.python_version(), + ), + } return auth_headers @timeit @@ -53,10 +56,10 @@ def healthcheck(self, verbose: bool = False) -> Response: @timeit def create_user( - self, - user_info: UserInfo = None, - device_info: DeviceInfo = None, - verbose: bool = False, + self, + user_info: UserInfo = None, + device_info: DeviceInfo = None, + verbose: bool = False, ) -> Response: """ @@ -219,15 +222,15 @@ def get_users(self, verbose: bool = False) -> Response: @timeit def get_users_status( - self, - verbose: bool = False, - page: int = 1, - page_size: int = 0, - descending: bool = True, - authorized: bool = False, - sort_by: str = None, - filter_field: str = None, - filter_value: str = None, + self, + verbose: bool = False, + page: int = 1, + page_size: int = 0, + descending: bool = True, + authorized: bool = False, + sort_by: str = None, + filter_field: str = None, + filter_value: str = None, ) -> Response: """ @@ -266,8 +269,8 @@ def get_users_status( if filter_field and filter_value: url_query_params = ( - url_query_params - + f"&filter_field={filter_field}&filter_value={filter_value}" + url_query_params + + f"&filter_field={filter_field}&filter_value={filter_value}" ) if sort_by: url_query_params = url_query_params + f"&sort_by={sort_by}" @@ -282,7 +285,7 @@ def get_users_status( @timeit def add_selfie( - self, user_id: str, media_data: bytes, verbose: bool = False + self, user_id: str, media_data: bytes, verbose: bool = False ) -> Response: """ @@ -321,9 +324,7 @@ def add_selfie( return response @timeit - def delete_selfie( - self, user_id: str, verbose: bool = False - ) -> Response: + def delete_selfie(self, user_id: str, verbose: bool = False) -> Response: """ This call is used to delete the video of the user's face to the onboarding service. @@ -348,11 +349,7 @@ def delete_selfie( headers = self._auth_headers(backend_token) - response = request( - "DELETE", - self.url + "/user/selfie", - headers=headers, - ) + response = request("DELETE", self.url + "/user/selfie", headers=headers) print_response(response=response, verbose=verbose) @@ -388,7 +385,7 @@ def supported_documents(self, user_id: str, verbose: bool = False) -> Response: @timeit def create_document( - self, user_id: str, type: str, issuing_country: str, verbose: bool = False + self, user_id: str, type: str, issuing_country: str, verbose: bool = False ) -> Response: """ @@ -428,11 +425,11 @@ def create_document( @timeit def delete_document( - self, user_id: str, document_id: str, verbose: bool = False + self, user_id: str, document_id: str, verbose: bool = False ) -> Response: """ - Delete all the information stored extracted from a document + Delete all the stored/extracted information from a document Parameters @@ -464,16 +461,53 @@ def delete_document( return response + def void_document( + self, user_id: str, document_id: str, verbose: bool = False + ) -> Response: + """ + + Mark a document as invalid. + + + Parameters + ---------- + user_id + User identifier + document_id + Document identifier + verbose + Used for print service response as well as the time elapsed + + Returns + ------- + A Response object [requests library] + """ + print_intro("void_document", verbose=verbose) + + backend_token = self.auth.create_backend_token(user_id).unwrap() + print_token("backend_token_with_user", backend_token, verbose=verbose) + + headers = self._auth_headers(backend_token) + response = request( + "PATCH", + self.url + "/user/document/{document_id}".format(document_id=document_id), + headers=headers, + ) + + print_response(response=response, verbose=verbose) + + return response + @timeit def add_document( - self, - user_id: str, - document_id: str, - media_data: bytes, - side: str, - manual: bool = False, - fields: dict = None, - verbose: bool = False, + self, + user_id: str, + document_id: str, + media_data: bytes, + side: str, + manual: bool = False, + fields: dict = None, + verbose: bool = False, ) -> Response: """ @@ -527,7 +561,7 @@ def add_document( @timeit def document_properties( - self, user_id: str, document_id: str, verbose: bool = False + self, user_id: str, document_id: str, verbose: bool = False ) -> Response: """ @@ -657,7 +691,7 @@ def deauthorize_user(self, user_id: str, verbose: bool = False) -> Response: @timeit def authenticate_user( - self, user_id: str, media_data: bytes, verbose: bool = False + self, user_id: str, media_data: bytes, verbose: bool = False ) -> Response: """ @@ -729,12 +763,12 @@ def get_authentications_ids(self, user_id: str, verbose: bool = False) -> Respon @timeit def get_authentications( - self, - user_id: str, - page: int = 1, - page_size: int = 0, - descending: bool = True, - verbose: bool = False, + self, + user_id: str, + page: int = 1, + page_size: int = 0, + descending: bool = True, + verbose: bool = False, ) -> Response: """ @@ -781,7 +815,7 @@ def get_authentications( @timeit def get_authentication( - self, user_id: str, authentication_id: str, verbose: bool = False + self, user_id: str, authentication_id: str, verbose: bool = False ) -> Response: """ @@ -822,7 +856,7 @@ def get_authentication( @timeit def retrieve_media( - self, user_id: str, media_id: str, verbose: bool = False + self, user_id: str, media_id: str, verbose: bool = False ) -> Response: """ diff --git a/alice/onboarding/onboarding_errors.py b/alice/onboarding/onboarding_errors.py index 4f70728..d3a1d27 100644 --- a/alice/onboarding/onboarding_errors.py +++ b/alice/onboarding/onboarding_errors.py @@ -9,7 +9,7 @@ class OnboardingError(Error): operation: str code: int - message: Dict[str, str] + message: Dict def __str__(self): return self.__repr__()