mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-09 10:09:49 -04: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():
|
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 \
|
service_id = request.view_args.get('service_id', session.get('service_id')) if request.view_args \
|
||||||
else session.get('service_id')
|
else session.get('service_id')
|
||||||
from flask.globals import _request_ctx_stack
|
from flask.globals import _request_ctx_stack
|
||||||
@@ -296,6 +298,7 @@ def load_service_before_request():
|
|||||||
_request_ctx_stack.top,
|
_request_ctx_stack.top,
|
||||||
'service',
|
'service',
|
||||||
service_api_client.get_service(service_id)['data'] if service_id else None)
|
service_api_client.get_service(service_id)['data'] if service_id else None)
|
||||||
|
print('before_request', request.url)
|
||||||
|
|
||||||
|
|
||||||
def save_service_after_request(response):
|
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'))
|
form = ServiceBrandingOrg(branding_type=current_service.get('branding'))
|
||||||
# dynamically create org choices, including the null option
|
# dynamically create org choices, including the null option
|
||||||
form.organisation.choices = [('', 'None')] + get_branding_as_value_and_label(organisations)
|
form.organisation.choices = [('nil', 'None')] + get_branding_as_value_and_label(organisations)
|
||||||
form.organisation.data = current_service['organisation'] or ''
|
|
||||||
|
|
||||||
if form.validate_on_submit():
|
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_api_client.update_service(
|
||||||
service_id,
|
service_id,
|
||||||
branding=form.branding_type.data,
|
branding=form.branding_type.data,
|
||||||
organisation=organisation
|
organisation_id=organisation
|
||||||
)
|
)
|
||||||
return redirect(url_for('.service_settings', service_id=service_id))
|
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(
|
return render_template(
|
||||||
'views/service-settings/set-branding-and-org.html',
|
'views/service-settings/set-branding-and-org.html',
|
||||||
form=form,
|
form=form,
|
||||||
|
|||||||
@@ -90,7 +90,9 @@ class ServiceAPIClient(NotificationsAPIClient):
|
|||||||
'email_from',
|
'email_from',
|
||||||
'reply_to_email_address',
|
'reply_to_email_address',
|
||||||
'sms_sender',
|
'sms_sender',
|
||||||
'created_by'
|
'created_by',
|
||||||
|
'branding',
|
||||||
|
'organisation_id'
|
||||||
}
|
}
|
||||||
if disallowed_attributes:
|
if disallowed_attributes:
|
||||||
raise TypeError('Not allowed to update service attributes: {}'.format(
|
raise TypeError('Not allowed to update service attributes: {}'.format(
|
||||||
|
|||||||
Reference in New Issue
Block a user