Skip to content

Commit bef3f8b

Browse files
committed
Allow to change the privacy level of external versions
Only the field is added here, the auth check is done in .com.
1 parent 9943148 commit bef3f8b

File tree

5 files changed

+52
-6
lines changed

5 files changed

+52
-6
lines changed

readthedocs/core/mixins.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Common mixin classes for views."""
22

3+
from copy import copy
4+
35
from django.contrib.auth.mixins import LoginRequiredMixin
46
from django.utils.translation import ugettext_lazy as _
57
from vanilla import ListView
@@ -39,7 +41,11 @@ class HideProtectedLevelMixin:
3941
def __init__(self, *args, **kwargs):
4042
super().__init__(*args, **kwargs)
4143

44+
privacy_level = list(PRIVACY_CHOICES)
45+
privacy_level.remove((PROTECTED, _('Protected')))
46+
4247
if self.instance is None or self.instance.privacy_level != PROTECTED:
43-
privacy_level = list(PRIVACY_CHOICES)
44-
privacy_level.remove((PROTECTED, _('Protected')))
4548
self.fields['privacy_level'].choices = privacy_level
49+
50+
if 'external_builds_privacy_level' in self.fields:
51+
self.fields['external_builds_privacy_level'].choices = copy(privacy_level)

readthedocs/projects/forms.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,9 @@ class Meta:
204204
'analytics_disabled',
205205
'show_version_warning',
206206
'single_version',
207-
'external_builds_enabled',
208207
'privacy_level',
208+
'external_builds_enabled',
209+
'external_builds_privacy_level',
209210
)
210211
# These that can be set per-version using a config file.
211212
per_version_settings = (
@@ -237,8 +238,9 @@ def __init__(self, *args, **kwargs):
237238

238239
per_project_settings = list(self.Meta.per_project_settings)
239240
if not settings.ALLOW_PRIVATE_REPOS:
240-
self.fields.pop('privacy_level')
241-
per_project_settings.remove('privacy_level')
241+
for field in ['privacy_level', 'external_builds_privacy_level']:
242+
self.fields.pop(field)
243+
per_project_settings.remove(field)
242244

243245
field_sets = [
244246
Fieldset(
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Generated by Django 2.2.17 on 2021-01-12 22:39
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('projects', '0068_remove_slug_field'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='project',
15+
name='external_builds_privacy_level',
16+
field=models.CharField(choices=[('public', 'Public'), ('protected', 'Protected'), ('private', 'Private')], default='private', null=True, help_text='Should builds from pull requests be public?', max_length=20, verbose_name='Privacy level of builds from pull requests'),
17+
),
18+
migrations.AlterField(
19+
model_name='project',
20+
name='external_builds_enabled',
21+
field=models.BooleanField(default=False, help_text='More information in <a href="https://docs.readthedocs.io/page/guides/autobuild-docs-for-pull-requests.html">our docs</a>', verbose_name='Build pull requests for this project'),
22+
),
23+
]

readthedocs/projects/models.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,24 @@ class Project(models.Model):
213213
),
214214
)
215215

216+
# External versions
216217
external_builds_enabled = models.BooleanField(
217218
_('Build pull requests for this project'),
218219
default=False,
219-
help_text=_('More information in <a href="https://docs.readthedocs.io/en/latest/guides/autobuild-docs-for-pull-requests.html">our docs</a>') # noqa
220+
help_text=_('More information in <a href="https://docs.readthedocs.io/page/guides/autobuild-docs-for-pull-requests.html">our docs</a>') # noqa
221+
)
222+
external_builds_privacy_level = models.CharField(
223+
_('Privacy level of builds from pull requests'),
224+
max_length=20,
225+
# TODO: remove after migration
226+
null=True,
227+
choices=constants.PRIVACY_CHOICES,
228+
# Force it to private so current projects in .com
229+
# use this value.
230+
default=constants.PRIVATE,
231+
help_text=_(
232+
'Should builds from pull requests be public?',
233+
),
220234
)
221235

222236
# Project features

readthedocs/rtd_tests/tests/test_project_forms.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ def test_can_update_privacy_level(self):
298298
'documentation_type': SPHINX,
299299
'python_interpreter': 'python3',
300300
'privacy_level': PRIVATE,
301+
'external_builds_privacy_level': PRIVATE,
301302
},
302303
instance=self.project,
303304
)

0 commit comments

Comments
 (0)