submission: allow NameID and channel in query string (#25305)
This commit is contained in:
parent
597a40eed9
commit
439a5bb82c
|
@ -2270,6 +2270,44 @@ def test_backoffice_submission_no_manual_channel_with_welco(pub, welco_url):
|
|||
resp = app.get('/backoffice/submission/%s/' % formdef.url_name)
|
||||
assert 'submission_channel' not in resp.form.fields
|
||||
|
||||
def test_backoffice_submission_with_nameid_and_channel(pub, local_user):
|
||||
user = create_user(pub)
|
||||
create_environment(pub)
|
||||
|
||||
formdef = FormDef.get_by_urlname('form-title')
|
||||
formdef.fields[0].prefill = {'type': 'formula', 'value': 'form_user_email'}
|
||||
formdef.backoffice_submission_roles = user.roles[:]
|
||||
formdef.enable_tracking_codes = True
|
||||
formdef.store()
|
||||
|
||||
app = login(get_app(pub))
|
||||
resp = app.get('/backoffice/submission/form-title/?NameID=%s&channel=mail' % local_user.name_identifiers[0])
|
||||
assert resp.location.startswith('http://example.net/backoffice/submission/form-title/')
|
||||
|
||||
formdata_no = resp.location.split('/')[-1]
|
||||
formdata = formdef.data_class().get(formdata_no)
|
||||
assert formdata.user_id == str(local_user.id)
|
||||
assert formdata.submission_channel == 'mail'
|
||||
assert formdata.status == 'draft'
|
||||
|
||||
resp = resp.follow() # redirect to created draft
|
||||
resp = resp.follow() # redirect to ?mt=
|
||||
|
||||
assert resp.form['f1'].value == local_user.email # prefill with form_user_email
|
||||
resp.form['f2'] = 'baz'
|
||||
resp.form['f3'] = 'C'
|
||||
resp = resp.form.submit('submit')
|
||||
assert 'Check values then click submit.' in resp.body
|
||||
# final submit
|
||||
resp = resp.form.submit('submit')
|
||||
|
||||
formdata_no = resp.location.split('/')[-2]
|
||||
data_class = formdef.data_class()
|
||||
formdata = data_class.get(formdata_no)
|
||||
assert formdata.user_id == str(local_user.id)
|
||||
assert formdata.submission_channel == 'mail'
|
||||
assert formdata.status == 'wf-new'
|
||||
|
||||
def test_backoffice_wscall_failure_display(http_requests, pub):
|
||||
user = create_user(pub)
|
||||
create_environment(pub)
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import time
|
||||
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from quixote import get_publisher, get_request, get_response, get_session, redirect
|
||||
|
@ -85,6 +87,26 @@ class FormFillPage(PublicFormFillPage):
|
|||
self.remove_draft = RemoveDraftDirectory(self)
|
||||
|
||||
def _q_index(self, *args, **kwargs):
|
||||
# if NameID or channel are in query string, create a new draft with
|
||||
# these parameters, and redirect to it
|
||||
submission_channel = get_request().form.get('channel')
|
||||
name_id = get_request().form.get('NameID')
|
||||
if name_id or submission_channel:
|
||||
formdata = self.formdef.data_class()()
|
||||
formdata.data = {}
|
||||
formdata.backoffice_submission = True
|
||||
formdata.submission_channel = submission_channel or ''
|
||||
formdata.submission_context = {'agent_id': get_request().user.id}
|
||||
formdata.status = 'draft'
|
||||
formdata.receipt_time = time.localtime()
|
||||
if name_id:
|
||||
users = list(get_publisher().user_class.get_users_with_name_identifier(name_id))
|
||||
if users:
|
||||
formdata.user_id = users[0].id
|
||||
formdata.store()
|
||||
self.set_tracking_code(formdata)
|
||||
return redirect('%s' % formdata.id)
|
||||
|
||||
self.selected_submission_channel = get_request().form.get('submission_channel') or ''
|
||||
return super(FormFillPage, self)._q_index(*args, **kwargs)
|
||||
|
||||
|
@ -127,7 +149,10 @@ class FormFillPage(PublicFormFillPage):
|
|||
r += htmltext('<p>-</p>')
|
||||
|
||||
welco_url = get_publisher().get_site_option('welco_url', 'options')
|
||||
if not welco_url and not self.edit_mode:
|
||||
if formdata and formdata.submission_context:
|
||||
from .management import FormBackOfficeStatusPage
|
||||
r += FormBackOfficeStatusPage(self.formdef, formdata).get_extra_context_bar()
|
||||
elif not welco_url and not self.edit_mode:
|
||||
r += htmltext('<div class="submit-channel-selection" style="display: none;">')
|
||||
r += htmltext('<h3>%s</h3>') % _('Channel')
|
||||
r += htmltext('<select>')
|
||||
|
@ -140,10 +165,6 @@ class FormFillPage(PublicFormFillPage):
|
|||
r += htmltext('</select>')
|
||||
r += htmltext('</div>')
|
||||
|
||||
if formdata and formdata.submission_context:
|
||||
from .management import FormBackOfficeStatusPage
|
||||
r += FormBackOfficeStatusPage(self.formdef, formdata).get_extra_context_bar()
|
||||
|
||||
return r.getvalue()
|
||||
|
||||
def create_view_form(self, *args, **kwargs):
|
||||
|
|
Loading…
Reference in New Issue