Skip to content

Allow to change the privacy level of external versions #7825

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jul 1, 2021
Merged
10 changes: 8 additions & 2 deletions readthedocs/core/mixins.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Common mixin classes for views."""

from copy import copy

from django.contrib.auth.mixins import LoginRequiredMixin
from django.utils.translation import ugettext_lazy as _
from vanilla import ListView
Expand Down Expand Up @@ -39,7 +41,11 @@ class HideProtectedLevelMixin:
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

privacy_level = list(PRIVACY_CHOICES)
privacy_level.remove((PROTECTED, _('Protected')))

if self.instance is None or self.instance.privacy_level != PROTECTED:
privacy_level = list(PRIVACY_CHOICES)
privacy_level.remove((PROTECTED, _('Protected')))
self.fields['privacy_level'].choices = privacy_level

if 'external_builds_privacy_level' in self.fields:
self.fields['external_builds_privacy_level'].choices = copy(privacy_level)
8 changes: 5 additions & 3 deletions readthedocs/projects/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,9 @@ class Meta:
'analytics_disabled',
'show_version_warning',
'single_version',
'external_builds_enabled',
'privacy_level',
'external_builds_enabled',
'external_builds_privacy_level',
)
# These that can be set per-version using a config file.
per_version_settings = (
Expand Down Expand Up @@ -237,8 +238,9 @@ def __init__(self, *args, **kwargs):

per_project_settings = list(self.Meta.per_project_settings)
if not settings.ALLOW_PRIVATE_REPOS:
self.fields.pop('privacy_level')
per_project_settings.remove('privacy_level')
for field in ['privacy_level', 'external_builds_privacy_level']:
self.fields.pop(field)
per_project_settings.remove(field)

field_sets = [
Fieldset(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 2.2.17 on 2021-01-12 22:39

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('projects', '0068_remove_slug_field'),
]

operations = [
migrations.AddField(
model_name='project',
name='external_builds_privacy_level',
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'),
),
migrations.AlterField(
model_name='project',
name='external_builds_enabled',
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'),
),
]
16 changes: 15 additions & 1 deletion readthedocs/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,24 @@ class Project(models.Model):
),
)

# External versions
external_builds_enabled = models.BooleanField(
_('Build pull requests for this project'),
default=False,
help_text=_('More information in <a href="https://docs.readthedocs.io/en/latest/guides/autobuild-docs-for-pull-requests.html">our docs</a>') # noqa
help_text=_('More information in <a href="https://docs.readthedocs.io/page/guides/autobuild-docs-for-pull-requests.html">our docs</a>') # noqa
)
external_builds_privacy_level = models.CharField(
_('Privacy level of builds from pull requests'),
max_length=20,
# TODO: remove after migration
null=True,
choices=constants.PRIVACY_CHOICES,
# Force it to private so current projects in .com
# use this value.
default=constants.PRIVATE,
help_text=_(
'Should builds from pull requests be public?',
),
)

# Project features
Expand Down
1 change: 1 addition & 0 deletions readthedocs/rtd_tests/tests/test_project_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ def test_can_update_privacy_level(self):
'documentation_type': SPHINX,
'python_interpreter': 'python3',
'privacy_level': PRIVATE,
'external_builds_privacy_level': PRIVATE,
},
instance=self.project,
)
Expand Down