mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-04-15 06:41:23 -04:00
Use service model for the copy page
The view here is rebuilding a pseudo-service object. Now that service objects have templates it’s cleaner to use the actual service object. Requires a small change to the `templates_by_type` method so that it can filter by one or many template types (a user should be able to copy any template whose type is enabled for their service, and the service they’re copying from).
This commit is contained in:
@@ -25,6 +25,7 @@ from app.main.forms import (
|
||||
SMSTemplateForm,
|
||||
)
|
||||
from app.main.views.send import get_example_csv_rows, get_sender_details
|
||||
from app.models.service import Service
|
||||
from app.template_previews import TemplatePreview, get_page_count_for_letter
|
||||
from app.utils import (
|
||||
email_or_sms_not_enabled,
|
||||
@@ -231,15 +232,10 @@ def add_template_by_type(service_id):
|
||||
def choose_template_to_copy(service_id):
|
||||
return render_template(
|
||||
'views/templates/copy.html',
|
||||
services=[{
|
||||
'name': service['name'],
|
||||
'id': service['id'],
|
||||
'templates': [
|
||||
template for template in
|
||||
service_api_client.get_service_templates(service['id'])['data']
|
||||
if current_service.has_permission(template['template_type'])
|
||||
],
|
||||
} for service in user_api_client.get_services_for_user(current_user)],
|
||||
services=[
|
||||
Service(service)
|
||||
for service in user_api_client.get_services_for_user(current_user)
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -81,9 +81,11 @@ class Service():
|
||||
]
|
||||
|
||||
def templates_by_type(self, template_type):
|
||||
if isinstance(template_type, str):
|
||||
template_type = [template_type]
|
||||
return [
|
||||
template for template in self.templates
|
||||
if template_type in {'all', template['template_type']}
|
||||
if set(template_type) & {'all', template['template_type']}
|
||||
]
|
||||
|
||||
@property
|
||||
|
||||
@@ -13,13 +13,14 @@
|
||||
</div>
|
||||
<nav>
|
||||
{% for service in services %}
|
||||
{% if service.templates and services|length > 1 %}
|
||||
{% set templates = service.templates_by_type(current_service.permissions) %}
|
||||
{% if templates and services|length > 1 %}
|
||||
<h2 class="">
|
||||
{{ service.name }}
|
||||
</h2>
|
||||
<div class="left-gutter-4-3 bottom-gutter-3-2">
|
||||
{% endif %}
|
||||
{% for template in service.templates %}
|
||||
{% for template in templates %}
|
||||
<h2 class="message-name">
|
||||
<a href="{{ url_for('.copy_template', service_id=current_service.id, template_id=template.id, from_service=service.id) }}">{{ template.name }}</a>
|
||||
</h2>
|
||||
@@ -27,7 +28,7 @@
|
||||
{{ message_count_label(1, template.template_type, suffix='')|capitalize }} template
|
||||
</p>
|
||||
{% endfor %}
|
||||
{% if service.templates %}
|
||||
{% if templates %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
Reference in New Issue
Block a user