Skip to content

Commit 709c88c

Browse files
authored
Project: force PR previews to match repo only if the repo is public (#11184)
* Project: force PR previews to match repo only if the repo is public * Fix test * Lint
1 parent b49ffc9 commit 709c88c

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

docs/user/guides/pull-requests.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ Privacy levels
2626

2727
Privacy levels are only supported on :doc:`/commercial/index`.
2828

29-
If you didn’t import your project manually, the privacy level of pull request previews will match your repository,
29+
If you didn’t import your project manually and your repository is public,
30+
the privacy level of pull request previews will be set to *Public*,
3031
otherwise it will be set to *Private*.
3132
Public pull request previews are available to anyone with the link to the preview,
3233
while private previews are only available to users with access to the Read the Docs project.

docs/user/pull-requests.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ if you have environment variables with private information, make sure they aren'
4848
See :ref:`environment-variables:Environment variables and build process` for more information.
4949

5050
On |com_brand| you can set pull request previews to be private or public,
51-
if you didn't import your project manually, the privacy level of pull request previews will match your repository.
51+
If you didn’t import your project manually and your repository is public,
52+
the privacy level of pull request previews will be set to *Public*.
5253
Public pull request previews are available to anyone with the link to the preview,
5354
while private previews are only available to users with access to the Read the Docs project.
5455

readthedocs/projects/forms.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -384,16 +384,15 @@ def __init__(self, *args, **kwargs):
384384

385385
def setup_external_builds_option(self):
386386
"""Disable the external builds option if the project doesn't meet the requirements."""
387-
if settings.ALLOW_PRIVATE_REPOS and self.instance.remote_repository:
387+
if (
388+
settings.ALLOW_PRIVATE_REPOS
389+
and self.instance.remote_repository
390+
and not self.instance.remote_repository.private
391+
):
388392
self.fields["external_builds_privacy_level"].disabled = True
389-
if self.instance.remote_repository.private:
390-
help_text = _(
391-
"We have detected that this project is private, pull request previews are set to private."
392-
)
393-
else:
394-
help_text = _(
395-
"We have detected that this project is public, pull request previews are set to public."
396-
)
393+
help_text = _(
394+
"We have detected that this project is public, pull request previews are set to public."
395+
)
397396
self.fields["external_builds_privacy_level"].help_text = help_text
398397

399398
integrations = list(self.instance.integrations.all())

readthedocs/projects/models.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
MEDIA_TYPES,
6666
MULTIPLE_VERSIONS_WITH_TRANSLATIONS,
6767
MULTIPLE_VERSIONS_WITHOUT_TRANSLATIONS,
68-
PRIVATE,
6968
PUBLIC,
7069
)
7170

@@ -583,9 +582,11 @@ def save(self, *args, **kwargs):
583582
_("Model must have slug")
584583
)
585584

586-
if self.remote_repository:
587-
privacy_level = PRIVATE if self.remote_repository.private else PUBLIC
588-
self.external_builds_privacy_level = privacy_level
585+
# If the project is linked to a remote repository,
586+
# and the repository is public, we force the privacy level of
587+
# pull requests previews to be public, see GHSA-pw32-ffxw-68rh.
588+
if self.remote_repository and not self.remote_repository.private:
589+
self.external_builds_privacy_level = PUBLIC
589590

590591
super().save(*args, **kwargs)
591592

readthedocs/projects/tests/test_views.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from readthedocs.projects.constants import (
1212
DOWNLOADABLE_MEDIA_TYPES,
1313
MEDIA_TYPE_HTMLZIP,
14-
PRIVATE,
1514
PUBLIC,
1615
)
1716
from readthedocs.projects.models import Project
@@ -111,7 +110,7 @@ def test_gitlab_integration(self):
111110
)
112111

113112
@override_settings(ALLOW_PRIVATE_REPOS=True)
114-
def test_privacy_level_pr_previews_match_remote_repository(self):
113+
def test_privacy_level_pr_previews_match_remote_repository_if_public(self):
115114
remote_repository = get(RemoteRepository, private=False)
116115
self.project.remote_repository = remote_repository
117116
self.project.save()
@@ -128,9 +127,8 @@ def test_privacy_level_pr_previews_match_remote_repository(self):
128127

129128
resp = self.client.get(self.url)
130129
field = resp.context["form"].fields["external_builds_privacy_level"]
131-
self.assertTrue(field.disabled)
132-
self.assertIn("We have detected that this project is private", field.help_text)
133-
self.assertEqual(self.project.external_builds_privacy_level, PRIVATE)
130+
self.assertFalse(field.disabled)
131+
self.assertEqual(self.project.external_builds_privacy_level, PUBLIC)
134132

135133

136134
@override_settings(RTD_ALLOW_ORGANIZATIONS=True)

0 commit comments

Comments
 (0)