mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-01 04:09:46 -04:00
Make _attach_current_user a pure function
Mutating dictionaries is gross and doesn’t work as you’d expect. Better to have the function return a new dictionary instead. Means we can be explicit that `created_by` is one of the allowed params when updating a service.
This commit is contained in:
@@ -2,5 +2,7 @@ from flask.ext.login import current_user
|
||||
|
||||
|
||||
def _attach_current_user(data):
|
||||
data['created_by'] = current_user.id
|
||||
return data
|
||||
return dict(
|
||||
created_by=current_user.id,
|
||||
**data
|
||||
)
|
||||
|
||||
@@ -30,7 +30,7 @@ class ApiKeyApiClient(BaseAPIClient):
|
||||
'name': key_name,
|
||||
'key_type': key_type
|
||||
}
|
||||
_attach_current_user(data)
|
||||
data = _attach_current_user(data)
|
||||
key = self.post(url='/service/{}/api-key'.format(service_id), data=data)
|
||||
return key['data']
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ class InviteApiClient(BaseAPIClient):
|
||||
'from_user': invite_from_id,
|
||||
'permissions': permissions
|
||||
}
|
||||
_attach_current_user(data)
|
||||
data = _attach_current_user(data)
|
||||
resp = self.post(url='/service/{}/invite'.format(service_id), data=data)
|
||||
return InvitedUser(**resp['data'])
|
||||
|
||||
@@ -40,7 +40,7 @@ class InviteApiClient(BaseAPIClient):
|
||||
|
||||
def cancel_invited_user(self, service_id, invited_user_id):
|
||||
data = {'status': 'cancelled'}
|
||||
_attach_current_user(data)
|
||||
data = _attach_current_user(data)
|
||||
self.post(url='/service/{0}/invite/{1}'.format(service_id, invited_user_id),
|
||||
data=data)
|
||||
|
||||
|
||||
@@ -32,6 +32,6 @@ class JobApiClient(BaseAPIClient):
|
||||
"original_file_name": original_file_name,
|
||||
"notification_count": notification_count
|
||||
}
|
||||
_attach_current_user(data)
|
||||
data = _attach_current_user(data)
|
||||
resp = self.post(url='/service/{}/job'.format(service_id), data=data)
|
||||
return resp['data']
|
||||
|
||||
@@ -29,5 +29,5 @@ class ProviderClient(BaseAPIClient):
|
||||
data = {
|
||||
"priority": priority
|
||||
}
|
||||
_attach_current_user(data)
|
||||
data = _attach_current_user(data)
|
||||
return self.post(url='/provider-details/{}'.format(provider_id), data=data)
|
||||
|
||||
@@ -30,7 +30,7 @@ class ServiceAPIClient(NotificationsAPIClient):
|
||||
"restricted": restricted,
|
||||
"email_from": email_from
|
||||
}
|
||||
_attach_current_user(data)
|
||||
data = _attach_current_user(data)
|
||||
return self.post("/service", data)['data']['id']
|
||||
|
||||
def delete_service(self, service_id):
|
||||
@@ -81,7 +81,8 @@ class ServiceAPIClient(NotificationsAPIClient):
|
||||
"""
|
||||
Update a service.
|
||||
"""
|
||||
disallowed_attributes = set(kwargs.keys()) - {
|
||||
data = _attach_current_user(kwargs)
|
||||
disallowed_attributes = set(data.keys()) - {
|
||||
'name',
|
||||
'users',
|
||||
'message_limit',
|
||||
@@ -89,14 +90,14 @@ class ServiceAPIClient(NotificationsAPIClient):
|
||||
'restricted',
|
||||
'email_from',
|
||||
'reply_to_email_address',
|
||||
'sms_sender'
|
||||
'sms_sender',
|
||||
'created_by'
|
||||
}
|
||||
if disallowed_attributes:
|
||||
raise TypeError('Not allowed to update service attributes: {}'.format(
|
||||
", ".join(disallowed_attributes)
|
||||
))
|
||||
|
||||
_attach_current_user(kwargs)
|
||||
endpoint = "/service/{0}".format(service_id)
|
||||
return self.post(endpoint, data)
|
||||
|
||||
@@ -127,7 +128,7 @@ class ServiceAPIClient(NotificationsAPIClient):
|
||||
data.update({
|
||||
'subject': subject
|
||||
})
|
||||
_attach_current_user(data)
|
||||
data = _attach_current_user(data)
|
||||
endpoint = "/service/{0}/template".format(service_id)
|
||||
return self.post(endpoint, data)
|
||||
|
||||
@@ -146,7 +147,7 @@ class ServiceAPIClient(NotificationsAPIClient):
|
||||
data.update({
|
||||
'subject': subject
|
||||
})
|
||||
_attach_current_user(data)
|
||||
data = _attach_current_user(data)
|
||||
endpoint = "/service/{0}/template/{1}".format(service_id, id_)
|
||||
return self.post(endpoint, data)
|
||||
|
||||
@@ -187,7 +188,7 @@ class ServiceAPIClient(NotificationsAPIClient):
|
||||
data = {
|
||||
'archived': True
|
||||
}
|
||||
_attach_current_user(data)
|
||||
data = _attach_current_user(data)
|
||||
return self.post(endpoint, data=data)
|
||||
|
||||
def find_all_service_email_from(self, user_id=None):
|
||||
|
||||
Reference in New Issue
Block a user