🐛(backend) route share invitation link to file view for files

Clicking the invitation link for a shared file opened the folder
explorer page with an empty children listing, because
`Item.send_email` hardcoded `/explorer/items/<uuid>/` regardless of
the item type.

Branch on `item.type` to use the dedicated file route
`/explorer/items/files/<uuid>/` already served by nginx and used by
the in-app share-link copy button.
This commit is contained in:
Nathan Panchout
2026-04-13 13:34:22 +02:00
parent 77a67db6d8
commit af8ba1031f
3 changed files with 39 additions and 3 deletions

View File

@@ -24,6 +24,7 @@ and this project adheres to
- 🐛(front) set size and variant on trash navigate modal #666
- 🐛(frontend) fix uploads continuing after parent folder deletion
- 🐛(frontend) fix SDK picker link reach promotion
- 🐛(backend) route share invitation link to file view for files
### Fixed

View File

@@ -922,7 +922,11 @@ class Item(TreeModel, BaseModel):
"brandname": settings.EMAIL_BRAND_NAME,
"item": self,
"domain": domain,
"link": f"{domain}/explorer/items/{self.id}/",
"link": (
f"{domain}/explorer/items/files/{self.id}/"
if self.type == ItemTypeChoices.FILE
else f"{domain}/explorer/items/{self.id}/"
),
"logo_img": settings.EMAIL_LOGO_IMG,
}
)

View File

@@ -759,7 +759,7 @@ def test_models_items__email_invitation__success():
"""
The email invitation is sent successfully.
"""
item = factories.ItemFactory()
item = factories.ItemFactory(type=models.ItemTypeChoices.FOLDER)
# pylint: disable-next=no-member
assert len(mail.outbox) == 0
@@ -787,7 +787,7 @@ def test_models_items__email_invitation__success_fr():
"""
The email invitation is sent successfully in french.
"""
item = factories.ItemFactory()
item = factories.ItemFactory(type=models.ItemTypeChoices.FOLDER)
# pylint: disable-next=no-member
assert len(mail.outbox) == 0
@@ -816,6 +816,37 @@ def test_models_items__email_invitation__success_fr():
assert f"items/{item.id}/" in email_content
def test_models_items__email_invitation__link_for_folder():
"""
The invitation email link for a folder item points to the folder explorer route.
"""
item = factories.ItemFactory(type=models.ItemTypeChoices.FOLDER)
sender = factories.UserFactory()
item.send_invitation_email("guest-folder@example.com", models.RoleChoices.EDITOR, sender, "en")
# pylint: disable-next=no-member
email = mail.outbox[-1]
assert f"/explorer/items/{item.id}/" in email.body
assert f"/explorer/items/files/{item.id}/" not in email.body
def test_models_items__email_invitation__link_for_file():
"""
The invitation email link for a file item points to the dedicated file route,
so the recipient opens the file preview rather than an empty folder view.
"""
item = factories.ItemFactory(type=models.ItemTypeChoices.FILE, filename="doc.pdf")
sender = factories.UserFactory()
item.send_invitation_email("guest-file@example.com", models.RoleChoices.EDITOR, sender, "en")
# pylint: disable-next=no-member
email = mail.outbox[-1]
assert f"/explorer/items/files/{item.id}/" in email.body
assert f"/explorer/items/{item.id}/" not in email.body
@mock.patch(
"core.models.send_mail",
side_effect=smtplib.SMTPException("Error SMTPException"),