mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-05 02:42:26 -05:00
Merge branch 'master' into platform-admin
Conflicts: app/__init__.py app/main/views/add_service.py app/main/views/jobs.py app/templates/main_nav.html tests/app/main/views/test_dashboard.py tests/conftest.py
This commit is contained in:
18
app/notify_client/statistics_api_client.py
Normal file
18
app/notify_client/statistics_api_client.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from notifications_python_client.base import BaseAPIClient
|
||||
|
||||
|
||||
class StatisticsApiClient(BaseAPIClient):
|
||||
def __init__(self, base_url=None, client_id=None, secret=None):
|
||||
super(self.__class__, self).__init__(base_url=base_url or 'base_url',
|
||||
client_id=client_id or 'client_id',
|
||||
secret=secret or 'secret')
|
||||
|
||||
def init_app(self, app):
|
||||
self.base_url = app.config['API_HOST_NAME']
|
||||
self.client_id = app.config['ADMIN_CLIENT_USER_NAME']
|
||||
self.secret = app.config['ADMIN_CLIENT_SECRET']
|
||||
|
||||
def get_statistics_for_service(self, service_id):
|
||||
return self.get(
|
||||
url='/service/{}/notifications-statistics'.format(service_id),
|
||||
)
|
||||
@@ -32,14 +32,7 @@ class UserApiClient(BaseAPIClient):
|
||||
return User(user_data['data'], max_failed_login_count=self.max_failed_login_count)
|
||||
|
||||
def get_user_by_email(self, email_address):
|
||||
try:
|
||||
params = {'email': email_address}
|
||||
user_data = self.get('/user/email', params=params)
|
||||
except HTTPError as e:
|
||||
if e.status_code == 404:
|
||||
return None
|
||||
else:
|
||||
raise e
|
||||
user_data = self.get('/user/email', params={'email': email_address})
|
||||
return User(user_data['data'], max_failed_login_count=self.max_failed_login_count)
|
||||
|
||||
def get_users(self):
|
||||
@@ -68,7 +61,12 @@ class UserApiClient(BaseAPIClient):
|
||||
def send_verify_code(self, user_id, code_type, to):
|
||||
data = {'to': to}
|
||||
endpoint = '/user/{0}/{1}-code'.format(user_id, code_type)
|
||||
resp = self.post(endpoint, data=data)
|
||||
self.post(endpoint, data=data)
|
||||
|
||||
def send_verify_email(self, user_id, to):
|
||||
data = {'to': to}
|
||||
endpoint = '/user/{0}/email-verification'.format(user_id)
|
||||
self.post(endpoint, data=data)
|
||||
|
||||
def check_verify_code(self, user_id, code, code_type):
|
||||
data = {'code_type': code_type, 'code': code}
|
||||
@@ -106,3 +104,18 @@ class UserApiClient(BaseAPIClient):
|
||||
endpoint = '/user/reset-password'
|
||||
data = {'email': email_address}
|
||||
self.post(endpoint, data=data)
|
||||
|
||||
def is_email_unique(self, email_address):
|
||||
try:
|
||||
if self.get_user_by_email(email_address):
|
||||
return False
|
||||
return True
|
||||
except HTTPError as ex:
|
||||
if ex.status_code == 404:
|
||||
return True
|
||||
else:
|
||||
raise ex
|
||||
|
||||
def activate_user(self, user):
|
||||
user.state = 'active'
|
||||
return self.update_user(user)
|
||||
|
||||
Reference in New Issue
Block a user