-
Notifications
You must be signed in to change notification settings - Fork 358
[ENG-10768] Have a display of some form when the OSF is down for planned maintenance #11706
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
brianjgeiger
merged 5 commits into
CenterForOpenScience:feature/pbs-26-9
from
mkovalua:feature/ENG-10768
Apr 30, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8b91d23
return 503 for API if maintanence_mode is set to ture
mkovalua 6e3360e
set maintenance mode via admin
mkovalua 6655865
resolve CR comments add unittests
mkovalua d49a26e
resolve CR comments update unittests
mkovalua 86784a3
update tests
mkovalua 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,38 @@ | ||
| # Generated by Django 4.2.26 on 2026-04-23 14:25 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| def create_initial_record(apps, schema_editor): | ||
| MaintenanceMode = apps.get_model('osf', 'MaintenanceMode') | ||
| MaintenanceMode.objects.get_or_create( | ||
| pk=1, | ||
| defaults={'maintenance_mode': False} | ||
| ) | ||
|
|
||
|
|
||
| def reverse_initial_record(apps, schema_editor): | ||
| # the reverse 'reverse_initial_record' does nothing | ||
| # because the table will be removed | ||
| pass | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('osf', '0038_abstractnode_date_last_indexed_and_more'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name='MaintenanceMode', | ||
| fields=[ | ||
| ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
| ('maintenance_mode', models.BooleanField(default=False)), | ||
| ], | ||
| ), | ||
| migrations.RunPython( | ||
| create_initial_record, | ||
| reverse_code=reverse_initial_record | ||
| ), | ||
| ] |
This file contains hidden or 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 hidden or 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 hidden or 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,105 @@ | ||
| import pytest | ||
| from unittest import mock | ||
| from tests.base import ApiTestCase | ||
| from osf.utils import permissions | ||
| from osf_tests.factories import ( | ||
| AuthUserFactory, | ||
| CollectionProviderFactory, | ||
| ProjectFactory, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture() | ||
| def provider(): | ||
| provider = CollectionProviderFactory() | ||
| provider.update_group_permissions() | ||
| return provider | ||
|
|
||
|
|
||
| @pytest.fixture() | ||
| def admin(provider): | ||
| user = AuthUserFactory() | ||
| provider.get_group(permissions.ADMIN).user_set.add(user) | ||
| return user | ||
|
|
||
|
|
||
| @pytest.fixture() | ||
| def node(admin): | ||
| return ProjectFactory(creator=admin) | ||
|
|
||
|
|
||
| class TestMaintenanceModeMiddlewareIntegration(ApiTestCase): | ||
| MAINTENANCE_MOCK_PATH = 'api.base.middleware.MaintenanceMode.is_under_maintenance' | ||
|
|
||
| def setUp(self): | ||
| super().setUp() | ||
| self.provider = CollectionProviderFactory() | ||
| self.provider.update_group_permissions() | ||
| self.admin = AuthUserFactory() | ||
| self.provider.get_group(permissions.ADMIN).user_set.add(self.admin) | ||
| self.node = ProjectFactory(creator=self.admin) | ||
|
|
||
| @mock.patch(MAINTENANCE_MOCK_PATH, return_value=True) | ||
| def test_middleware_blocks_post_if_maintenance_mode_on(self, mock_maintenance): | ||
| url = f'/v2/nodes/{self.node._id}/' | ||
| response = self.app.post_json(url, {}, expect_errors=True) | ||
| assert response.status_code == 503 | ||
| assert response.json['meta']['maintenance_mode'] is True | ||
| assert response.json['meta']['status_page'] == 'https://status.cos.io' | ||
|
|
||
| @mock.patch(MAINTENANCE_MOCK_PATH, return_value=True) | ||
| def test_middleware_blocks_patch_if_maintenance_mode_on(self, mock_maintenance): | ||
| url = f'/v2/nodes/{self.node._id}/' | ||
| original_title = self.node.title | ||
| payload = { | ||
| 'data': { | ||
| 'id': self.node._id, | ||
| 'type': 'nodes', | ||
| 'attributes': {'title': 'Updated Title'} | ||
| } | ||
| } | ||
| response = self.app.patch_json(url, payload, expect_errors=True) | ||
| assert response.status_code == 503 | ||
| assert response.json['meta']['maintenance_mode'] is True | ||
| self.node.reload() | ||
| assert self.node.title == original_title | ||
|
|
||
| @mock.patch(MAINTENANCE_MOCK_PATH, return_value=True) | ||
| def test_middleware_blocks_delete_if_maintenance_mode_on(self, mock_maintenance): | ||
| url = f'/v2/nodes/{self.node._id}/' | ||
| response = self.app.delete(url, expect_errors=True) | ||
| assert response.status_code == 503 | ||
| assert response.json['meta']['maintenance_mode'] is True | ||
|
Comment on lines
+50
to
+72
Collaborator
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. Could you add into these tests that the underlying resource doesn't get changed or deleted when you make these requests, not just that the response is correct? |
||
| self.node.reload() | ||
| assert self.node.is_deleted is False | ||
|
|
||
| @mock.patch(MAINTENANCE_MOCK_PATH, return_value=False) | ||
| def test_go_to_post_view_if_maintenance_mode_off(self, mock_maintenance): | ||
| url = '/v2/nodes/' | ||
| payload = { | ||
| 'data': { | ||
| 'type': 'nodes', | ||
| 'attributes': {'title': 'New Node', 'category': 'project'} | ||
| } | ||
| } | ||
| response = self.app.post_json(url, payload, auth=self.admin.auth) | ||
| assert response.status_code == 201 | ||
|
|
||
| @mock.patch(MAINTENANCE_MOCK_PATH, return_value=False) | ||
| def test_go_to_patch_view_if_maintenance_mode_off(self, mock_maintenance): | ||
| url = f'/v2/nodes/{self.node._id}/' | ||
| payload = { | ||
| 'data': { | ||
| 'id': self.node._id, | ||
| 'type': 'nodes', | ||
| 'attributes': {'title': 'Updated Title'} | ||
| } | ||
| } | ||
| response = self.app.patch_json(url, payload, auth=self.admin.auth) | ||
| assert response.status_code == 200 | ||
|
|
||
| @mock.patch(MAINTENANCE_MOCK_PATH, return_value=False) | ||
| def test_go_to_delete_view_if_maintenance_mode_off(self, mock_maintenance): | ||
| url = f'/v2/nodes/{self.node._id}/' | ||
| response = self.app.delete(url, auth=self.admin.auth) | ||
| assert response.status_code == 204 | ||
Oops, something went wrong.
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.
I'm not super-familiar with Middleware in Django. Will this also prevent incoming requests from being processed (i.e. if someone POSTs or PATCHes something, will we prevent that from affecting the OSF DB)?
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.
Yes, middleware calls for all requests and workflow goes to view only if
MaintenanceMode.is_under_maintenance()is False