[FIX] docuseal_signing: restrict signature requests and report API errors
- Reserve the generated "Request signature" action to administrators (base.group_system), who are the only ones able to read the Docuseal templates, instead of letting other users hit an AccessError. - Request the signature of a single contact from the contextual action (_action_request_signature): with several contacts, a failure could leave some of them already emailed while the action reports an error. A notification confirms the request. - Share the Docuseal API call in _docuseal_request: a missing token or a Docuseal error (with the explanation it sends) now raises a readable UserError when sending submissions too, not only when fetching. Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,15 @@
|
||||
import io
|
||||
import json
|
||||
import urllib.error
|
||||
from unittest import mock
|
||||
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.tests import TransactionCase
|
||||
|
||||
from odoo.addons.docuseal_signing.models import (
|
||||
docuseal_template as docuseal_template_module,
|
||||
)
|
||||
|
||||
from .common import DocusealApiMockMixin
|
||||
|
||||
|
||||
@@ -131,3 +141,31 @@ class TestCreateSubmissions(DocusealApiMockMixin, TransactionCase):
|
||||
self.requests[0]["url"],
|
||||
"https://sign.example.com/api/submissions",
|
||||
)
|
||||
|
||||
def test_missing_token_raises_user_error(self):
|
||||
"""Without API token, the user is told to configure it instead of
|
||||
getting a technical error."""
|
||||
self._set_api_config()
|
||||
self.env["ir.config_parameter"].sudo().set_param("docuseal.api_token", "")
|
||||
with self._mock_api({"id": 59}), self.assertRaisesRegex(
|
||||
UserError, "API token"
|
||||
):
|
||||
self.template._create_submissions(self.partner)
|
||||
self.assertFalse(self.requests)
|
||||
|
||||
def test_docuseal_error_raises_user_error_with_detail(self):
|
||||
"""A Docuseal rejection is reported with the explanation it sent."""
|
||||
self._set_api_config()
|
||||
error = urllib.error.HTTPError(
|
||||
"https://sign.example.com/api/submissions",
|
||||
422,
|
||||
"Unprocessable Entity",
|
||||
{},
|
||||
io.BytesIO(json.dumps({"error": "Role not found"}).encode()),
|
||||
)
|
||||
with mock.patch.object(
|
||||
docuseal_template_module.urllib.request,
|
||||
"urlopen",
|
||||
side_effect=error,
|
||||
), self.assertRaisesRegex(UserError, "422: Role not found"):
|
||||
self.template._create_submissions(self.partner)
|
||||
|
||||
Reference in New Issue
Block a user