mirror of
https://github.com/GSA/notifications-admin.git
synced 2025-12-15 09:34:25 -05:00
Add created_by to all appropriate requests.
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
from flask.ext.login import current_user
|
||||||
|
|
||||||
|
|
||||||
|
def _attach_current_user(data):
|
||||||
|
data['created_by'] = current_user.id
|
||||||
|
return data
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ from __future__ import unicode_literals
|
|||||||
from flask import url_for
|
from flask import url_for
|
||||||
from notifications_python_client.notifications import NotificationsAPIClient
|
from notifications_python_client.notifications import NotificationsAPIClient
|
||||||
from app.utils import BrowsableItem
|
from app.utils import BrowsableItem
|
||||||
|
from app.notify_client import _attach_current_user
|
||||||
|
|
||||||
|
|
||||||
class ServiceAPIClient(NotificationsAPIClient):
|
class ServiceAPIClient(NotificationsAPIClient):
|
||||||
@@ -30,6 +31,7 @@ class ServiceAPIClient(NotificationsAPIClient):
|
|||||||
"restricted": restricted,
|
"restricted": restricted,
|
||||||
"email_from": email_from
|
"email_from": email_from
|
||||||
}
|
}
|
||||||
|
_attach_current_user(data)
|
||||||
return self.post("/service", data)['data']['id']
|
return self.post("/service", data)['data']['id']
|
||||||
|
|
||||||
def delete_service(self, service_id):
|
def delete_service(self, service_id):
|
||||||
@@ -37,7 +39,8 @@ class ServiceAPIClient(NotificationsAPIClient):
|
|||||||
Delete a service.
|
Delete a service.
|
||||||
"""
|
"""
|
||||||
endpoint = "/service/{0}".format(service_id)
|
endpoint = "/service/{0}".format(service_id)
|
||||||
return self.delete(endpoint)
|
data = _attach_current_user({})
|
||||||
|
return self.delete(endpoint, data)
|
||||||
|
|
||||||
def get_service(self, service_id, *params):
|
def get_service(self, service_id, *params):
|
||||||
"""
|
"""
|
||||||
@@ -72,6 +75,7 @@ class ServiceAPIClient(NotificationsAPIClient):
|
|||||||
"users": users,
|
"users": users,
|
||||||
"email_from": email_from
|
"email_from": email_from
|
||||||
}
|
}
|
||||||
|
_attach_current_user(data)
|
||||||
endpoint = "/service/{0}".format(service_id)
|
endpoint = "/service/{0}".format(service_id)
|
||||||
return self.post(endpoint, data)
|
return self.post(endpoint, data)
|
||||||
|
|
||||||
@@ -82,7 +86,8 @@ class ServiceAPIClient(NotificationsAPIClient):
|
|||||||
endpoint = '/service/{service_id}/users/{user_id}'.format(
|
endpoint = '/service/{service_id}/users/{user_id}'.format(
|
||||||
service_id=service_id,
|
service_id=service_id,
|
||||||
user_id=user_id)
|
user_id=user_id)
|
||||||
return self.delete(endpoint)
|
data = _attach_current_user({})
|
||||||
|
return self.delete(endpoint, data)
|
||||||
|
|
||||||
def create_service_template(self, name, type_, content, service_id, subject=None):
|
def create_service_template(self, name, type_, content, service_id, subject=None):
|
||||||
"""
|
"""
|
||||||
@@ -98,6 +103,7 @@ class ServiceAPIClient(NotificationsAPIClient):
|
|||||||
data.update({
|
data.update({
|
||||||
'subject': subject
|
'subject': subject
|
||||||
})
|
})
|
||||||
|
_attach_current_user(data)
|
||||||
endpoint = "/service/{0}/template".format(service_id)
|
endpoint = "/service/{0}/template".format(service_id)
|
||||||
return self.post(endpoint, data)
|
return self.post(endpoint, data)
|
||||||
|
|
||||||
@@ -116,6 +122,7 @@ class ServiceAPIClient(NotificationsAPIClient):
|
|||||||
data.update({
|
data.update({
|
||||||
'subject': subject
|
'subject': subject
|
||||||
})
|
})
|
||||||
|
_attach_current_user(data)
|
||||||
endpoint = "/service/{0}/template/{1}".format(service_id, id_)
|
endpoint = "/service/{0}/template/{1}".format(service_id, id_)
|
||||||
return self.post(endpoint, data)
|
return self.post(endpoint, data)
|
||||||
|
|
||||||
@@ -141,6 +148,7 @@ class ServiceAPIClient(NotificationsAPIClient):
|
|||||||
Delete a service template.
|
Delete a service template.
|
||||||
"""
|
"""
|
||||||
endpoint = "/service/{0}/template/{1}".format(service_id, template_id)
|
endpoint = "/service/{0}/template/{1}".format(service_id, template_id)
|
||||||
|
data = _attach_current_user({})
|
||||||
return self.delete(endpoint)
|
return self.delete(endpoint)
|
||||||
|
|
||||||
def find_all_service_email_from(self, user_id=None):
|
def find_all_service_email_from(self, user_id=None):
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from notifications_python_client.base import BaseAPIClient
|
from notifications_python_client.base import BaseAPIClient
|
||||||
|
from app.notify_client import _attach_current_user
|
||||||
|
|
||||||
|
|
||||||
class ApiKeyApiClient(BaseAPIClient):
|
class ApiKeyApiClient(BaseAPIClient):
|
||||||
@@ -20,8 +21,12 @@ class ApiKeyApiClient(BaseAPIClient):
|
|||||||
|
|
||||||
def create_api_key(self, service_id, key_name, *params):
|
def create_api_key(self, service_id, key_name, *params):
|
||||||
data = {"name": key_name}
|
data = {"name": key_name}
|
||||||
|
_attach_current_user(data)
|
||||||
key = self.post(url='/service/{}/api-key'.format(service_id), data=data)
|
key = self.post(url='/service/{}/api-key'.format(service_id), data=data)
|
||||||
return key['data']
|
return key['data']
|
||||||
|
|
||||||
def revoke_api_key(self, service_id, key_id, *params):
|
def revoke_api_key(self, service_id, key_id, *params):
|
||||||
return self.post(url='/service/{0}/api-key/revoke/{1}'.format(service_id, key_id), data=None)
|
data = _attach_current_user({})
|
||||||
|
return self.post(
|
||||||
|
url='/service/{0}/api-key/revoke/{1}'.format(service_id, key_id),
|
||||||
|
data=data)
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ class InviteApiClient(BaseAPIClient):
|
|||||||
'from_user': invite_from_id,
|
'from_user': invite_from_id,
|
||||||
'permissions': permissions
|
'permissions': permissions
|
||||||
}
|
}
|
||||||
|
_attach_current_user(data)
|
||||||
resp = self.post(url='/service/{}/invite'.format(service_id), data=data)
|
resp = self.post(url='/service/{}/invite'.format(service_id), data=data)
|
||||||
return InvitedUser(**resp['data'])
|
return InvitedUser(**resp['data'])
|
||||||
|
|
||||||
@@ -37,6 +38,7 @@ class InviteApiClient(BaseAPIClient):
|
|||||||
|
|
||||||
def cancel_invited_user(self, service_id, invited_user_id):
|
def cancel_invited_user(self, service_id, invited_user_id):
|
||||||
data = {'status': 'cancelled'}
|
data = {'status': 'cancelled'}
|
||||||
|
_attach_current_user(data)
|
||||||
self.post(url='/service/{0}/invite/{1}'.format(service_id, invited_user_id),
|
self.post(url='/service/{0}/invite/{1}'.format(service_id, invited_user_id),
|
||||||
data=data)
|
data=data)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
from notifications_python_client.base import BaseAPIClient
|
from notifications_python_client.base import BaseAPIClient
|
||||||
|
from app.notify_client import _attach_current_user
|
||||||
|
|
||||||
|
|
||||||
class JobApiClient(BaseAPIClient):
|
class JobApiClient(BaseAPIClient):
|
||||||
@@ -26,6 +27,6 @@ class JobApiClient(BaseAPIClient):
|
|||||||
"original_file_name": original_file_name,
|
"original_file_name": original_file_name,
|
||||||
"notification_count": notification_count
|
"notification_count": notification_count
|
||||||
}
|
}
|
||||||
|
_attach_current_user(data)
|
||||||
resp = self.post(url='/service/{}/job'.format(service_id), data=data)
|
resp = self.post(url='/service/{}/job'.format(service_id), data=data)
|
||||||
return resp['data']
|
return resp['data']
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
from app.notify_client.job_api_client import JobApiClient
|
from app.notify_client.job_api_client import JobApiClient
|
||||||
|
|
||||||
|
|
||||||
def test_client_creates_job_data_correctly(mocker):
|
def test_client_creates_job_data_correctly(mocker, fake_uuid):
|
||||||
import uuid
|
job_id = fake_uuid
|
||||||
job_id = str(uuid.uuid4())
|
service_id = fake_uuid
|
||||||
service_id = str(uuid.uuid4())
|
template_id = fake_uuid
|
||||||
template_id = 1
|
|
||||||
original_file_name = 'test.csv'
|
original_file_name = 'test.csv'
|
||||||
notification_count = 1
|
notification_count = 1
|
||||||
|
|
||||||
@@ -19,6 +18,9 @@ def test_client_creates_job_data_correctly(mocker):
|
|||||||
expected_url = '/service/{}/job'.format(service_id)
|
expected_url = '/service/{}/job'.format(service_id)
|
||||||
|
|
||||||
client = JobApiClient()
|
client = JobApiClient()
|
||||||
|
mock_attach_user = mocker.patch(
|
||||||
|
'app.notify_client.job_api_client._attach_current_user',
|
||||||
|
return_value={'created_by': fake_uuid})
|
||||||
mock_post = mocker.patch('app.notify_client.job_api_client.JobApiClient.post')
|
mock_post = mocker.patch('app.notify_client.job_api_client.JobApiClient.post')
|
||||||
|
|
||||||
client.create_job(job_id, service_id, template_id, original_file_name, notification_count)
|
client.create_job(job_id, service_id, template_id, original_file_name, notification_count)
|
||||||
|
|||||||
Reference in New Issue
Block a user