|
11 | 11 | from kitsune.dashboards.models import WikiDocumentVisits
|
12 | 12 | from kitsune.products.tests import ProductFactory, TopicFactory
|
13 | 13 | from kitsune.sumo.tests import TestCase
|
14 |
| -from kitsune.users.tests import UserFactory |
| 14 | +from kitsune.users.tests import GroupFactory, UserFactory |
15 | 15 | from kitsune.wiki.tests import (
|
16 | 16 | ApprovedRevisionFactory,
|
17 | 17 | DocumentFactory,
|
@@ -852,3 +852,132 @@ def test_unapproved_revision(self):
|
852 | 852 | creator = unapproved_doc.revisions.first().creator
|
853 | 853 | doc = get_visible_document_or_404(creator, locale="en-US", slug="unapproved")
|
854 | 854 | self.assertEqual(doc, unapproved_doc)
|
| 855 | + |
| 856 | + def test_cross_locale_lookup_with_restricted_visibility(self): |
| 857 | + g1 = GroupFactory(name="group1") |
| 858 | + |
| 859 | + g1_user = UserFactory(groups=[g1]) |
| 860 | + |
| 861 | + en_doc = ApprovedRevisionFactory( |
| 862 | + document__locale="en-US", |
| 863 | + document__slug="restricted-test-document", |
| 864 | + document__restrict_to_groups=[g1], |
| 865 | + document__allow_discussion=False, |
| 866 | + is_ready_for_localization=True, |
| 867 | + ).document |
| 868 | + |
| 869 | + de_doc = TranslatedRevisionFactory( |
| 870 | + document__locale="de", |
| 871 | + document__slug="restricted-test-document-de", |
| 872 | + document__allow_discussion=False, |
| 873 | + document__parent=en_doc, |
| 874 | + based_on=en_doc.current_revision, |
| 875 | + ).document |
| 876 | + |
| 877 | + fr_doc = TranslatedRevisionFactory( |
| 878 | + document__locale="fr", |
| 879 | + document__slug="restricted-test-document-fr", |
| 880 | + document__allow_discussion=False, |
| 881 | + document__parent=en_doc, |
| 882 | + based_on=en_doc.current_revision, |
| 883 | + ).document |
| 884 | + |
| 885 | + with self.assertRaises(Http404): |
| 886 | + get_visible_document_or_404( |
| 887 | + self.user, |
| 888 | + locale="en-US", |
| 889 | + slug="restricted-test-document-de", |
| 890 | + look_for_translation_via_parent=True, |
| 891 | + ) |
| 892 | + |
| 893 | + with self.assertRaises(Http404): |
| 894 | + get_visible_document_or_404( |
| 895 | + self.user, |
| 896 | + locale="en-US", |
| 897 | + slug="restricted-test-document-fr", |
| 898 | + look_for_translation_via_parent=True, |
| 899 | + ) |
| 900 | + |
| 901 | + with self.assertRaises(Http404): |
| 902 | + get_visible_document_or_404( |
| 903 | + self.user, |
| 904 | + locale="de", |
| 905 | + slug="restricted-test-document", |
| 906 | + look_for_translation_via_parent=True, |
| 907 | + ) |
| 908 | + |
| 909 | + with self.assertRaises(Http404): |
| 910 | + get_visible_document_or_404( |
| 911 | + self.user, |
| 912 | + locale="de", |
| 913 | + slug="restricted-test-document-fr", |
| 914 | + look_for_translation_via_parent=True, |
| 915 | + ) |
| 916 | + |
| 917 | + doc = get_visible_document_or_404( |
| 918 | + g1_user, |
| 919 | + locale="en-US", |
| 920 | + slug="restricted-test-document-de", |
| 921 | + look_for_translation_via_parent=True, |
| 922 | + ) |
| 923 | + self.assertEqual(doc, en_doc) |
| 924 | + |
| 925 | + doc = get_visible_document_or_404( |
| 926 | + g1_user, |
| 927 | + locale="en-US", |
| 928 | + slug="restricted-test-document-fr", |
| 929 | + look_for_translation_via_parent=True, |
| 930 | + ) |
| 931 | + self.assertEqual(doc, en_doc) |
| 932 | + |
| 933 | + doc = get_visible_document_or_404( |
| 934 | + g1_user, |
| 935 | + locale="de", |
| 936 | + slug="restricted-test-document", |
| 937 | + look_for_translation_via_parent=True, |
| 938 | + ) |
| 939 | + self.assertEqual(doc, de_doc) |
| 940 | + |
| 941 | + doc = get_visible_document_or_404( |
| 942 | + g1_user, |
| 943 | + locale="de", |
| 944 | + slug="restricted-test-document-fr", |
| 945 | + look_for_translation_via_parent=True, |
| 946 | + ) |
| 947 | + self.assertEqual(doc, de_doc) |
| 948 | + |
| 949 | + doc = get_visible_document_or_404( |
| 950 | + g1_user, |
| 951 | + locale="fr", |
| 952 | + slug="restricted-test-document-de", |
| 953 | + look_for_translation_via_parent=True, |
| 954 | + ) |
| 955 | + self.assertEqual(doc, fr_doc) |
| 956 | + |
| 957 | + # All of the kwargs should be respected. |
| 958 | + with self.assertRaises(Http404): |
| 959 | + get_visible_document_or_404( |
| 960 | + g1_user, |
| 961 | + locale="en-US", |
| 962 | + slug="restricted-test-document-de", |
| 963 | + allow_discussion=True, |
| 964 | + look_for_translation_via_parent=True, |
| 965 | + ) |
| 966 | + |
| 967 | + with self.assertRaises(Http404): |
| 968 | + get_visible_document_or_404( |
| 969 | + g1_user, |
| 970 | + locale="de", |
| 971 | + slug="restricted-test-document", |
| 972 | + allow_discussion=True, |
| 973 | + look_for_translation_via_parent=True, |
| 974 | + ) |
| 975 | + |
| 976 | + with self.assertRaises(Http404): |
| 977 | + get_visible_document_or_404( |
| 978 | + g1_user, |
| 979 | + locale="de", |
| 980 | + slug="restricted-test-document-fr", |
| 981 | + allow_discussion=True, |
| 982 | + look_for_translation_via_parent=True, |
| 983 | + ) |
0 commit comments