Skip to content

Commit 7ea51c0

Browse files
authored
Version warning banner: disable it for project not using it already (#10483)
* Version warning banner: disable it for project not using it already We disccussed about this in readthedocs/meta#125 Basically, I want to disable it because it's more confusing than useful currently. Besides, it will be completely replaced by the new addons work we are doing. This is the first step we are taking here: stop keep confusing users. The following step would be to contact (if required) projects already using this feature and migrate them to the new addons. This commit includes a migration that creates the feature flag and assign all the projects that are already using `Show version banner` to that flag. * Hardcode feature id
1 parent 37be26d commit 7ea51c0

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

readthedocs/projects/forms.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ def clean_remote_repository(self):
143143
pk=remote_repo,
144144
users=self.user,
145145
)
146-
except RemoteRepository.DoesNotExist:
147-
raise forms.ValidationError(_('Repository invalid'))
146+
except RemoteRepository.DoesNotExist as exc:
147+
raise forms.ValidationError(_("Repository invalid")) from exc
148148

149149
def placehold_repo(self):
150150
return choice([
@@ -248,6 +248,14 @@ def __init__(self, *args, **kwargs):
248248
)
249249

250250
per_project_settings = list(self.Meta.per_project_settings)
251+
252+
# NOTE: we are deprecating this feature.
253+
# However, we will keep it available for projects that already using it.
254+
# Old projects not using it already or new projects won't be able to enable.
255+
if not self.instance.has_feature(Feature.ALLOW_VERSION_WARNING_BANNER):
256+
self.fields.pop("show_version_warning")
257+
per_project_settings.remove("show_version_warning")
258+
251259
if not settings.ALLOW_PRIVATE_REPOS:
252260
for field in ['privacy_level', 'external_builds_privacy_level']:
253261
self.fields.pop(field)
@@ -595,8 +603,10 @@ def clean_payload(self):
595603
try:
596604
payload = json.loads(payload)
597605
payload = json.dumps(payload, indent=2)
598-
except Exception:
599-
raise forms.ValidationError(_('The payload must be a valid JSON object.'))
606+
except Exception as exc:
607+
raise forms.ValidationError(
608+
_("The payload must be a valid JSON object.")
609+
) from exc
600610
return payload
601611

602612

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Generated by Django 3.2.19 on 2023-06-27 15:52
2+
3+
from django.db import migrations
4+
5+
6+
def forwards_func(apps, schema_editor):
7+
"""Create ALLOW_VERSION_WARNING_BANNER feature flag and assign projects."""
8+
Project = apps.get_model("projects", "Project")
9+
Feature = apps.get_model("projects", "Feature")
10+
11+
feature = Feature.objects.create(feature_id="allow_version_warning_banner")
12+
for project in Project.objects.filter(show_version_warning=True).iterator():
13+
feature.projects.add(project)
14+
15+
16+
class Migration(migrations.Migration):
17+
dependencies = [
18+
("projects", "0101_add_path_prefixes"),
19+
]
20+
21+
operations = [
22+
migrations.RunPython(forwards_func),
23+
]

readthedocs/projects/models.py

+5
Original file line numberDiff line numberDiff line change
@@ -1915,6 +1915,7 @@ def add_features(sender, **kwargs):
19151915
DISABLE_PAGEVIEWS = "disable_pageviews"
19161916
RESOLVE_PROJECT_FROM_HEADER = "resolve_project_from_header"
19171917
USE_UNRESOLVER_WITH_PROXITO = "use_unresolver_with_proxito"
1918+
ALLOW_VERSION_WARNING_BANNER = "allow_version_warning_banner"
19181919

19191920
# Versions sync related features
19201921
SKIP_SYNC_TAGS = 'skip_sync_tags'
@@ -2007,6 +2008,10 @@ def add_features(sender, **kwargs):
20072008
"Proxito: Use new unresolver implementation for serving documentation files."
20082009
),
20092010
),
2011+
(
2012+
ALLOW_VERSION_WARNING_BANNER,
2013+
_("Dashboard: Allow project to use the version warning banner."),
2014+
),
20102015

20112016
# Versions sync related features
20122017
(

0 commit comments

Comments
 (0)