Make a service model and use for permissions

Having the service floating about as JSON is a bit flakey. Could easily
introduce a mistake where you mistype the name of a key and silently
get `None`.

Also means doing awkward things like `if 'permission' in
current_service['permissions']`, whereas for users we can do the
much cleaner `user.has_permission()`.

So this commit:
- introduces a model
- adds a `.has_permission` method similar to the one we have for users
This commit is contained in:
Chris Hill-Scott
2018-07-20 08:43:02 +01:00
parent 3056731cbb
commit 036923c382
12 changed files with 47 additions and 31 deletions

View File

@@ -37,7 +37,7 @@ dummy_bearer_token = 'bearer_token_set'
@user_has_permissions('manage_api_keys')
def api_integration(service_id):
callbacks_link = (
'.api_callbacks' if 'inbound_sms' in current_service['permissions']
'.api_callbacks' if current_service.has_permission('inbound_sms')
else '.delivery_status_callback'
)
return render_template(
@@ -104,7 +104,7 @@ def create_api_key(service_id):
'Not available because your service is in '
'<a href="{}#trial-mode">trial mode</a>'.format(url_for(".using_notify"))
)
if 'letter' in current_service['permissions']:
if current_service.has_permission('letter'):
option_hints[KEY_TYPE_TEAM] = 'Cant be used to send letters'
if form.validate_on_submit():
if form.key_type.data in disabled_options:
@@ -198,7 +198,7 @@ def get_delivery_status_callback_details():
def delivery_status_callback(service_id):
delivery_status_callback = get_delivery_status_callback_details()
back_link = (
'.api_callbacks' if 'inbound_sms' in current_service['permissions']
'.api_callbacks' if current_service.has_permission('inbound_sms')
else '.api_integration'
)