-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Addons: allow users to show/hide notifications on latest/non-stable #11718
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5d5f64d
Addons: allow users to show/hide notifications on latest/non-stable
humitos 232bbbe
Add basic docs on Doc notifications
ericholscher 057d581
Update readthedocs/projects/forms.py
humitos 65cece8
Update test to fix it
humitos 2138ad7
Merge branch 'humitos/addons-notifications-latest-stable' of github.c…
humitos 8a8323b
Quotes :(
humitos 0294f2d
Update API response for tests
humitos bed03bd
Lint
humitos c4bea78
Merge branch 'main' of github.com:readthedocs/readthedocs.org into hu…
humitos 104fdd0
lint
humitos b19d0dc
lint: meh, pre-commit is failing locally for some reason
humitos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Documentation notifications | ||
=========================== | ||
|
||
Documentation notifications alert users to information about the documentation they are viewing. | ||
These notifications can be enabled or disabled by the project maintainer, | ||
and are displayed to the user in the rendered documentation. | ||
|
||
Overview | ||
-------- | ||
|
||
The current notifications are: | ||
|
||
- **Pull request warning**: Show a notification on builds from pull requests, with a link back to the pull request for giving feedback. | ||
- **Latest version warning**: Show a notification on latest version, warning users that they are reading docs from a development version. | ||
- **Non-stable version warning**: Show a notification on non-stable versions, warning users that they are reading docs from a non-stable release. | ||
|
||
Manage notifications | ||
-------------------- | ||
|
||
To manage notifications for your project: | ||
|
||
1. Go to the :term:`dashboard`. | ||
2. Click on a project name. | ||
3. Go to :guilabel:`Settings`. | ||
4. In the left bar, go to :guilabel:`Addons`. | ||
5. Configure each Addon in the :guilabel:`Notifications` section. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
readthedocs/projects/migrations/0128_addons_notifications.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# 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), | ||
] |
31 changes: 31 additions & 0 deletions
31
readthedocs/projects/migrations/0129_addons_remove_old_fields.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
I do wonder if we want to default all of these to
True
, though? In particular, I'm not sure we wantlatest
to have a default warning?There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 comment
The 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 comment
The 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 comment
The 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 comment
The 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 😄 .