-
-
Notifications
You must be signed in to change notification settings - Fork 4
feat: Docuseal member agreement webhook #69
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8939631
feat: add Docuseal webhook endpoint for member agreement (#48)
kanbei65 c722156
test: add docuseal webhook coverage
michaelmwu 16d9b2a
fix: sanitize and align docuseal webhook identifiers
michaelmwu 9966025
feat: ignore docuseal webhooks when template filter unset
michaelmwu 0dc58c7
docs: clarify DOCUSEAL template id optional behavior
michaelmwu a41457e
Improve Docuseal webhook handling and masking
michaelmwu 269b277
chore: stop writing redundant cSignedMemberAgreement flag
michaelmwu 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,98 @@ | ||
| """Docuseal member agreement processing workflow.""" | ||
|
|
||
| import logging | ||
| from typing import Any | ||
|
|
||
| from five08.clients.espo import EspoAPI, EspoAPIError | ||
| from five08.worker.config import settings | ||
| from five08.worker.masking import mask_email | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class DocusealAgreementProcessor: | ||
| """Look up a CRM contact by email and mark their member agreement as signed.""" | ||
|
|
||
| def __init__(self) -> None: | ||
| api_url = settings.espo_base_url.rstrip("/") + "/api/v1" | ||
| self.api = EspoAPI(api_url, settings.espo_api_key) | ||
|
|
||
| def process_agreement( | ||
| self, | ||
| email: str, | ||
| completed_at: str, | ||
| submission_id: int, | ||
| ) -> dict[str, Any]: | ||
| """Search for the signer by email and update cMemberAgreementSignedAt.""" | ||
| masked_email = mask_email(email) | ||
|
|
||
| try: | ||
| result = self.api.request( | ||
| "GET", | ||
| "Contact", | ||
| { | ||
| "where": [ | ||
| { | ||
| "type": "equals", | ||
| "attribute": "emailAddress", | ||
| "value": email, | ||
| } | ||
| ], | ||
| "maxSize": 1, | ||
| "select": "id,name,emailAddress", | ||
| }, | ||
| ) | ||
| except EspoAPIError as exc: | ||
| logger.error("CRM search failed for masked_email=%s: %s", masked_email, exc) | ||
| return { | ||
| "success": False, | ||
| "masked_email": masked_email, | ||
| "error": f"CRM search failed: {exc}", | ||
| } | ||
|
|
||
| contacts = result.get("list", []) | ||
| if not contacts: | ||
| logger.warning( | ||
| "No CRM contact found for masked_email=%s submission_id=%s", | ||
| masked_email, | ||
| submission_id, | ||
| ) | ||
| return { | ||
| "success": False, | ||
| "masked_email": masked_email, | ||
| "error": "contact_not_found", | ||
| } | ||
|
|
||
| contact = contacts[0] | ||
| contact_id = contact["id"] | ||
|
|
||
| try: | ||
| self.api.request( | ||
| "PUT", | ||
| f"Contact/{contact_id}", | ||
| { | ||
| "cMemberAgreementSignedAt": completed_at, | ||
| }, | ||
| ) | ||
| except EspoAPIError as exc: | ||
| logger.error("CRM update failed for contact_id=%s: %s", contact_id, exc) | ||
| return { | ||
| "success": False, | ||
| "masked_email": masked_email, | ||
| "submission_id": submission_id, | ||
| "contact_id": contact_id, | ||
| "error": f"CRM update failed: {exc}", | ||
| } | ||
|
|
||
| logger.info( | ||
| "Marked member agreement signed contact_id=%s masked_email=%s", | ||
| contact_id, | ||
| masked_email, | ||
| ) | ||
| return { | ||
| "success": True, | ||
| "masked_email": masked_email, | ||
| "contact_id": contact_id, | ||
| "submission_id": submission_id, | ||
| "completed_at": completed_at, | ||
| } |
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,15 @@ | ||
| """PII masking helpers used across worker modules.""" | ||
|
|
||
|
|
||
| def mask_email(email: str) -> str: | ||
| """Return a deterministic redacted email representation for logs and responses.""" | ||
| local, at, domain = email.partition("@") | ||
| if not at: | ||
| return "***" | ||
|
|
||
| masked_local = (local[:1] if local else "*") + "***" | ||
|
|
||
| if not domain: | ||
| return f"{masked_local}@****..." | ||
|
|
||
| return f"{masked_local}@{domain[:1]}****..." | ||
|
Comment on lines
+10
to
+15
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. Use hash-based masking instead of partial-character exposure. This currently reveals email initials ( 🔧 Proposed fix+import hashlib
+
def mask_email(email: str) -> str:
- """Return a deterministic redacted email representation for logs and responses."""
- local, at, domain = email.partition("@")
- if not at:
- return "***"
-
- masked_local = (local[:1] if local else "*") + "***"
-
- if not domain:
- return f"{masked_local}@****..."
-
- return f"{masked_local}@{domain[:1]}****..."
+ """Return deterministic non-reversible email token for logs/responses."""
+ normalized = email.strip().lower()
+ if "@" not in normalized:
+ return "email#invalid"
+ digest = hashlib.sha256(normalized.encode("utf-8")).hexdigest()[:12]
+ return f"email#{digest}"🤖 Prompt for AI Agents |
||
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.
Uh oh!
There was an error while loading. Please reload this page.