Skip to content

PARAF-550: Formalised the sent filename generation in ISignable.get_filename - #49

Merged
chris-adam merged 2 commits into
mainfrom
PARAF-550/signable_adapter_filename
Sep 17, 2026
Merged

chris-adam merged 2 commits into
mainfrom
PARAF-550/signable_adapter_filename

Conversation

@chris-adam

@chris-adam chris-adam commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

PARAF-550

ISignable.get_filename(annex, existing_files) replaces the hardcoded get_correct_id(...) in add_files_to_session, so applications can name the files sent to the signing service. It gets the annex, not just its filename, so the adapter owns the whole name.

The default implementation reproduces the previous behaviour exactly — no existing test assertion needed updating, and imio.dms.mail needs no override.

Also:

  • events.on_categorized_annex_updated now goes through the adapter too. It recomputed the filename with raw get_correct_id, so any rename silently reverted on the next annex edit.
  • The file's own entry is excluded from existing_files, so a deduplicated name no longer drifts -1 → -2 → -3 on repeated modifications.
  • Default SignableAdapter registered for="*" in configure.zcml (was testing.zcml only), otherwise ISignable(obj) raises Could not adapt outside imio.dms.mail.

⚠️ The returned name must keep the __<uid> suffix. The signed file comes back under that name and imio.zamqp.dms/consumer.py:301 parses the uid out of it to find the file to update — no uid, and the PDF is silently discarded. imio.dms.mail still owns the suffix (adapters.py:1954); the constraint is documented in the docstring, not enforced.

⚠️ The events.py changes have no test — verified by mutation that the existing suite stays green if they regress.

Summary by CodeRabbit

  • New Features

    • Added automatic filename generation for files added to signing sessions.
    • Preserves original file extensions and uses a PDF fallback when no filename is available.
    • Prevents filename collisions by adding numbering while preserving unique file identifiers.
  • Bug Fixes

    • Updated filenames remain stable when file metadata changes, while the associated title is refreshed.

@coderabbitai

coderabbitai Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Essentials

Run ID: 6170fd12-d61b-4818-ae10-21097c7471dd

📥 Commits

Reviewing files that changed from the base of the PR and between 5701297 and 0ff899d.

📒 Files selected for processing (1)
  • src/imio/esign/tests/test_events.py

📝 Walkthrough

Walkthrough

The change formalizes annex filename generation through ISignable.get_filename. The adapter preserves extensions, supplies defaults, avoids collisions, and is used by event and session update flows.

Changes

Filename generation

Layer / File(s) Summary
Filename contract and adapter implementation
src/imio/esign/adapters.py, src/imio/esign/tests/test_adapters.py, CHANGES.rst
ISignable.get_filename and SignableAdapter.get_filename now support defaults, extension preservation, unique names, and UID suffixes. Tests cover these cases.
Adapter registration and event assignment
src/imio/esign/configure.zcml, src/imio/esign/testing.zcml, src/imio/esign/events.py
The production adapter is registered globally. The event flow delegates filename generation through the parent annex adapter and excludes the current annex from collision checks.
Session update integration
src/imio/esign/utils.py
add_files_to_session resolves the annex parent and delegates filename generation through ISignable.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant SessionUpdate
  participant AnnexParent
  participant ISignable
  participant SignableAdapter
  SessionUpdate->>AnnexParent: resolve annex parent
  SessionUpdate->>ISignable: obtain parent adapter
  ISignable->>SignableAdapter: generate filename
  SignableAdapter-->>SessionUpdate: return unique filename
Loading

Suggested reviewers: gbastien

Merge Risk: ⚪ Minimal · up to 57012

Filenames remain compatible with the session payload because target identifiers are sent separately. No actionable merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 55.56% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 4 files. (2 skipped: 2… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the formalization of sent filename generation through ISignable.get_filename, which matches the primary change.
Full details: Docstring Coverage

Explanation

Docstring coverage is 55.56% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 4 files. (2 skipped: 2 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch PARAF-550/signable_adapter_filename

Comment @coderabbitai help to get the list of available commands.

@coveralls

coveralls commented Sep 15, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 35195093396

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage decreased (-0.02%) to 86.824%

Details

  • Coverage decreased (-0.02%) from the base build.
  • Patch coverage: 1 uncovered change across 1 file (13 of 14 lines covered, 92.86%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
src/imio/esign/adapters.py 7 6 85.71%
Total (3 files) 14 13 92.86%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 1480
Covered Lines: 1285
Line Coverage: 86.82%
Coverage Strength: 0.87 hits per line

💛 - Coveralls

@chris-adam
chris-adam force-pushed the PARAF-550/signable_adapter_filename branch from 3495acf to 24b0d77 Compare September 15, 2026 13:13
@chris-adam
chris-adam force-pushed the PARAF-550/signable_adapter_filename branch from 24b0d77 to 5701297 Compare September 15, 2026 13:41
@chris-adam
chris-adam marked this pull request as ready for review September 15, 2026 13:41
@chris-adam chris-adam changed the title PARAF-550: Formalise sent filename generation in ISignable.get_filename PARAF-550: Formalised the sent filename generation in ISignable.get_filename Sep 15, 2026
@chris-adam

Copy link
Copy Markdown
Contributor Author

@gbastien J'ai ajouté l'adapter pour facilement renommer les fichiers envoyés au MS. Dans Docs, on ajoute "__" au fichiers convertis dans dmsommainfile.file.filename. Dans imio.zamqp.dms, on récupère le uid pour cibler le bon fichier à remplacer. Est-ce que vous faites ça dans Délib ? Si oui, alors on peut migrer cette logique dans l'adapter. Si non, on peut laisser comme ça.

@chris-adam
chris-adam requested a review from gbastien September 15, 2026 13:54

@gbastien gbastien left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ca me semble OK!
On peut merger comme çà et adapter par la suite si on voit qu'on peut passer un filename + title à part vers Cosi...
Merci pour le boulot!

# a name already used in the session gets a numbered suffix
self.assertEqual(adapter.get_filename(annex, existing_files=["annex0"]), u"annex0-1.pdf")
self.assertEqual(adapter.get_filename(annex, existing_files=["annex0", "annex0-1"]), u"annex0-2.pdf")
# a __<uid> suffix is kept: imio.zamqp parses it back

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ce fonctionnement est propre à dmsmail mais çà pourrait devenir le fonctionnement de base (pas inutile d'avoir l'uid dans le nom du fichier en cas de debug ou autre) mais le problème actuellement c'est que çà apparaît sans doute dans l'interface de Cosi (à vérifier), si il y a la notion de "friendly pdf name" dans Cosi avec possibilité d'afficher un titre qui n'est pas l'id du fichier pdf, çà pourrait rentrer dans le comportement par défaut...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oui, ça s'affiche dans l'interface COSI. Samuel me dit qu'il va chercher comment faire pour avoir ce "friendly pdf name"
image

Comment thread src/imio/esign/events.py
filename, ext = path.splitext(annex.file.filename)
new_filename = get_correct_id(existing_files, filename)
file_data["filename"] = new_filename + ext
existing_files = [

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ici le if f["uid"] != annex_uid peut être utile si le nom précédent correspond au nouveau nom généré par get_correct_id, donc bien vu, mais on pourrait même ajouter un test :-)

@chris-adam
chris-adam merged commit 43fec4e into main Sep 17, 2026
4 of 5 checks passed
@chris-adam
chris-adam deleted the PARAF-550/signable_adapter_filename branch September 17, 2026 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants