mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-06 03:13:42 -05:00
only set organisation on GET and add allowed fields to service client
we were overwriting it before validating the form for POST, so lost info
This commit is contained in:
@@ -288,6 +288,8 @@ def load_user(user_id):
|
||||
|
||||
|
||||
def load_service_before_request():
|
||||
if '/static/' in request.url:
|
||||
return
|
||||
service_id = request.view_args.get('service_id', session.get('service_id')) if request.view_args \
|
||||
else session.get('service_id')
|
||||
from flask.globals import _request_ctx_stack
|
||||
@@ -296,6 +298,7 @@ def load_service_before_request():
|
||||
_request_ctx_stack.top,
|
||||
'service',
|
||||
service_api_client.get_service(service_id)['data'] if service_id else None)
|
||||
print('before_request', request.url)
|
||||
|
||||
|
||||
def save_service_after_request(response):
|
||||
|
||||
@@ -276,17 +276,19 @@ def service_set_branding_and_org(service_id):
|
||||
|
||||
form = ServiceBrandingOrg(branding_type=current_service.get('branding'))
|
||||
# dynamically create org choices, including the null option
|
||||
form.organisation.choices = [('', 'None')] + get_branding_as_value_and_label(organisations)
|
||||
form.organisation.data = current_service['organisation'] or ''
|
||||
form.organisation.choices = [('nil', 'None')] + get_branding_as_value_and_label(organisations)
|
||||
|
||||
if form.validate_on_submit():
|
||||
organisation = None if form.organisation.data == '' else form.organisation.data
|
||||
organisation = None if form.organisation.data == 'nil' else form.organisation.data
|
||||
service_api_client.update_service(
|
||||
service_id,
|
||||
branding=form.branding_type.data,
|
||||
organisation=organisation
|
||||
organisation_id=organisation
|
||||
)
|
||||
return redirect(url_for('.service_settings', service_id=service_id))
|
||||
|
||||
# only set form.organisation.data on GET (to select correct initial radio button)
|
||||
form.organisation.data = current_service['organisation'] or 'nil'
|
||||
return render_template(
|
||||
'views/service-settings/set-branding-and-org.html',
|
||||
form=form,
|
||||
|
||||
@@ -90,7 +90,9 @@ class ServiceAPIClient(NotificationsAPIClient):
|
||||
'email_from',
|
||||
'reply_to_email_address',
|
||||
'sms_sender',
|
||||
'created_by'
|
||||
'created_by',
|
||||
'branding',
|
||||
'organisation_id'
|
||||
}
|
||||
if disallowed_attributes:
|
||||
raise TypeError('Not allowed to update service attributes: {}'.format(
|
||||
|
||||
Reference in New Issue
Block a user