Skip to content

Commit ea53b21

Browse files
committed
🐛(backend) use computed_link_reach in handle_onboarding_document
In the model method User::_handle_onboarding_documents_access we do not allow using documents with restricted link_reach to be added as onboarding documents. To check the real link_reach of the document, we must use instead the computed_link_reach to be sure that a sub document can also be used and compute its correct link_reach.
1 parent 0bfc697 commit ea53b21

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to
1414
### Fixed
1515

1616
- 🐛(docs) run migration 0027 without superuser role
17+
- 🐛(backend) use computed_link_reach in handle_onboarding_document
1718

1819

1920
## [v5.1.0] - 2026-05-11

src/backend/core/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def _handle_onboarding_documents_access(self):
244244
)
245245
continue
246246

247-
if document.link_reach == LinkReachChoices.RESTRICTED:
247+
if document.computed_link_reach == LinkReachChoices.RESTRICTED:
248248
logger.warning(
249249
"Onboarding on a restricted document is not allowed. Must be public or "
250250
"connected. Restricted document: %s",

src/backend/core/tests/test_models_users.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,25 @@ def test_models_users_handle_onboarding_documents_on_restricted_document_is_not_
195195
assert not models.LinkTrace.objects.filter(user=user, document=document).exists()
196196

197197

198+
def test_models_users_handle_onboarding_documents_computed_link_reach_not_restricted():
199+
"""Test that the computed_link_reach is used to check the real link_reach is used."""
200+
201+
parent = factories.DocumentFactory(link_reach=models.LinkReachChoices.PUBLIC)
202+
document = factories.DocumentFactory(
203+
parent=parent, link_reach=models.LinkReachChoices.RESTRICTED
204+
)
205+
206+
assert document.computed_link_reach == models.LinkReachChoices.PUBLIC
207+
208+
with override_settings(USER_ONBOARDING_DOCUMENTS=[str(document.id)]):
209+
user = factories.UserFactory()
210+
211+
assert models.LinkTrace.objects.filter(user=user, document=document).exists()
212+
user_favorites = models.DocumentFavorite.objects.filter(user=user)
213+
assert user_favorites.count() == 1
214+
assert user_favorites.filter(document=document).exists()
215+
216+
198217
@override_settings(USER_ONBOARDING_SANDBOX_DOCUMENT=None)
199218
def test_models_users_duplicate_onboarding_sandbox_document_no_setting():
200219
"""

0 commit comments

Comments
 (0)