Skip to content

Commit a655d8d

Browse files
Control read only mode with environmental variable #11710 (#11711)
* Add env-var to override the readonly mode * Fix flake8 issue * Add test coverage * Add test coverage * Add test coverage * Fix broken test
1 parent a76480f commit a655d8d

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

.env.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,3 +253,5 @@ RESTART_POLICY_WINDOW=120s
253253

254254
DEFAULT_MAX_UPLOAD_SIZE=5368709120
255255
DEFAULT_MAX_PARALLEL_UPLOADS_PER_USER=5
256+
257+
# FORCE_READ_ONLY_MODE=False Override the read-only value saved in the configuration

geonode/base/tests.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,17 @@ def test_maintenance_true(self):
666666

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

669+
@patch.dict(os.environ, {"FORCE_READ_ONLY_MODE": "True"})
670+
def test_readonly_overwrite_by_env(self):
671+
config = Configuration.load()
672+
self.assertTrue(config.read_only)
673+
674+
@patch.dict(os.environ, {"FORCE_READ_ONLY_MODE": "False"})
675+
def test_readonly_is_not_overwrite_by_env(self):
676+
# will take the value from the db
677+
config = Configuration.load()
678+
self.assertFalse(config.read_only)
679+
669680

670681
class TestOwnerRightsRequestUtils(TestCase):
671682
def setUp(self):

geonode/singleton.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
# Geonode functionality
2222

23+
import os
24+
import ast
2325
from django.db import models
2426

2527

@@ -38,6 +40,9 @@ class Meta:
3840
@classmethod
3941
def load(cls):
4042
obj, _ = cls.objects.get_or_create(pk=1)
43+
val = os.getenv("FORCE_READ_ONLY_MODE", None)
44+
if val is not None:
45+
setattr(obj, "read_only", ast.literal_eval(val))
4146
return obj
4247

4348
def save(self, *args, **kwargs):

0 commit comments

Comments
 (0)