-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Addons: allow users to show/hide notifications on latest/non-stable #11718
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
Changes from 1 commit
5d5f64d
232bbbe
057d581
65cece8
2138ad7
8a8323b
0294f2d
bed03bd
c4bea78
104fdd0
b19d0dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Generated by Django 4.2.16 on 2024-10-29 14:05 | ||
|
||
from django.db import migrations, models | ||
from django_safemigrate import Safe | ||
|
||
|
||
def forward_add_fields(apps, schema_editor): | ||
AddonsConfig = apps.get_model("projects", "AddonsConfig") | ||
for addons in AddonsConfig.objects.filter(project__isnull=False): | ||
addons.notifications_show_on_latest = addons.stable_latest_version_warning_enabled | ||
addons.notifications_show_on_non_stable = addons.stable_latest_version_warning_enabled | ||
addons.notifications_show_on_external = addons.external_version_warning_enabled | ||
addons.save() | ||
|
||
|
||
def reverse_remove_fields(apps, schema_editor): | ||
AddonsConfig = apps.get_model("projects", "AddonsConfig") | ||
for addons in AddonsConfig.objects.filter(project__isnull=False): | ||
addons.stable_latest_version_warning_enabled = addons.notifications_show_on_latest or addons.notifications_show_on_non_stable | ||
addons.external_version_warning_enabled = addons.notifications_show_on_external | ||
addons.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
safe = Safe.before_deploy | ||
|
||
dependencies = [ | ||
('projects', '0127_default_to_semver'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='addonsconfig', | ||
name='notifications_enabled', | ||
field=models.BooleanField(default=True), | ||
), | ||
migrations.AddField( | ||
model_name='addonsconfig', | ||
name='notifications_show_on_external', | ||
field=models.BooleanField(default=True), | ||
), | ||
migrations.AddField( | ||
model_name='addonsconfig', | ||
name='notifications_show_on_latest', | ||
field=models.BooleanField(default=True), | ||
), | ||
migrations.AddField( | ||
model_name='addonsconfig', | ||
name='notifications_show_on_non_stable', | ||
field=models.BooleanField(default=True), | ||
), | ||
migrations.AddField( | ||
model_name='historicaladdonsconfig', | ||
name='notifications_enabled', | ||
field=models.BooleanField(default=True), | ||
), | ||
migrations.AddField( | ||
model_name='historicaladdonsconfig', | ||
name='notifications_show_on_external', | ||
field=models.BooleanField(default=True), | ||
), | ||
migrations.AddField( | ||
model_name='historicaladdonsconfig', | ||
name='notifications_show_on_latest', | ||
field=models.BooleanField(default=True), | ||
), | ||
migrations.AddField( | ||
model_name='historicaladdonsconfig', | ||
name='notifications_show_on_non_stable', | ||
field=models.BooleanField(default=True), | ||
), | ||
migrations.RunPython(forward_add_fields, reverse_remove_fields), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Generated by Django 4.2.16 on 2024-10-29 14:09 | ||
|
||
from django.db import migrations | ||
from django_safemigrate import Safe | ||
|
||
|
||
class Migration(migrations.Migration): | ||
safe = Safe.after_deploy | ||
|
||
dependencies = [ | ||
('projects', '0128_addons_notifications'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='addonsconfig', | ||
name='external_version_warning_enabled', | ||
), | ||
migrations.RemoveField( | ||
model_name='addonsconfig', | ||
name='stable_latest_version_warning_enabled', | ||
), | ||
migrations.RemoveField( | ||
model_name='historicaladdonsconfig', | ||
name='external_version_warning_enabled', | ||
), | ||
migrations.RemoveField( | ||
model_name='historicaladdonsconfig', | ||
name='stable_latest_version_warning_enabled', | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,9 +178,6 @@ class AddonsConfig(TimeStampedModel): | |
help_text="CSS selector for the main content of the page", | ||
) | ||
|
||
# External version warning | ||
external_version_warning_enabled = models.BooleanField(default=True) | ||
|
||
# EthicalAds | ||
ethicalads_enabled = models.BooleanField(default=True) | ||
|
||
|
@@ -215,8 +212,11 @@ class AddonsConfig(TimeStampedModel): | |
search_enabled = models.BooleanField(default=True) | ||
search_default_filter = models.CharField(null=True, blank=True, max_length=128) | ||
|
||
# Stable/Latest version warning | ||
stable_latest_version_warning_enabled = models.BooleanField(default=True) | ||
# Notifications | ||
notifications_enabled = models.BooleanField(default=True) | ||
notifications_show_on_latest = models.BooleanField(default=True) | ||
notifications_show_on_non_stable = models.BooleanField(default=True) | ||
notifications_show_on_external = models.BooleanField(default=True) | ||
Comment on lines
+216
to
+219
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All these should be nullable to avoid downtime. https://dev.readthedocs.io/en/stable/migrations.html#adding-a-new-field If we are okay with not allowing to create/edit this model while the migration takes place, that's okay, I guess. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems fine, it should be a quick migration? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do wonder if we want to default all of these to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the field has a default value it doesn't need to be nullable, right? Once the field is added, it will be the default value automatically and when creating a new row from an old instance without passing the new value. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I haven't thought too much about this, I just followed the defaults we had previously. Apart from that, I think it's good to enable all the addons by default as a way to immediately expose these features to users and leave users to decide if they want to use them or not. The only ones I'm have to turn off by default are those that cost us money and are not very used by our users, eg. analytics. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm happy to talk more about this and change this default now and/or in the future, tho. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No, the default value is set at the django level, not at the db level. Django 5.x has an option to set default values at the db level. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point 👍🏼 . We should mention that in that document to avoid this confusion every time 😄 . |
||
|
||
|
||
class AddonSearchFilter(TimeStampedModel): | ||
|
Uh oh!
There was an error while loading. Please reload this page.