mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-23 07:46:23 -04:00
Refactor duplicative methods
These methods were both doing the exact same thing. There may well be others in the future that also need to do this thing.
This commit is contained in:
@@ -58,6 +58,12 @@ class Service():
|
|||||||
return self._dict[attr]
|
return self._dict[attr]
|
||||||
raise AttributeError('`{}` is not a service attribute'.format(attr))
|
raise AttributeError('`{}` is not a service attribute'.format(attr))
|
||||||
|
|
||||||
|
def _get_by_id(self, things, id):
|
||||||
|
try:
|
||||||
|
return next(thing for thing in things if thing['id'] == id)
|
||||||
|
except StopIteration:
|
||||||
|
abort(404)
|
||||||
|
|
||||||
def update(self, **kwargs):
|
def update(self, **kwargs):
|
||||||
return service_api_client.update_service(self.id, **kwargs)
|
return service_api_client.update_service(self.id, **kwargs)
|
||||||
|
|
||||||
@@ -310,13 +316,7 @@ class Service():
|
|||||||
]
|
]
|
||||||
|
|
||||||
def get_template_folder(self, folder_id):
|
def get_template_folder(self, folder_id):
|
||||||
try:
|
return self._get_by_id(self.all_template_folders, folder_id)
|
||||||
return next(
|
|
||||||
folder for folder in self.all_template_folders
|
|
||||||
if folder['id'] == folder_id
|
|
||||||
)
|
|
||||||
except StopIteration:
|
|
||||||
abort(404)
|
|
||||||
|
|
||||||
def is_folder_visible(self, template_folder_id, template_type='all'):
|
def is_folder_visible(self, template_folder_id, template_type='all'):
|
||||||
|
|
||||||
@@ -374,7 +374,4 @@ class Service():
|
|||||||
)
|
)
|
||||||
|
|
||||||
def get_api_key(self, id):
|
def get_api_key(self, id):
|
||||||
try:
|
return self._get_by_id(self.api_keys, id)
|
||||||
return next(key for key in self.api_keys if key['id'] == id)
|
|
||||||
except StopIteration:
|
|
||||||
abort(404)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user