# HG changeset patch # User Marcin Kuzminski # Date 2017-04-28 11:56:37 # Node ID 1a4c1af045520f737e450322ea3c8088730617b5 # Parent 0dad6b04e9dee5934f8dc0b9c8e5c19aae994a53 repo-caches: moved view into pyramid. diff --git a/rhodecode/apps/repository/__init__.py b/rhodecode/apps/repository/__init__.py --- a/rhodecode/apps/repository/__init__.py +++ b/rhodecode/apps/repository/__init__.py @@ -26,6 +26,12 @@ def includeme(config): name='edit_repo', pattern='/{repo_name:.*?[^/]}/settings', repo_route=True) + # Caches + config.add_route( + name='edit_repo_caches', + pattern='/{repo_name:.*?[^/]}/settings/caches', repo_route=True) + + # Maintenance config.add_route( name='repo_maintenance', pattern='/{repo_name:.*?[^/]}/maintenance', repo_route=True) diff --git a/rhodecode/apps/repository/tests/test_repo_settings.py b/rhodecode/apps/repository/tests/test_repo_settings.py --- a/rhodecode/apps/repository/tests/test_repo_settings.py +++ b/rhodecode/apps/repository/tests/test_repo_settings.py @@ -38,6 +38,7 @@ def route_path(name, params=None, **kwar base_url = { 'edit_repo': '/{repo_name}/settings', + 'edit_repo_caches': '/{repo_name}/settings/caches', }[name].format(**kwargs) if params: @@ -58,6 +59,7 @@ def _get_permission_for_user(user, repo) class TestAdminRepoSettings(object): @pytest.mark.parametrize('urlname', [ 'edit_repo', + 'edit_repo_caches' ]) def test_show_page(self, urlname, app, backend): app.get(route_path(urlname, repo_name=backend.repo_name), status=200) @@ -75,7 +77,6 @@ class TestAdminRepoSettings(object): 'repo_vcs_settings', 'edit_repo_fields', 'repo_settings_issuetracker', - 'edit_repo_caches', 'edit_repo_remote', 'edit_repo_statistics', ]) diff --git a/rhodecode/apps/repository/views/repo_caches.py b/rhodecode/apps/repository/views/repo_caches.py new file mode 100644 --- /dev/null +++ b/rhodecode/apps/repository/views/repo_caches.py @@ -0,0 +1,76 @@ +# -*- coding: utf-8 -*- + +# Copyright (C) 2011-2017 RhodeCode GmbH +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License, version 3 +# (only), as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +# This program is dual-licensed. If you wish to learn more about the +# RhodeCode Enterprise Edition, including its added features, Support services, +# and proprietary license terms, please see https://rhodecode.com/licenses/ + +import logging + +from pyramid.httpexceptions import HTTPFound +from pyramid.view import view_config + +from rhodecode.apps._base import RepoAppView +from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator +from rhodecode.lib import helpers as h +from rhodecode.model.meta import Session +from rhodecode.model.scm import ScmModel + +log = logging.getLogger(__name__) + + +class RepoCachesView(RepoAppView): + def load_default_context(self): + c = self._get_local_tmpl_context() + + # TODO(marcink): remove repo_info and use c.rhodecode_db_repo instead + c.repo_info = self.db_repo + + self._register_global_c(c) + return c + + @LoginRequired() + @HasRepoPermissionAnyDecorator('repository.admin') + @view_config( + route_name='edit_repo_caches', request_method='GET', + renderer='rhodecode:templates/admin/repos/repo_edit.mako') + def repo_caches(self): + c = self.load_default_context() + c.active = 'caches' + + return self._get_template_context(c) + + @LoginRequired() + @HasRepoPermissionAnyDecorator('repository.admin') + @view_config( + route_name='edit_repo_caches', request_method='POST') + def repo_caches_purge(self): + _ = self.request.translate + c = self.load_default_context() + c.active = 'caches' + + try: + ScmModel().mark_for_invalidation(self.db_repo_name, delete=True) + Session().commit() + h.flash(_('Cache invalidation successful'), + category='success') + except Exception: + log.exception("Exception during cache invalidation") + h.flash(_('An error occurred during cache invalidation'), + category='error') + + raise HTTPFound(h.route_path( + 'edit_repo_caches', repo_name=self.db_repo_name)) \ No newline at end of file diff --git a/rhodecode/config/routing.py b/rhodecode/config/routing.py --- a/rhodecode/config/routing.py +++ b/rhodecode/config/routing.py @@ -708,15 +708,6 @@ def make_map(config): conditions={'method': ['PUT'], 'function': check_repo}, requirements=URL_NAME_REQUIREMENTS) - rmap.connect('edit_repo_caches', '/{repo_name}/settings/caches', - controller='admin/repos', action='edit_caches_form', - conditions={'method': ['GET'], 'function': check_repo}, - requirements=URL_NAME_REQUIREMENTS) - rmap.connect('edit_repo_caches', '/{repo_name}/settings/caches', - controller='admin/repos', action='edit_caches', - conditions={'method': ['PUT'], 'function': check_repo}, - requirements=URL_NAME_REQUIREMENTS) - rmap.connect('edit_repo_remote', '/{repo_name}/settings/remote', controller='admin/repos', action='edit_remote_form', conditions={'method': ['GET'], 'function': check_repo}, diff --git a/rhodecode/controllers/admin/repos.py b/rhodecode/controllers/admin/repos.py --- a/rhodecode/controllers/admin/repos.py +++ b/rhodecode/controllers/admin/repos.py @@ -541,30 +541,6 @@ class ReposController(BaseRepoController @HasRepoPermissionAllDecorator('repository.admin') @auth.CSRFRequired() - def edit_caches(self, repo_name): - """PUT /{repo_name}/settings/caches: invalidate the repo caches.""" - try: - ScmModel().mark_for_invalidation(repo_name, delete=True) - Session().commit() - h.flash(_('Cache invalidation successful'), - category='success') - except Exception: - log.exception("Exception during cache invalidation") - h.flash(_('An error occurred during cache invalidation'), - category='error') - - return redirect(url('edit_repo_caches', repo_name=c.repo_name)) - - @HasRepoPermissionAllDecorator('repository.admin') - def edit_caches_form(self, repo_name): - """GET /repo_name/settings: Form to edit an existing item""" - c.repo_info = self._load_repo(repo_name) - c.active = 'caches' - - return render('admin/repos/repo_edit.mako') - - @HasRepoPermissionAllDecorator('repository.admin') - @auth.CSRFRequired() def edit_remote(self, repo_name): """PUT /{repo_name}/settings/remote: edit the repo remote.""" try: diff --git a/rhodecode/public/js/rhodecode/routes.js b/rhodecode/public/js/rhodecode/routes.js --- a/rhodecode/public/js/rhodecode/routes.js +++ b/rhodecode/public/js/rhodecode/routes.js @@ -98,6 +98,7 @@ function registerRCRoutes() { pyroutes.register('repo_list_data', '/_repos', []); pyroutes.register('goto_switcher_data', '/_goto_data', []); pyroutes.register('edit_repo', '/%(repo_name)s/settings', ['repo_name']); + pyroutes.register('edit_repo_caches', '/%(repo_name)s/settings/caches', ['repo_name']); pyroutes.register('repo_maintenance', '/%(repo_name)s/maintenance', ['repo_name']); pyroutes.register('repo_maintenance_execute', '/%(repo_name)s/maintenance/execute', ['repo_name']); pyroutes.register('strip', '/%(repo_name)s/strip', ['repo_name']); diff --git a/rhodecode/templates/admin/repos/repo_edit.mako b/rhodecode/templates/admin/repos/repo_edit.mako --- a/rhodecode/templates/admin/repos/repo_edit.mako +++ b/rhodecode/templates/admin/repos/repo_edit.mako @@ -58,7 +58,7 @@ ${_('Issue Tracker')}
  • - ${_('Caches')} + ${_('Caches')}
  • %if c.repo_info.repo_type != 'svn':
  • diff --git a/rhodecode/templates/admin/repos/repo_edit_caches.mako b/rhodecode/templates/admin/repos/repo_edit_caches.mako --- a/rhodecode/templates/admin/repos/repo_edit_caches.mako +++ b/rhodecode/templates/admin/repos/repo_edit_caches.mako @@ -3,21 +3,25 @@

    ${_('Invalidate Cache for Repository')}

    - ${h.secure_form(url('edit_repo_caches', repo_name=c.repo_name), method='put')} -
    + +

    ${_('Manually invalidate the repository cache. On the next access a repository cache will be recreated.')}

    + +

    + ${_('Cache purge can be automated by such api call called periodically (in crontab etc)')} +
    + + curl ${h.route_url('apiv2')} -X POST -H 'content-type:text/plain' --data-binary '{"id":1, "auth_token":"SECRET", "method":"invalidate_cache", "args":{"repoid":"${c.repo_info.repo_name}"}}' + +

    + + ${h.secure_form(h.route_path('edit_repo_caches', repo_name=c.repo_name), method='POST')} +
    -

    - ${h.submit('reset_cache_%s' % c.repo_info.repo_name,_('Invalidate repository cache'),class_="btn btn-small",onclick="return confirm('"+_('Confirm to invalidate repository cache')+"');")} -

    -
    - - ${_('Manually invalidate the repository cache. On the next access a repository cache will be recreated.')} - -
    - + ${h.submit('reset_cache_%s' % c.repo_info.repo_name,_('Invalidate repository cache'),class_="btn btn-small",onclick="return confirm('"+_('Confirm to invalidate repository cache')+"');")}
    ${h.end_form()} +
    @@ -25,7 +29,7 @@

    - ${(ungettext('List of repository caches (%(count)s entry)', 'List of repository caches (%(count)s entries)' ,len(c.repo_info.cache_keys)) % {'count': len(c.repo_info.cache_keys)})} + ${(_ungettext('List of repository caches (%(count)s entry)', 'List of repository caches (%(count)s entries)' ,len(c.repo_info.cache_keys)) % {'count': len(c.repo_info.cache_keys)})}