Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update monitoring related eps to match new-onboarding eps #95

Merged
merged 3 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions alice/onboarding/onboarding.py
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,39 @@ def screening_monitor_delete(
)
)

@early_return
def get_monitoring_alerts(
self, user_id: str, verbose: bool = False
) -> Result[bool, Union[OnboardingError, AuthError]]:
"""
Retrieves from the monitoring list the users with open alerts

Parameters
----------
user_id
User identifier
verbose
Used for print service response as well as the time elapsed

Returns
-------
A Result where if the operation is successful it returns a dictionary.
Otherwise, it returns an OnboardingError or AuthError.
"""
verbose = self.verbose or verbose
response = self.onboarding_client.get_monitoring_alerts(
user_id=user_id, verbose=verbose
).unwrap_or_return()

if response.status_code == 200:
return Success(response.json())
else:
return Failure(
OnboardingError.from_response(
operation="get_monitoring_alerts", response=response
)
)

@early_return
def identify_user(
self,
Expand Down
42 changes: 41 additions & 1 deletion alice/onboarding/onboarding_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,7 @@ def screening_monitor_add(
headers = self._auth_headers(backend_user_token)

try:
response = self.session.get(
response = self.session.post(
f"{self.url}/user/screening/monitor",
headers=headers,
timeout=self.timeout,
Expand Down Expand Up @@ -1327,6 +1327,46 @@ def screening_monitor_delete(

return Success(response)

@early_return
@timeit
def get_monitoring_alerts(
self, user_id: str, verbose: bool = False
) -> Result[Response, Error]:
"""
Retrieves from the monitoring list the users with open alerts

Parameters
----------
user_id
User identifier
verbose
Used for print service response as well as the time elapsed


Returns
-------
A Result object with Response object [requests library] if Success
"""
print_intro("get_monitoring_alerts", verbose=verbose)

backend_token = self.auth.create_backend_token(
user_id=user_id
).unwrap_or_return()
print_token("backend_token_with_user", backend_token, verbose=verbose)
headers = self._auth_headers(backend_token)

try:
response = self.session.get(
f"{self.url}/user/screening/monitor",
headers=headers,
timeout=self.timeout,
)
except requests.exceptions.Timeout:
return Failure(OnboardingError.timeout(operation="get_monitoring_alerts"))
print_response(response=response, verbose=verbose)

return Success(response)

@early_return
@timeit
def identify_user(
Expand Down
13 changes: 8 additions & 5 deletions examples/onboarding_with_screening.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,14 @@ def screening_onboarding(api_key: str, verbose: Optional[bool] = False) -> None:
assert isinstance(detailed_screening, dict)

# Add user to monitoring list
# onboarding.screening_monitor_add(user_id=user_id).unwrap_or_raise()
#
# onboarding.screening_monitor_delete(
# user_id=user_id, verbose=verbose
# ).unwrap_or_raise()
onboarding.screening_monitor_add(user_id=user_id).unwrap_or_raise()

open_alerts = onboarding.get_monitoring_alerts(user_id=user_id).unwrap_or_raise()
assert isinstance(open_alerts, dict)

onboarding.screening_monitor_delete(
user_id=user_id, verbose=verbose
).unwrap_or_raise()


def given_any_document_front_media_data() -> bytes:
Expand Down