mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-10 01:55:41 -04:00
Refactor to avoid duplicated method definitions
Each of these methods does the same thing, so this refactors into an attribute lookup, which saves writing boilerplate code and makes it easier to add new properties.
This commit is contained in:
@@ -265,73 +265,32 @@ class AnonymousUser(AnonymousUserMixin):
|
|||||||
|
|
||||||
class Service(dict):
|
class Service(dict):
|
||||||
|
|
||||||
|
ALLOWED_PROPERTIES = {
|
||||||
|
'active',
|
||||||
|
'branding',
|
||||||
|
'dvla_organisation',
|
||||||
|
'email_branding',
|
||||||
|
'email_from',
|
||||||
|
'id',
|
||||||
|
'inbound_api',
|
||||||
|
'letter_contact_block',
|
||||||
|
'message_limit',
|
||||||
|
'name',
|
||||||
|
'organisation_type',
|
||||||
|
'permissions',
|
||||||
|
'prefix_sms',
|
||||||
|
'research_mode',
|
||||||
|
'service_callback_api',
|
||||||
|
}
|
||||||
|
|
||||||
def __init__(self, _dict):
|
def __init__(self, _dict):
|
||||||
# in the case of a bad request current service may be `None`
|
# in the case of a bad request current service may be `None`
|
||||||
super().__init__(_dict or {})
|
super().__init__(_dict or {})
|
||||||
|
|
||||||
@property
|
def __getattr__(self, attr):
|
||||||
def id(self):
|
if attr in self.ALLOWED_PROPERTIES:
|
||||||
return self['id']
|
return self[attr]
|
||||||
|
raise AttributeError
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
return self['name']
|
|
||||||
|
|
||||||
@property
|
|
||||||
def inbound_api(self):
|
|
||||||
return self['inbound_api']
|
|
||||||
|
|
||||||
@property
|
|
||||||
def callback_api(self):
|
|
||||||
return self['callback_api']
|
|
||||||
|
|
||||||
@property
|
|
||||||
def service_callback_api(self):
|
|
||||||
return self['service_callback_api']
|
|
||||||
|
|
||||||
@property
|
|
||||||
def organisation_type(self):
|
|
||||||
return self['organisation_type']
|
|
||||||
|
|
||||||
@property
|
|
||||||
def active(self):
|
|
||||||
return self['active']
|
|
||||||
|
|
||||||
@property
|
|
||||||
def message_limit(self):
|
|
||||||
return self['message_limit']
|
|
||||||
|
|
||||||
@property
|
|
||||||
def email_branding(self):
|
|
||||||
return self['email_branding']
|
|
||||||
|
|
||||||
@property
|
|
||||||
def email_from(self):
|
|
||||||
return self['email_from']
|
|
||||||
|
|
||||||
@property
|
|
||||||
def letter_contact_block(self):
|
|
||||||
return self['letter_contact_block']
|
|
||||||
|
|
||||||
@property
|
|
||||||
def prefix_sms(self):
|
|
||||||
return self['prefix_sms']
|
|
||||||
|
|
||||||
@property
|
|
||||||
def research_mode(self):
|
|
||||||
return self['research_mode']
|
|
||||||
|
|
||||||
@property
|
|
||||||
def branding(self):
|
|
||||||
return self['branding']
|
|
||||||
|
|
||||||
@property
|
|
||||||
def dvla_organisation(self):
|
|
||||||
return self['dvla_organisation']
|
|
||||||
|
|
||||||
@property
|
|
||||||
def permissions(self):
|
|
||||||
return self['permissions']
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def trial_mode(self):
|
def trial_mode(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user