changeset 373:3171614c0067

Added permissions check on repo switcher, and cached that for super short cache. repo switcher css updates
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 28 Jul 2010 02:25:47 +0200
parents 1fa58ca0a77e
children 6725742f029a
files pylons_app/lib/base.py pylons_app/model/hg_model.py pylons_app/public/css/style.css pylons_app/templates/base/base.html pylons_app/templates/index.html
diffstat 5 files changed, 31 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/pylons_app/lib/base.py	Wed Jul 28 01:52:12 2010 +0200
+++ b/pylons_app/lib/base.py	Wed Jul 28 02:25:47 2010 +0200
@@ -5,11 +5,12 @@
 from pylons import config, tmpl_context as c, request, session
 from pylons.controllers import WSGIController
 from pylons.templating import render_mako as render
+from pylons_app import __version__
 from pylons_app.lib import auth
 from pylons_app.lib.utils import get_repo_slug
 from pylons_app.model import meta
-from pylons_app.model.hg_model import _get_repos_cached
-from pylons_app import __version__
+from pylons_app.model.hg_model import _get_repos_cached, \
+    _get_repos_switcher_cached
 
 class BaseController(WSGIController):
     
@@ -18,6 +19,7 @@
         c.hg_app_name = config['hg_app_name']
         c.repo_name = get_repo_slug(request)
         c.cached_repo_list = _get_repos_cached()
+        c.repo_switcher_list = _get_repos_switcher_cached(c.cached_repo_list)
         self.sa = meta.Session
     
     def __call__(self, environ, start_response):
--- a/pylons_app/model/hg_model.py	Wed Jul 28 01:52:12 2010 +0200
+++ b/pylons_app/model/hg_model.py	Wed Jul 28 02:25:47 2010 +0200
@@ -2,7 +2,7 @@
 # encoding: utf-8
 # Model for hg app
 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
- 
+# 
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
 # as published by the Free Software Foundation; version 2
@@ -25,10 +25,12 @@
 from beaker.cache import cache_region
 from mercurial import ui
 from mercurial.hgweb.hgwebdir_mod import findrepos
-from vcs.exceptions import RepositoryError, VCSError
+from pylons.i18n.translation import _
+from pylons_app.lib.auth import HasRepoPermissionAny
 from pylons_app.model import meta
 from pylons_app.model.db import Repository
 from sqlalchemy.orm import joinedload
+from vcs.exceptions import RepositoryError, VCSError
 import logging
 import os
 import sys
@@ -56,6 +58,15 @@
     from pylons import app_globals as g
     return HgModel.repo_scan(g.paths[0][0], g.paths[0][1], g.baseui)
 
+@cache_region('super_short_term', 'cached_repos_switcher_list')
+def _get_repos_switcher_cached(cached_repo_list):
+    repos_lst = []
+    for repo in sorted(x.name.lower() for x in cached_repo_list.values()):
+        if HasRepoPermissionAny('repository.write', 'repository.read', 'repository.admin')(repo, 'main page check'):
+            repos_lst.append(repo)
+    
+    return repos_lst
+
 @cache_region('long_term', 'full_changelog')
 def _full_changelog_cached(repo_name):
     log.info('getting full changelog for %s', repo_name)
--- a/pylons_app/public/css/style.css	Wed Jul 28 01:52:12 2010 +0200
+++ b/pylons_app/public/css/style.css	Wed Jul 28 02:25:47 2010 +0200
@@ -3197,6 +3197,15 @@
 }
 
 /* -----------------------------------------------------------
+    REPO SWITCHER
+----------------------------------------------------------- */
+
+#switch_repos{
+	position: absolute;
+	height: 25px;
+	z-index: 1;
+}
+/* -----------------------------------------------------------
     BREADCRUMBS
 ----------------------------------------------------------- */
 
--- a/pylons_app/templates/base/base.html	Wed Jul 28 01:52:12 2010 +0200
+++ b/pylons_app/templates/base/base.html	Wed Jul 28 02:25:47 2010 +0200
@@ -91,15 +91,13 @@
                     }
                     else{
                         YAHOO.util.Dom.setStyle('switch_repos','display','');
-                        //YAHOO.util.Dom.setStyle('repo_switcher','background','#FFFFFF');
-                        //YAHOO.util.Dom.setStyle('repo_switcher','color','#556CB5');
                         YAHOO.util.Dom.addClass('repo_switcher','selected');
                     }
                     });
                 YAHOO.util.Event.addListener('repos_list','change',function(e){
                     var wa = YAHOO.util.Dom.get('repos_list').value;
                     
-                    var url = "${h.url('summary_home',repo_name='__REPLACE__')}".replace('__REPLACE__',wa);
+                    var url = "${h.url('summary_home',repo_name='__REPO__')}".replace('__REPO__',wa);
                     window.location = url;
                 })
                });
@@ -115,9 +113,9 @@
                     </span>
                     <span>&darr;</span>					
 					</a>
-					<div id="switch_repos" style="display:none;position: absolute;height: 25px;z-index: 1">
-						<select id="repos_list" size="=10" style="min-width: 150px">
-						%for repo in sorted(x.name.lower() for x in c.cached_repo_list.values()):
+					<div id="switch_repos" style="display:none;">
+						<select id="repos_list" size="10">
+						%for repo in c.repo_switcher_list:
 							<option value="${repo}">${repo}</option>
 						%endfor
 						</select>
--- a/pylons_app/templates/index.html	Wed Jul 28 01:52:12 2010 +0200
+++ b/pylons_app/templates/index.html	Wed Jul 28 02:25:47 2010 +0200
@@ -51,7 +51,7 @@
             </thead>
                         <tbody>
 					    %for cnt,repo in enumerate(c.repos_list):
-					        %if h.HasRepoPermissionAny('repository.write','repository.read','repository.admin')(repo['name'],'main page check'):
+					        %if repo['name'] in c.repo_switcher_list:
 					        <tr class="parity${cnt%2}">
 					            <td>
 					             %if repo['repo'].dbrepo.private: