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

@@ -401,7 +401,7 @@ def send_test_step(service_id, template_id, step_index):
dict_to_populate_from=get_normalised_placeholders_from_session(),
template_type=template.template_type,
optional_placeholder=optional_placeholder,
allow_international_phone_numbers='international_sms' in current_service['permissions'],
allow_international_phone_numbers=current_service.has_permission('international_sms'),
)
if form.validate_on_submit():
@@ -551,7 +551,7 @@ def _check_messages(service_id, template_id, upload_id, preview_row, letters_as_
[user.name, user.mobile_number, user.email_address] for user in users
) if current_service['restricted'] else None,
remaining_messages=remaining_messages,
international_sms='international_sms' in current_service['permissions'],
international_sms=current_service.has_permission('international_sms'),
)
if request.args.get('from_test'):