Skip to content
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

[Backport 4.2.x] Control read only mode with environmental variable #11710 #11712

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,5 @@ RESTART_POLICY_WINDOW=120s

DEFAULT_MAX_UPLOAD_SIZE=5368709120
DEFAULT_MAX_PARALLEL_UPLOADS_PER_USER=5

# FORCE_READ_ONLY_MODE=False Override the read-only value saved in the configuration
11 changes: 11 additions & 0 deletions geonode/base/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,17 @@ def test_maintenance_true(self):

self.assertEqual(response.status_code, 503, "User is allowed to get index page")

@patch.dict(os.environ, {"FORCE_READ_ONLY_MODE": "True"})
def test_readonly_overwrite_by_env(self):
config = Configuration.load()
self.assertTrue(config.read_only)

@patch.dict(os.environ, {"FORCE_READ_ONLY_MODE": "False"})
def test_readonly_is_not_overwrite_by_env(self):
# will take the value from the db
config = Configuration.load()
self.assertFalse(config.read_only)


class TestOwnerRightsRequestUtils(TestCase):
def setUp(self):
Expand Down
5 changes: 5 additions & 0 deletions geonode/singleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

# Geonode functionality

import os
import ast
from django.db import models


Expand All @@ -38,6 +40,9 @@ class Meta:
@classmethod
def load(cls):
obj, _ = cls.objects.get_or_create(pk=1)
val = os.getenv("FORCE_READ_ONLY_MODE", None)
if val is not None:
setattr(obj, "read_only", ast.literal_eval(val))
return obj

def save(self, *args, **kwargs):
Expand Down