-
Notifications
You must be signed in to change notification settings - Fork 0
Added action to create a custom session + action to add a item to a specific session #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
chris-adam
wants to merge
3
commits into
main
Choose a base branch
from
PARAF-370/create-custom-session
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| # -*- coding: utf-8 -*- | ||
| from imio.esign import _ | ||
| from imio.esign.config import get_esign_registry_seal_code | ||
| from imio.esign.utils import create_session | ||
| from imio.helpers.content import uuidToObject | ||
| from plone import api | ||
| from plone.autoform import directives | ||
| from plone.autoform.form import AutoExtensibleForm | ||
| from plone.z3cform.layout import wrap_form | ||
| from z3c.form import button | ||
| from z3c.form import form | ||
| from z3c.form.browser.checkbox import CheckBoxFieldWidget | ||
| from zope import schema | ||
| from zope.component import queryUtility | ||
| from zope.interface import implementer | ||
| from zope.interface import Interface | ||
| from zope.schema.interfaces import IContextSourceBinder | ||
| from zope.schema.interfaces import IVocabularyFactory | ||
| from zope.schema.vocabulary import SimpleVocabulary | ||
|
|
||
|
|
||
| @implementer(IContextSourceBinder) | ||
| class SignersSourceBinder(object): | ||
| """Source binder that delegates to the named vocabulary.""" | ||
|
|
||
| def __call__(self, context): | ||
| factory = queryUtility( | ||
| IVocabularyFactory, name=u"imio.esign.ActiveSignersVocabulary" | ||
| ) | ||
| if factory is not None: | ||
| return factory(context) | ||
| return SimpleVocabulary([]) | ||
|
|
||
|
|
||
| class ICreateCustomSession(Interface): | ||
|
|
||
| title = schema.TextLine( | ||
| title=_(u"Session title"), | ||
| required=False, | ||
| ) | ||
|
|
||
| signers = schema.Set( | ||
| title=_(u"Signers"), | ||
| required=True, | ||
| value_type=schema.Choice( | ||
| source=SignersSourceBinder(), | ||
| ), | ||
| ) | ||
| directives.widget("signers", CheckBoxFieldWidget) | ||
|
|
||
| seal = schema.Bool( | ||
| title=_(u"Seal"), | ||
| required=False, | ||
| default=False, | ||
| ) | ||
|
|
||
|
|
||
| class CreateCustomSessionForm(AutoExtensibleForm, form.Form): | ||
|
|
||
| schema = ICreateCustomSession | ||
| ignoreContext = True | ||
| label = _(u"Create custom session") | ||
| css_class = u"create-custom-session" | ||
|
|
||
| def get_default_seal(self): | ||
| """Return the default value for the seal field. | ||
| Override in a subclass to change the default. | ||
| """ | ||
| return False | ||
|
|
||
| def get_default_title(self): | ||
| """Return the default value for the title field. | ||
| Override in a subclass to change the default. | ||
| """ | ||
| return _(u"Custom session") | ||
|
|
||
| def extract_signer_info(self, value): | ||
| """Extract signer info from a held_position UID. | ||
|
|
||
| Returns a (userid, email, fullname, position) tuple, or None | ||
| if the held_position does not exist or has no linked user. | ||
| """ | ||
| hp = uuidToObject(value, unrestricted=True) | ||
| if hp is None: | ||
| return None | ||
| person = hp.get_person() | ||
| if person is None or not person.userid: | ||
| return None | ||
| user = api.user.get(userid=person.userid) | ||
| if user is None: | ||
| return None | ||
| email = user.getProperty("email", "") | ||
| fullname = person.get_title(include_person_title=False) | ||
| position = hp.get_full_title(first_index=1) | ||
| return (person.userid, email, fullname, position) | ||
|
Comment on lines
+92
to
+95
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a defensive empty-email guard in signer extraction. On Line 92, 💡 Proposed fix- email = user.getProperty("email", "")
+ email = (user.getProperty("email", u"") or u"").strip()
+ if not email:
+ return None
fullname = person.get_title(include_person_title=False)
position = hp.get_full_title(first_index=1)
return (person.userid, email, fullname, position)🤖 Prompt for AI Agents |
||
|
|
||
| def updateFields(self): | ||
| super(CreateCustomSessionForm, self).updateFields() | ||
| if not get_esign_registry_seal_code(): | ||
| self.fields = self.fields.omit("seal") | ||
|
|
||
| def updateWidgets(self): | ||
| super(CreateCustomSessionForm, self).updateWidgets() | ||
| if not self.widgets["title"].value: | ||
| self.widgets["title"].value = self.get_default_title() | ||
| if "seal" in self.widgets: | ||
| if self.get_default_seal(): | ||
|
chris-adam marked this conversation as resolved.
|
||
| self.widgets["seal"].value = ("selected",) | ||
|
|
||
| @button.buttonAndHandler(_(u"Create"), name="create") | ||
| def handleCreate(self, action): | ||
| data, errors = self.extractData() | ||
| if errors: | ||
| return | ||
|
|
||
| signers = [] | ||
| for value in data.get("signers", []): | ||
| info = self.extract_signer_info(value) | ||
| if info is not None: | ||
| signers.append(info) | ||
|
|
||
| if not signers: | ||
| api.portal.show_message( | ||
| _(u"No valid signers selected!"), | ||
| request=self.request, | ||
| type="warning", | ||
| ) | ||
| return | ||
|
|
||
| seal = data.get("seal", False) | ||
| title = data.get("title") or u"" | ||
|
|
||
| create_session(signers=signers, seal=seal, title=title) | ||
|
|
||
| api.portal.show_message( | ||
| _(u"Custom session created successfully!"), | ||
| request=self.request, | ||
| type="info", | ||
| ) | ||
| self.request.RESPONSE.redirect( | ||
| api.portal.get().absolute_url() + "/@@parapheo" | ||
| ) | ||
|
|
||
| @button.buttonAndHandler(_(u"Cancel"), name="cancel") | ||
| def handleCancel(self, action): | ||
| self.request.RESPONSE.redirect( | ||
| api.portal.get().absolute_url() + "/@@parapheo" | ||
| ) | ||
|
|
||
|
|
||
| CreateCustomSessionFormView = wrap_form(CreateCustomSessionForm) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* Add-to-custom-esign-session overlay table */ | ||
| #add-to-custom-esign-session-form .sessions-table { | ||
| table-layout: fixed; | ||
| width: 100%; | ||
| overflow-wrap: break-word; | ||
| } | ||
|
|
||
| #add-to-custom-esign-session-form .th_header_sessions_radio { width: 4%; } | ||
| #add-to-custom-esign-session-form .th_header_sessions_id { width: 6%; } | ||
| #add-to-custom-esign-session-form .th_header_sessions_title { width: 25%; } | ||
| #add-to-custom-esign-session-form .th_header_sessions_signers { width: 30%; } | ||
| #add-to-custom-esign-session-form .th_header_sessions_seal { width: 7%; } | ||
| #add-to-custom-esign-session-form .th_header_sessions_documents { width: 28%; } | ||
|
|
||
| #add-to-custom-esign-session-form .signers-column ol { | ||
| margin: 0; | ||
| padding-left: 1.2em; | ||
| } | ||
|
|
||
| #add-to-custom-esign-session-form .documents-column .collapsible { | ||
| white-space: normal; | ||
| } | ||
|
|
||
| /* Create-custom-session form */ | ||
| .create-custom-session .fieldset-level-1 { | ||
| margin-bottom: 0; | ||
| } | ||
|
|
||
| .create-custom-session #formfield-form-widgets-signers { | ||
| max-height: 300px; | ||
| overflow-y: auto; | ||
| padding: 8px; | ||
| border: 1px solid #ddd; | ||
| border-radius: 4px; | ||
| margin-bottom: 1.5em; | ||
| } | ||
|
|
||
| .create-custom-session #formfield-form-widgets-seal { | ||
| padding-top: 1em; | ||
| border-top: 1px solid #ccc; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A voir si on veut mettre un titre par défaut particulier