Remove dependence on domains.yml from settings

Settings looked at `domains.yml` when users were making go live requests
or email branding requests.

This will allow us to remove the `domains.yml` file, by using
information about organisations that is now stored in the database
instead.
This commit is contained in:
Chris Hill-Scott
2019-04-04 11:23:40 +01:00
parent 835d11d8d6
commit 3565ffc33f
6 changed files with 72 additions and 54 deletions

View File

@@ -54,7 +54,6 @@ from app.main.forms import (
branding_options_dict,
)
from app.utils import (
AgreementInfo,
email_safe,
user_has_permissions,
user_is_gov_user,
@@ -180,7 +179,7 @@ def estimate_usage(service_id):
@user_has_permissions('manage_service')
def request_to_go_live(service_id):
agreement_signed = AgreementInfo.from_current_user().agreement_signed
agreement_signed = current_service.organisation.agreement_signed
return render_template(
'views/service-settings/request-to-go-live.html',
@@ -226,7 +225,7 @@ def submit_request_to_go_live(service_id):
service_name=current_service.name,
service_dashboard=url_for('main.service_dashboard', service_id=current_service.id, _external=True),
organisation_type=str(current_service.organisation_type).title(),
agreement=AgreementInfo.from_current_user().as_human_readable,
agreement=current_service.organisation.as_human_readable(current_user.email_domain),
checklist=current_service.go_live_checklist_completed_as_yes_no,
volume_email=print_if_number(current_service.volume_email),
volume_email_formatted=format_if_number(current_service.volume_email),
@@ -237,7 +236,7 @@ def submit_request_to_go_live(service_id):
research_consent='Yes' if current_service.consent_to_research else 'No',
existing_live='Yes' if user_api_client.user_has_live_services(current_user) else 'No',
service_id=current_service.id,
organisation=AgreementInfo.from_current_user().owner,
organisation=current_service.organisation.name,
user_name=current_user.name,
user_email=current_user.email_address,
date=datetime.now(tz=pytz.timezone('Europe/London')).strftime('%d/%m/%Y'),
@@ -245,7 +244,7 @@ def submit_request_to_go_live(service_id):
ticket_type=zendesk_client.TYPE_QUESTION,
user_email=current_user.email_address,
user_name=current_user.name,
tags=get_request_to_go_live_tags(current_service, current_user),
tags=get_request_to_go_live_tags(current_service),
)
flash('Thanks for your request to go live. Well get back to you within one working day.', 'default')
@@ -985,7 +984,7 @@ def branding_request(service_id):
'\nCurrent branding: {current_branding}'
'\nBranding requested: {branding_requested}'
).format(
organisation=AgreementInfo.from_current_user().as_info_for_branding_request,
organisation=current_service.organisation.as_info_for_branding_request(current_user.email_domain),
service_name=current_service.name,
dashboard_url=url_for('main.service_dashboard', service_id=current_service.id, _external=True),
current_branding=current_service.email_branding_name,
@@ -1073,20 +1072,17 @@ def check_contact_details_type(contact_details):
return 'phone_number'
def get_request_to_go_live_tags(service, user):
return list(_get_request_to_go_live_tags(
service,
AgreementInfo.from_user(user).agreement_signed,
))
def get_request_to_go_live_tags(service):
return list(_get_request_to_go_live_tags(service))
def _get_request_to_go_live_tags(service, agreement_signed):
def _get_request_to_go_live_tags(service):
BASE = 'notify_request_to_go_live'
yield BASE
if service.go_live_checklist_completed and agreement_signed:
if service.go_live_checklist_completed and service.organisation.agreement_signed:
yield BASE + '_complete'
return
@@ -1094,7 +1090,7 @@ def _get_request_to_go_live_tags(service, agreement_signed):
(True, ''),
(not service.volumes, '_volumes'),
(not service.go_live_checklist_completed, '_checklist'),
(not agreement_signed, '_mou'),
(not service.organisation.agreement_signed, '_mou'),
(service.needs_to_add_email_reply_to_address, '_email_reply_to'),
(not service.has_team_members, '_team_member'),
(not service.has_templates, '_template_content'),

View File

@@ -31,13 +31,12 @@ class Organisation(JSONModel):
def crown_status(self):
return self.crown
@property
def as_human_readable(self):
def as_human_readable(self, fallback_domain):
if 'dwp.' in ''.join(self.domains):
return 'DWP - Requires OED approval'
if self.agreement_signed:
return 'Yes, on behalf of {}'.format(self.name)
elif self.owner:
elif self.name:
return '{} (organisation is {}, {})'.format(
{
False: 'No',
@@ -51,11 +50,10 @@ class Organisation(JSONModel):
}.get(self.crown_status),
)
else:
return 'Cant tell (domain is {})'.format(self._domain)
return 'Cant tell (domain is {})'.format(fallback_domain)
@property
def as_info_for_branding_request(self):
return self.owner or 'Cant tell (domain is {})'.format(self._domain)
def as_info_for_branding_request(self, fallback_domain):
return self.name or 'Cant tell (domain is {})'.format(fallback_domain)
@property
def as_jinja_template(self):

View File

@@ -396,10 +396,6 @@ class Service(JSONModel):
organisations_client.get_service_organisation(self.id)
)
@property
def organisation_name(self):
return self.organisation.name
@cached_property
def inbound_number(self):
return inbound_number_client.get_inbound_sms_number_for_service(self.id)['data'].get('number', '')

View File

@@ -300,7 +300,7 @@
{% call row() %}
{{ text_field('Organisation')}}
{{ optional_text_field(current_service.organisation_name) }}
{{ optional_text_field(current_service.organisation.name) }}
{{ edit_field('Change', url_for('.link_service_to_organisation', service_id=current_service.id)) }}
{% endcall %}
{% call row() %}