diff pylons_app/model/hg_model.py @ 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 e9a6783f5502
children 7fbf81447c6c
line wrap: on
line diff
--- 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)