Skip to content

Commit

Permalink
Control read only mode with environmental variable GeoNode#11710 (Geo…
Browse files Browse the repository at this point in the history
…Node#11711)

* Add env-var to override the readonly mode

* Fix flake8 issue

* Add test coverage

* Add test coverage

* Add test coverage

* Fix broken test
  • Loading branch information
mattiagiupponi committed Nov 21, 2023
1 parent a76480f commit a655d8d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
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

0 comments on commit a655d8d

Please sign in to comment.