1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-31 14:42:10 +00:00

Merge pull request #1212 from haiwen/enhancement/constance

Add setting to enable/disable constance(web settings)
This commit is contained in:
Daniel Pan
2016-05-27 11:11:34 +08:00
7 changed files with 31 additions and 1 deletions

View File

@@ -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

View File

@@ -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,
}

View File

@@ -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,''),

View File

@@ -8,9 +8,11 @@
</li>
<li class="tab <% if (cur_tab == 'devices') { %> tab-cur<% } %>"> <a href="{{ SITE_ROOT }}sysadmin/#desktop-devices/"><span class="sf2-icon-monitor"></span>{% trans "Devices" %}</a>
</li>
{% if constance_enabled %}
<li class="tab">
<a href="{% url "sys_settings" %}"><span class="sf2-icon-cog2"></span>{% trans "Settings" %}</a>
</li>
{% endif %}
<li class="tab">
<a href="{{ SITE_ROOT }}sys/seafadmin/"><span class="sf2-icon-library"></span>{% trans "Libraries" %}</a>
</li>

View File

@@ -11,9 +11,11 @@
<li class="tab {% block cur_devices %}{% endblock %}">
<a href="{{ SITE_ROOT }}sysadmin/#desktop-devices/"><span class="sf2-icon-monitor"></span>{% trans "Devices" %}</a>
</li>
{% if constance_enabled %}
<li class="tab {% block cur_settings %}{% endblock %}">
<a href="{% url "sys_settings" %}"><span class="sf2-icon-cog2"></span>{% trans "Settings" %}</a>
</li>
{% endif %}
<li class="tab {% block cur_repo %}{% endblock %}">
<a href="{{ SITE_ROOT }}sys/seafadmin/"><span class="sf2-icon-library"></span>{% trans "Libraries" %}</a>
</li>

View File

@@ -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',

View File

@@ -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)