diff --git a/src/backend/core/models.py b/src/backend/core/models.py index 9c855a2b..d941992a 100644 --- a/src/backend/core/models.py +++ b/src/backend/core/models.py @@ -115,16 +115,16 @@ class LinkReachChoices(models.TextChoices): if LinkRoleChoices.EDITOR in reach_roles.get(cls.PUBLIC, set()): return {cls.PUBLIC: [LinkRoleChoices.EDITOR]} - # Rule 2: public/reader - if LinkRoleChoices.READER in reach_roles.get(cls.PUBLIC, set()): - result.get(cls.AUTHENTICATED, set()).discard(LinkRoleChoices.READER) - result.pop(cls.RESTRICTED, None) - - # Rule 3: authenticated/editor + # Rule 2: authenticated/editor if LinkRoleChoices.EDITOR in reach_roles.get(cls.AUTHENTICATED, set()): result[cls.AUTHENTICATED].discard(LinkRoleChoices.READER) result.pop(cls.RESTRICTED, None) + # Rule 3: public/reader + if LinkRoleChoices.READER in reach_roles.get(cls.PUBLIC, set()): + result.pop(cls.AUTHENTICATED, None) + result.pop(cls.RESTRICTED, None) + # Rule 4: authenticated/reader if LinkRoleChoices.READER in reach_roles.get(cls.AUTHENTICATED, set()): result.pop(cls.RESTRICTED, None) diff --git a/src/backend/core/tests/test_models_documents.py b/src/backend/core/tests/test_models_documents.py index bbadbe95..90821536 100644 --- a/src/backend/core/tests/test_models_documents.py +++ b/src/backend/core/tests/test_models_documents.py @@ -1182,7 +1182,6 @@ def test_models_documents_restore_complex_bis(django_assert_num_queries): ( [{"link_reach": "public", "link_role": "reader"}], { - "authenticated": ["editor"], "public": ["reader", "editor"], }, ), @@ -1247,7 +1246,6 @@ def test_models_documents_restore_complex_bis(django_assert_num_queries): {"link_reach": "public", "link_role": "reader"}, ], { - "authenticated": ["editor"], "public": ["reader", "editor"], }, ), @@ -1258,7 +1256,6 @@ def test_models_documents_restore_complex_bis(django_assert_num_queries): {"link_reach": "public", "link_role": "reader"}, ], { - "authenticated": ["editor"], "public": ["reader", "editor"], }, ), @@ -1268,7 +1265,7 @@ def test_models_documents_restore_complex_bis(django_assert_num_queries): {"link_reach": "authenticated", "link_role": "editor"}, {"link_reach": "public", "link_role": "reader"}, ], - {"authenticated": ["editor"], "public": ["reader", "editor"]}, + {"public": ["reader", "editor"]}, ), ( [