esup_signature: do not send empty parameters (#79611)
gitea/passerelle/pipeline/head This commit looks good
Details
gitea/passerelle/pipeline/head This commit looks good
Details
This commit is contained in:
parent
122a0f6c22
commit
78c27ffe27
|
@ -176,6 +176,22 @@ def to_bool(some_str):
|
|||
return some_str == 'true'
|
||||
|
||||
|
||||
def add_params(params, params_spec, post_data):
|
||||
for name, esup_name in params_spec:
|
||||
value = post_data.get(name, '')
|
||||
if value:
|
||||
params[esup_name] = value
|
||||
return params
|
||||
|
||||
|
||||
def add_list_params(params, params_spec, post_data):
|
||||
for name, esup_name in params_spec:
|
||||
value = clean_list(post_data.get(name, []))
|
||||
if value:
|
||||
params[esup_name] = value
|
||||
return params
|
||||
|
||||
|
||||
class EsupSignature(BaseResource, HTTPResource):
|
||||
base_url = models.URLField(_('API URL'))
|
||||
forced_headers = models.TextField(
|
||||
|
@ -276,14 +292,13 @@ class EsupSignature(BaseResource, HTTPResource):
|
|||
|
||||
params = {
|
||||
'recipientsEmails': clean_list(post_data['recipients_emails']),
|
||||
'recipientsCCEmails': clean_list(post_data.get('recipients_cc_emails', [])),
|
||||
'comment': post_data.get('comment', ''),
|
||||
'signType': post_data.get('sign_type', 'pdfImageStamp'),
|
||||
'eppn': post_data['eppn'],
|
||||
'title': post_data.get('title', ''),
|
||||
'targetUrl': post_data.get('target_url', ''),
|
||||
}
|
||||
|
||||
params = add_list_params(params, (('recipients_cc_emails', 'recipientsCCEmails'),), post_data)
|
||||
params = add_params(
|
||||
params, (('comment', 'comment'), ('title', 'title'), ('target_url', 'targetUrl')), post_data
|
||||
)
|
||||
bool_params = {
|
||||
'all_sign_to_complete': ('allSignToComplete', False),
|
||||
'user_sign_first': ('userSignFirst', False),
|
||||
|
@ -346,14 +361,22 @@ class EsupSignature(BaseResource, HTTPResource):
|
|||
|
||||
params = {
|
||||
'createByEppn': post_data['create_by_eppn'],
|
||||
'title': post_data.get('title', ''),
|
||||
'recipientsEmails': clean_list(post_data.get('recipients_emails', [])),
|
||||
'allSignToCompletes': clean_list(post_data.get('all_sign_to_completes', [])),
|
||||
'targetEmails': clean_list(post_data.get('target_emails', [])),
|
||||
'signRequestParamsJsonString': post_data.get('signrequest_params_jsonstring', ''),
|
||||
'targetUrls': clean_list(post_data.get('target_urls', [])),
|
||||
}
|
||||
|
||||
params = add_list_params(
|
||||
params,
|
||||
(
|
||||
('recipients_emails', 'recipientsEmails'),
|
||||
('all_sign_to_completes', 'allSignToCompletes'),
|
||||
('target_emails', 'targetEmails'),
|
||||
('target_urls', 'targetUrls'),
|
||||
),
|
||||
post_data,
|
||||
)
|
||||
params = add_params(
|
||||
params,
|
||||
(('title', 'title'), ('signrequest_params_jsonstring', 'signRequestParamsJsonString')),
|
||||
post_data,
|
||||
)
|
||||
return {
|
||||
'data': self._call(
|
||||
'/ws/workflows/%s/new' % post_data['workflow_id'], method='post', params=params, files=files
|
||||
|
|
|
@ -53,7 +53,11 @@ def test_new(app, connector):
|
|||
)
|
||||
resp = app.post_json('/esup-signature/esup-signature/new', params=params)
|
||||
assert len(rsps.calls) == 1
|
||||
assert rsps.calls[0].request.headers['Content-Type'].startswith('multipart/form-data')
|
||||
req = rsps.calls[0].request
|
||||
assert req.headers['Content-Type'].startswith('multipart/form-data')
|
||||
assert 'comment' not in req.url
|
||||
assert 'targetUrl' not in req.url
|
||||
assert 'recipientsCCEmails' not in req.url
|
||||
json_resp = resp.json
|
||||
assert json_resp['err'] == 0
|
||||
assert json_resp['data'] == 9
|
||||
|
@ -107,6 +111,37 @@ def test_new_with_workflow(app, connector):
|
|||
assert json_resp['data'] == 9
|
||||
|
||||
|
||||
def test_new_with_workflow_min_params(app, connector):
|
||||
params = {
|
||||
'file': {
|
||||
'filename': 'bla',
|
||||
'content': base64.b64encode(b'who what').decode(),
|
||||
'content_type': 'text/plain',
|
||||
},
|
||||
'workflow_id': '99',
|
||||
'create_by_eppn': 'aa@foo.com',
|
||||
}
|
||||
with responses.RequestsMock() as rsps:
|
||||
query_params = {
|
||||
'createByEppn': 'aa@foo.com',
|
||||
}
|
||||
rsps.post(
|
||||
'https://esup-signature.invalid/ws/workflows/99/new',
|
||||
match=[responses.matchers.query_param_matcher(query_params)],
|
||||
status=200,
|
||||
json=9,
|
||||
)
|
||||
resp = app.post_json('/esup-signature/esup-signature/new-with-workflow', params=params)
|
||||
assert len(rsps.calls) == 1
|
||||
req = rsps.calls[0].request
|
||||
assert req.headers['Content-Type'].startswith('multipart/form-data')
|
||||
assert 'title' not in req.url
|
||||
assert 'recipientsEmails' not in req.url
|
||||
json_resp = resp.json
|
||||
assert json_resp['err'] == 0
|
||||
assert json_resp['data'] == 9
|
||||
|
||||
|
||||
def test_status(app, connector):
|
||||
with responses.RequestsMock() as rsps:
|
||||
rsps.get('https://esup-signature.invalid/ws/signrequests/1', status=200, json={'status': 'completed'})
|
||||
|
|
Loading…
Reference in New Issue