diff --git a/requirements.txt b/requirements.txt index bcaaddbcb8..52f6ab755e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,6 +8,6 @@ django-compressor==1.4 django-post-office==2.0.3 django-statici18n==1.1.2 djangorestframework==3.3.1 -git+git://github.com/haiwen/django-constance.git@bde7f7cdfd0ed1631a6817fd4cd76f37bf54fe35#egg=django-constance[database] +git+git://github.com/haiwen/django-constance.git@751f7f8b60651a2828e4a535a47fc05b907883da#egg=django-constance[database] openpyxl==2.3.0 pytz==2015.7 diff --git a/seahub/base/context_processors.py b/seahub/base/context_processors.py index 18b90e98d4..17566a5d87 100644 --- a/seahub/base/context_processors.py +++ b/seahub/base/context_processors.py @@ -89,4 +89,5 @@ def base(request): 'multi_institution': getattr(dj_settings, 'MULTI_INSTITUTION', False), 'search_repo_id': search_repo_id, 'SITE_ROOT': SITE_ROOT, + 'constance_enabled': dj_settings.CONSTANCE_ENABLED, } diff --git a/seahub/settings.py b/seahub/settings.py index 1a92f69ec8..76830866cf 100644 --- a/seahub/settings.py +++ b/seahub/settings.py @@ -212,6 +212,8 @@ INSTALLED_APPS = ( 'seahub.password_session', ) +# Enabled or disable constance(web settings). +ENABLE_SETTINGS_VIA_WEB = True CONSTANCE_BACKEND = 'constance.backends.database.DatabaseBackend' CONSTANCE_DATABASE_CACHE_BACKEND = 'default' @@ -622,8 +624,10 @@ if 'win32' in sys.platform: fp.write("%d\n" % os.getpid()) fp.close() +# Following settings are private, can not be overwrite. INNER_FILE_SERVER_ROOT = 'http://127.0.0.1:' + FILE_SERVER_PORT +CONSTANCE_ENABLED = ENABLE_SETTINGS_VIA_WEB CONSTANCE_CONFIG = { 'SERVICE_URL': (SERVICE_URL,''), 'FILE_SERVER_ROOT': (FILE_SERVER_ROOT,''), diff --git a/seahub/templates/js/sysadmin-templates.html b/seahub/templates/js/sysadmin-templates.html index 3ed6b0213d..005846667c 100644 --- a/seahub/templates/js/sysadmin-templates.html +++ b/seahub/templates/js/sysadmin-templates.html @@ -8,9 +8,11 @@
  • {% trans "Devices" %}
  • + {% if constance_enabled %}
  • {% trans "Settings" %}
  • + {% endif %}
  • {% trans "Libraries" %}
  • diff --git a/seahub/templates/sysadmin/base.html b/seahub/templates/sysadmin/base.html index 1809df959d..ff6ef6cd0a 100644 --- a/seahub/templates/sysadmin/base.html +++ b/seahub/templates/sysadmin/base.html @@ -11,9 +11,11 @@
  • {% trans "Devices" %}
  • + {% if constance_enabled %}
  • {% trans "Settings" %}
  • + {% endif %}
  • {% trans "Libraries" %}
  • diff --git a/seahub/views/sysadmin.py b/seahub/views/sysadmin.py index 52feb9591f..d9004558d7 100644 --- a/seahub/views/sysadmin.py +++ b/seahub/views/sysadmin.py @@ -11,6 +11,7 @@ import csv, chardet, StringIO import time from constance import config +from django.conf import settings as dj_settings from django.core.urlresolvers import reverse from django.contrib import messages from django.http import HttpResponse, Http404, HttpResponseRedirect, HttpResponseNotAllowed @@ -2181,6 +2182,8 @@ def sys_sudo_mode(request): def sys_settings(request): """List and change seahub settings in admin panel. """ + if not dj_settings.ENABLE_SETTINGS_VIA_WEB: + raise Http404 DIGIT_WEB_SETTINGS = ( 'DISABLE_SYNC_WITH_ANY_FOLDER', 'ENABLE_SIGNUP', diff --git a/tests/seahub/views/sysadmin/test_sys_settings.py b/tests/seahub/views/sysadmin/test_sys_settings.py new file mode 100644 index 0000000000..1d041d8947 --- /dev/null +++ b/tests/seahub/views/sysadmin/test_sys_settings.py @@ -0,0 +1,18 @@ +from django.core.urlresolvers import reverse + +from seahub.test_utils import BaseTestCase + + +class SysSettingsTest(BaseTestCase): + def setUp(self): + self.url = reverse('sys_settings') + self.login_as(self.admin) + + def test_can_render(self): + resp = self.client.get(self.url) + self.assertEqual(200, resp.status_code) + + def test_can_not_render_if_setting_disabled(self): + with self.settings(ENABLE_SETTINGS_VIA_WEB=False): + resp = self.client.get(self.url) + self.assertEqual(404, resp.status_code)