diff --git a/rhodecode/admin/__init__.py b/rhodecode/admin/__init__.py --- a/rhodecode/admin/__init__.py +++ b/rhodecode/admin/__init__.py @@ -39,5 +39,12 @@ def includeme(config): name='admin_settings_vcs_svn_generate_cfg', pattern=ADMIN_PREFIX + '/settings/vcs/svn_generate_cfg') + config.add_route( + name='admin_settings_sessions', + pattern=ADMIN_PREFIX + '/settings/sessions') + config.add_route( + name='admin_settings_sessions_cleanup', + pattern=ADMIN_PREFIX + '/settings/sessions/cleanup') + # Scan module for configuration decorators. config.scan() diff --git a/rhodecode/admin/navigation.py b/rhodecode/admin/navigation.py --- a/rhodecode/admin/navigation.py +++ b/rhodecode/admin/navigation.py @@ -80,10 +80,15 @@ class NavigationRegistry(object): NavEntry('email', _('Email'), 'admin_settings_email'), NavEntry('hooks', _('Hooks'), 'admin_settings_hooks'), NavEntry('search', _('Full Text Search'), 'admin_settings_search'), + + NavEntry('integrations', _('Integrations'), 'global_integrations_home', pyramid=True), NavEntry('system', _('System Info'), 'admin_settings_system'), - NavEntry('session', _('User Sessions'), 'admin_settings_sessions'), + + + NavEntry('session', _('User Sessions'), + 'admin_settings_sessions', pyramid=True), NavEntry('open_source', _('Open Source Licenses'), 'admin_settings_open_source', pyramid=True), diff --git a/rhodecode/admin/views.py b/rhodecode/admin/views.py --- a/rhodecode/admin/views.py +++ b/rhodecode/admin/views.py @@ -23,12 +23,18 @@ import logging from pylons import tmpl_context as c from pyramid.view import view_config +from pyramid.httpexceptions import HTTPFound + +from rhodecode.translation import _ +from rhodecode.svn_support.utils import generate_mod_dav_svn_config from rhodecode.lib.auth import ( LoginRequired, HasPermissionAllDecorator, CSRFRequired) from rhodecode.lib.utils import read_opensource_licenses -from rhodecode.svn_support.utils import generate_mod_dav_svn_config -from rhodecode.translation import _ +from rhodecode.lib.utils2 import safe_int +from rhodecode.lib import system_info +from rhodecode.lib import user_sessions + from .navigation import navigation_list @@ -72,7 +78,8 @@ class AdminSettingsView(object): } except Exception: log.exception( - 'Exception while generating the Apache configuration for Subversion.') + 'Exception while generating the Apache ' + 'configuration for Subversion.') msg = { 'message': _('Failed to generate the Apache configuration for Subversion.'), 'level': 'error', @@ -80,3 +87,59 @@ class AdminSettingsView(object): data = {'message': msg} return data + + @LoginRequired() + @HasPermissionAllDecorator('hg.admin') + @view_config( + route_name='admin_settings_sessions', request_method='GET', + renderer='rhodecode:templates/admin/settings/settings.mako') + def settings_sessions(self): + c.active = 'sessions' + c.navlist = navigation_list(self.request) + + c.cleanup_older_days = 60 + older_than_seconds = 24 * 60 * 60 * 24 * c.cleanup_older_days + + config = system_info.rhodecode_config().get_value()['value']['config'] + c.session_model = user_sessions.get_session_handler( + config.get('beaker.session.type', 'memory'))(config) + + c.session_conf = c.session_model.config + c.session_count = c.session_model.get_count() + c.session_expired_count = c.session_model.get_expired_count( + older_than_seconds) + + return {} + + @LoginRequired() + @HasPermissionAllDecorator('hg.admin') + @view_config( + route_name='admin_settings_sessions_cleanup', request_method='POST') + def settings_sessions_cleanup(self): + + expire_days = safe_int(self.request.params.get('expire_days')) + + if expire_days is None: + expire_days = 60 + + older_than_seconds = 24 * 60 * 60 * 24 * expire_days + + config = system_info.rhodecode_config().get_value()['value']['config'] + session_model = user_sessions.get_session_handler( + config.get('beaker.session.type', 'memory'))(config) + + try: + session_model.clean_sessions( + older_than_seconds=older_than_seconds) + self.request.session.flash( + _('Cleaned up old sessions'), queue='success') + except user_sessions.CleanupCommand as msg: + self.request.session.flash(msg, category='warning') + except Exception as e: + log.exception('Failed session cleanup') + self.request.session.flash( + _('Failed to cleanup up old sessions'), queue='error') + + redirect_to = self.request.resource_path( + self.context, route_name='admin_settings_sessions') + return HTTPFound(redirect_to) diff --git a/rhodecode/config/routing.py b/rhodecode/config/routing.py --- a/rhodecode/config/routing.py +++ b/rhodecode/config/routing.py @@ -509,12 +509,6 @@ def make_map(config): m.connect('admin_settings_system_update', '/settings/system/updates', action='settings_system_update', conditions={'method': ['GET']}) - m.connect('admin_settings_sessions', '/settings/sessions', - action='settings_sessions', conditions={'method': ['GET']}) - - m.connect('admin_settings_sessions_cleanup', '/settings/sessions/cleanup', - action='settings_sessions_cleanup', conditions={'method': ['POST']}) - m.connect('admin_settings_supervisor', '/settings/supervisor', action='settings_supervisor', conditions={'method': ['GET']}) m.connect('admin_settings_supervisor_log', '/settings/supervisor/{procid}/log', diff --git a/rhodecode/controllers/admin/settings.py b/rhodecode/controllers/admin/settings.py --- a/rhodecode/controllers/admin/settings.py +++ b/rhodecode/controllers/admin/settings.py @@ -50,8 +50,6 @@ from rhodecode.lib.utils2 import ( from rhodecode.lib.compat import OrderedDict from rhodecode.lib.ext_json import json from rhodecode.lib.utils import jsonify -from rhodecode.lib import system_info -from rhodecode.lib import user_sessions from rhodecode.model.db import RhodeCodeUi, Repository from rhodecode.model.forms import ApplicationSettingsForm, \ @@ -693,52 +691,6 @@ class SettingsController(BaseController) return render('admin/settings/settings_system_update.mako') @HasPermissionAllDecorator('hg.admin') - def settings_sessions(self): - # url('admin_settings_sessions') - - c.active = 'sessions' - c.cleanup_older_days = 60 - older_than_seconds = 24 * 60 * 60 * 24 * c.cleanup_older_days - - config = system_info.rhodecode_config().get_value()['value']['config'] - c.session_model = user_sessions.get_session_handler( - config.get('beaker.session.type', 'memory'))(config) - - c.session_conf = c.session_model.config - c.session_count = c.session_model.get_count() - c.session_expired_count = c.session_model.get_expired_count( - older_than_seconds) - - return render('admin/settings/settings.mako') - - @HasPermissionAllDecorator('hg.admin') - def settings_sessions_cleanup(self): - # url('admin_settings_sessions_update') - - expire_days = safe_int(request.POST.get('expire_days')) - - if expire_days is None: - expire_days = 60 - - older_than_seconds = 24 * 60 * 60 * 24 * expire_days - - config = system_info.rhodecode_config().get_value()['value']['config'] - session_model = user_sessions.get_session_handler( - config.get('beaker.session.type', 'memory'))(config) - - try: - session_model.clean_sessions( - older_than_seconds=older_than_seconds) - h.flash(_('Cleaned up old sessions'), category='success') - except user_sessions.CleanupCommand as msg: - h.flash(msg, category='warning') - except Exception as e: - log.exception('Failed session cleanup') - h.flash(_('Failed to cleanup up old sessions'), category='error') - - return redirect(url('admin_settings_sessions')) - - @HasPermissionAllDecorator('hg.admin') def settings_supervisor(self): c.rhodecode_ini = rhodecode.CONFIG c.active = 'supervisor' diff --git a/rhodecode/templates/admin/settings/settings_sessions.mako b/rhodecode/templates/admin/settings/settings_sessions.mako --- a/rhodecode/templates/admin/settings/settings_sessions.mako +++ b/rhodecode/templates/admin/settings/settings_sessions.mako @@ -28,7 +28,7 @@
${_('Cleanup user sessions that were not active during chosen time frame.')}