Fix setting of broadcast permission

This was broken because current_service doesn’t update itself after
calling the `update` method of the API. So we thought we were changing
the permissions like this:
```
{'email', 'sms', 'letter'}
{'email', 'sms', 'letter', 'broadcast'}
{'sms', 'letter', 'broadcast'}
{'letter', 'broadcast'}
{'broadcast'}
```

But actually we were doing this:
```
{'email', 'sms', 'letter'}
{'email', 'sms', 'letter', 'broadcast'}
{'sms', 'letter'}
{'email', 'letter'}
{'email', 'sms'}
```

This commit changes the code to update the permissions like this:
```
{'email', 'sms', 'letter'}
{'broadcast'}
```

It does so by adding a new method to the service model which changes all
the permissions in one API call, and updates the tests to mock the
underlying API call, not the method on the model.
This commit is contained in:
Chris Hill-Scott
2020-07-16 17:21:27 +01:00
parent 7b00e3c5b9
commit e29a477eb1
3 changed files with 64 additions and 36 deletions

View File

@@ -318,10 +318,7 @@ def service_set_broadcast_permission(service_id):
if form.validate_on_submit():
if form.enabled.data:
current_service.force_permission('broadcast', on=True)
current_service.force_permission('email', on=False)
current_service.force_permission('sms', on=False)
current_service.force_permission('letter', on=False)
current_service.force_broadcast_permission_on()
else:
current_service.force_permission('broadcast', on=False)