-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.py
More file actions
111 lines (87 loc) · 3.39 KB
/
settings.py
File metadata and controls
111 lines (87 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# -*- coding: utf-8 -*-
from imio.esign import _
from plone import api
from plone.app.registry.browser.controlpanel import ControlPanelFormWrapper
from plone.app.registry.browser.controlpanel import RegistryEditForm
from plone.z3cform import layout
from string import Formatter
from zope import schema
from zope.interface import Interface
from zope.interface import Invalid
def validate_vat_number(va_nb):
"""Validate the VAT number format. It should start with BE followed by 10 digits,
with the last 2 digits being a control checksum of the first 8 digits."""
if not va_nb:
return True
# Check format: BE followed by 10 digits
if not va_nb.startswith('BE'):
raise Invalid(_("VAT number must start with 'BE'"))
if len(va_nb) != 12:
raise Invalid(_("VAT number must be 12 characters (BE + 10 digits)"))
digits = va_nb[2:]
if not digits.isdigit():
raise Invalid(_("VAT number must contain 10 digits after 'BE'"))
# Validate checksum: last 2 digits should be 97 - (first 8 digits modulo 97)
first_eight = int(digits[:8])
control = int(digits[8:10])
expected_control = 97 - (first_eight % 97)
if control != expected_control:
raise Invalid(_("Invalid VAT number: checksum verification failed"))
return True
def validate_signing_users_email_content(value):
"""Allow only known placeholders in the email template."""
allowed = {"fullname", "firstname", "lastname", "email", "userid"}
for _ignored1, field, _ignored2, _ignored3 in Formatter().parse(value or ""):
if field and field not in allowed:
raise Invalid(
_("Unknown placeholder: ${field}", mapping={"field": field})
)
return True
class IImioEsignSettings(Interface):
enabled = schema.Bool(
title=_("Enabled?"),
description=_("Is the eSign service enabled?"),
default=True,
)
vat_number = schema.TextLine(
title=_("VAT number"),
description=_("VAT number used for esign billing (BE0123456789)."),
constraint=validate_vat_number,
required=True,
)
file_url = schema.URI(
title=_("File URL download domain"),
description=_("URL domain where the file can be donwloaded."),
required=False,
)
seal_code = schema.TextLine(
title=_("Seal code"),
description=_("Seal code given by eidas provider."),
required=False,
)
seal_email = schema.TextLine(
title=_("Seal email"),
description=_("Email of the eidas provider account containing the seal image."),
required=False,
)
sign_code = schema.TextLine(
title=_("Sign code"),
description=_("Sign code used to specify sign method. Keep empty to use default method."),
required=False,
)
signing_users_email_content = schema.Text(
title=_("Email content for signing users"),
description=_(
"Email content sent to users when inviting them to Parapheo. "
"Use {fullname}, {firstname}, {lastname}, {email}, {userid} as placeholders."
),
required=False,
constraint=validate_signing_users_email_content,
)
class ImioEsignSettings(RegistryEditForm):
schema = IImioEsignSettings
schema_prefix = "imio.esign"
label = _("Imio Esign Settings")
ImioEsignSettingsView = layout.wrap_form(
ImioEsignSettings, ControlPanelFormWrapper
)