mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-02 17:48:50 -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:
@@ -152,7 +152,7 @@ def usage(service_id):
|
||||
yearly_usage = billing_api_client.get_service_usage_ft(service_id, year)
|
||||
|
||||
usage_template = 'views/usage.html'
|
||||
if 'letter' in current_service['permissions']:
|
||||
if current_service.has_permission('letter'):
|
||||
usage_template = 'views/usage-with-letters.html'
|
||||
return render_template(
|
||||
usage_template,
|
||||
@@ -293,7 +293,7 @@ def get_dashboard_partials(service_id):
|
||||
stats = service_api_client.get_service_statistics(service_id, today_only=False)
|
||||
column_width, max_notifiction_count = get_column_properties(
|
||||
number_of_columns=(
|
||||
3 if 'letter' in current_service['permissions'] else 2
|
||||
3 if current_service.has_permission('letter') else 2
|
||||
)
|
||||
)
|
||||
dashboard_totals = get_dashboard_totals(stats),
|
||||
@@ -313,7 +313,7 @@ def get_dashboard_partials(service_id):
|
||||
'views/dashboard/_inbox.html',
|
||||
inbound_sms_summary=(
|
||||
service_api_client.get_inbound_sms_summary(service_id)
|
||||
if 'inbound_sms' in current_service['permissions'] else None
|
||||
if current_service.has_permission('inbound_sms') else None
|
||||
),
|
||||
),
|
||||
'totals': render_template(
|
||||
|
||||
Reference in New Issue
Block a user