mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-18 13:39:41 -04:00
Use service model to look up service attributes
This is better than just keying into the JSON because it means you get an exception straight away when looking up a key that doesn’t exist (which via mocking you could ordinarily miss).
This commit is contained in:
@@ -47,7 +47,7 @@ class NotifyAdminAPIClient(BaseAPIClient):
|
||||
|
||||
# if the current service is inactive and the user isn't a platform admin, we should block them from making any
|
||||
# stateful modifications to that service
|
||||
if current_service and not current_service['active'] and not current_user.platform_admin:
|
||||
if current_service and not current_service.active and not current_user.platform_admin:
|
||||
abort(403)
|
||||
|
||||
def post(self, *args, **kwargs):
|
||||
|
||||
@@ -269,5 +269,73 @@ class Service(dict):
|
||||
# in the case of a bad request current service may be `None`
|
||||
super().__init__(_dict or {})
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
return self['id']
|
||||
|
||||
@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
|
||||
def trial_mode(self):
|
||||
return self['restricted']
|
||||
|
||||
def has_permission(self, permission):
|
||||
return permission in self['permissions']
|
||||
return permission in self.permissions
|
||||
|
||||
Reference in New Issue
Block a user