Merge pull request #2180 from alphagov/service-model

Make a service model
This commit is contained in:
Chris Hill-Scott
2018-07-31 13:31:09 +01:00
committed by GitHub
20 changed files with 156 additions and 111 deletions

View File

@@ -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):

View File

@@ -261,3 +261,40 @@ class AnonymousUser(AnonymousUserMixin):
# set the anonymous user so that if a new browser hits us we don't error http://stackoverflow.com/a/19275188
def logged_in_elsewhere(self):
return False
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):
# in the case of a bad request current service may be `None`
super().__init__(_dict or {})
def __getattr__(self, attr):
if attr in self.ALLOWED_PROPERTIES:
return self[attr]
raise AttributeError
@property
def trial_mode(self):
return self['restricted']
def has_permission(self, permission):
return permission in self.permissions