Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
df35686
Manage file added again to same session, data is updated.
gbastien Mar 6, 2026
caf6fcd
Completed test_add_files_already_exist_is_updated to show that filena…
gbastien Mar 6, 2026
66d8df8
Check added to same session
gbastien Mar 6, 2026
795cc16
Completed test_add_files_already_exist_is_updated regarding session s…
gbastien Mar 6, 2026
19e094f
doc
gbastien Mar 6, 2026
e425dcf
Manage size
gbastien Mar 6, 2026
9eefa2e
Added event to make sure session data (size, title, filename) is upda…
gbastien Mar 9, 2026
f9cef7c
Merge remote-tracking branch 'origin/main' into PARAF-359_file_added_…
gbastien Mar 12, 2026
343e978
Session size is now always correct as it is update on add/edit/remove…
gbastien Mar 12, 2026
a0ff5e9
Added collective.iconifiedcategory to auto-checkout
gbastien Mar 12, 2026
ba0f644
Setup coverage
gbastien Mar 12, 2026
7aef366
Removed double imio.annex
gbastien Mar 12, 2026
70620ab
Removed double get_sessions_for
gbastien Mar 12, 2026
84bd591
Install correct requirements-4.3.txt
gbastien Mar 12, 2026
b0d39a6
Run correct cfg file
gbastien Mar 12, 2026
ee3b6c4
Coverage gha
gbastien Mar 13, 2026
006d4cb
Try to fix coveralls
gbastien Mar 13, 2026
fa8e300
Install liblma-dev but not wheel that was already installed by requir…
gbastien Mar 13, 2026
820ea31
Pinned coverage = 5.3.1
gbastien Mar 13, 2026
c753000
Try to force pip3.8
gbastien Mar 13, 2026
01581a4
Py3
gbastien Mar 13, 2026
5e60ef1
Removed ls command
gbastien Mar 13, 2026
385efb9
Show that without adding it again, data is updated during the modifie…
gbastien Mar 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Changelog
[chris-adam]
- Added external watchers for esign sessions.
[chris-adam, sgeulette]
- Manage file added again to same session, data is updated.
[gbastien]

1.0a2 (2026-02-06)
------------------
Expand Down
59 changes: 59 additions & 0 deletions src/imio/esign/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,65 @@ def test_add_files_with_duplicate_filenames(self):
self.assertIn("same_filename-1.pdf", filenames)
self.assertIn("same_filename-2.pdf", filenames)

def test_add_files_already_exist_is_updated(self):
"""When adding a file to the same session, it is updated."""
annot = get_session_annotation()
self.assertEqual(len(annot["sessions"]), 0)

signers = [
("user1", "user1@sign.com", "User 1", "Position 1"),
]

annex0_uid = self.uids[0]
annex0 = api.content.get(UID=annex0_uid)

sid, session = add_files_to_session(signers, (annex0_uid,))
self.assertEqual(sid, 0)
self.assertEqual(len(session["files"]), 1)
self.assertEqual(session["files"][0]["filename"], "annex0.pdf")
self.assertEqual(session["files"][0]["title"], "Annex 0")
self.assertEqual(session["size"], 6968)
# edit annex and add again, still one annex in session and data are updated
annex0.file.filename = u"new_annex0.pdf"
annex0.setTitle('New Annex 0')
sid, session = add_files_to_session(signers, (annex0_uid,))
Copy link
Contributor

Choose a reason for hiding this comment

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

Est-ce qu'il ne faudrait pas tester ici que le filename et le title sont déjà mis à jour dans la session même avant de l'ajouter à nouveau ? Si oui, alors on n'est plus vraiment dans le contexte de test_utils mais plutôt test_events

Copy link
Member Author

Choose a reason for hiding this comment

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

Je vais compléter test_categorized_element_updated_event avec changement file, çà teste que c'est bien màj lors d'un edit, et donc ici c'est la création, on a le postulat que dans ce cas c'est bien à jour, d'ailleurs on le voit dans ce test, sinon on re-teste des choses déjà testées... Il me semble...

Copy link
Member Author

Choose a reason for hiding this comment

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

à voir car création ou ajout même annexe ne passe pas par l'event de modif, c'est juste le add_files_to_session qui gère cela, çà va mettre à jour les infos correctement, le code lié à l'event est ci-dessous dans le "edit file"...
Je vais push un test_categorized_element_updated_event + complet où on teste aussi que les infos filesize sont mises à jour, mais c'est double test pour moi

Copy link
Member Author

Choose a reason for hiding this comment

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

@chris-adam en effet le test a évolué petit à petit, et la partie "add" après le "modify" a été enlevée pour montrer que c'est màj sans re-add, j'avais lu trop vite car ton commentaire était "trop haut" dans le test, ici çà me semble bon comme çà on pourrait merger à mon sens

# same session_id
self.assertEqual(sid, 0)
self.assertEqual(len(session["files"]), 1)
self.assertEqual(session["files"][0]["filename"], "new_annex0.pdf")
self.assertEqual(session["files"][0]["title"], "New Annex 0")
self.assertEqual(session["size"], 6968)
# add again exact same file
sid, session = add_files_to_session(signers, (annex0_uid,))
self.assertEqual(sid, 0)
self.assertEqual(len(session["files"]), 1)
self.assertEqual(session["files"][0]["filename"], "new_annex0.pdf")
self.assertEqual(session["files"][0]["title"], "New Annex 0")
self.assertEqual(session["size"], 6968)
# add second file 2 times
annex1_uid = self.uids[1]
annex1 = api.content.get(UID=annex1_uid)
sid, session = add_files_to_session(signers, (annex1_uid,))
self.assertEqual(sid, 0)
self.assertEqual(len(session["files"]), 2)
self.assertEqual(session["files"][1]["filename"], "annex1.pdf")
self.assertEqual(session["files"][1]["title"], "Annex 1")
self.assertEqual(session["size"], 13982)
# edit and add again
annex1.setTitle('New Annex 1')
# edit file, filename and content so size changed
with open(os.path.join(os.path.dirname(__file__), "annex1.pdf"), "rb") as f:
annex1.file = NamedBlobFile(data=f.read(), filename=u"new_annex1.pdf", contentType="application/pdf")
sid, session = add_files_to_session(signers, (annex1_uid,))
self.assertEqual(sid, 0)
self.assertEqual(len(session["files"]), 2)
self.assertEqual(session["files"][1]["filename"], "new_annex1.pdf")
self.assertEqual(session["files"][1]["title"], "New Annex 1")
self.assertEqual(session["size"], 13936)
# just to check, remove annex1
remove_files_from_session((annex0_uid,))
self.assertEqual(session["size"], 6968)

def test_remove_context_from_session(self):
"""Test removing a context from a session."""
annot = get_session_annotation()
Expand Down
18 changes: 16 additions & 2 deletions src/imio/esign/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@ def add_files_to_session(
annex = uuidToObject(uuid=uid, unrestricted=True)
context_uid_provider = getAdapter(annex, IContextUidProvider)
context_uid = context_uid_provider.get_context_uid()
# update data if adding same file to same session
if annot['uids'].get(uid, -1) == session_id:
logger.info('File with UID %s is already in session_id %s and data were updated!', uid, session_id)
# remove old filename to avoid filename being renamed
old_filename = path.splitext([fn for fn in session["files"]
if fn['uid'] == uid][0]['filename'])[0]
existing_files.remove(old_filename)
# session size will be updated when removing file from session
# so save it because it is already correct
saved_size = session["size"]
remove_files_from_session([uid], remove_empty_session=False)
session["size"] = saved_size

filename, ext = path.splitext(annex.file.filename or "no_filename.pdf")
new_filename = get_correct_id(existing_files, filename)
session["files"].append(
Expand Down Expand Up @@ -353,10 +366,11 @@ def remove_context_from_session(context_uids):
remove_files_from_session(list(c_uids[context_uid]))


def remove_files_from_session(files_uids):
def remove_files_from_session(files_uids, remove_empty_session=True):
"""Remove files from their corresponding sessions.

:param files_uids: list of file UIDs to remove
:param remove_empty_session: when the last file of a session is removed the session will be removed by default, except when False, the empty session is kept
"""
annot = get_session_annotation()
sessions = annot["sessions"]
Expand Down Expand Up @@ -386,7 +400,7 @@ def remove_files_from_session(files_uids):
continue

del session["files"][i]
if not session["files"]:
if not session["files"] and remove_empty_session:
del sessions[session_id]
else:
session["last_update"] = datetime.now()
Expand Down
5 changes: 5 additions & 0 deletions test-4.3.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,8 @@ Pygments = 2.5.2
# beautifulsoup
soupsieve = 1.9.2
backports.functools-lru-cache = 1.5

# Required by:
# mock
mock = 3.0.5
funcsigs = 1.0.2
Loading