mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-09 01:23:11 -04:00
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:
@@ -108,7 +108,7 @@ def choose_template(service_id, template_type='all'):
|
||||
templates = service_api_client.get_service_templates(service_id)['data']
|
||||
|
||||
letters_available = (
|
||||
'letter' in current_service['permissions'] and
|
||||
current_service.has_permission('letter') and
|
||||
current_user.has_permissions('view_activity')
|
||||
)
|
||||
|
||||
@@ -207,9 +207,9 @@ def view_template_version_preview(service_id, template_id, version, filetype):
|
||||
def add_template_by_type(service_id):
|
||||
|
||||
form = ChooseTemplateType(
|
||||
include_letters='letter' in current_service['permissions'],
|
||||
include_letters=current_service.has_permission('letter'),
|
||||
include_copy=any((
|
||||
service_api_client.count_service_templates(service_id),
|
||||
service_api_client.count_service_templates(service_id) > 0,
|
||||
len(user_api_client.get_service_ids_for_user(current_user)) > 1,
|
||||
)),
|
||||
)
|
||||
@@ -672,5 +672,5 @@ def get_human_readable_delta(from_time, until_time):
|
||||
def should_show_template(template_type):
|
||||
return (
|
||||
template_type != 'letter' or
|
||||
'letter' in current_service['permissions']
|
||||
current_service.has_permission('letter')
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user