changeset 368:e9a6783f5502

fixed user permissions bug when adding permissions to user who couldn load those because of auth decorators Small fix for hg model and injecting dbrepo into cached repos
author Marcin Kuzminski <marcin@python-works.com>
date Tue, 27 Jul 2010 14:54:41 +0200
parents a26f48ad7a8a
children 38736d60c527
files pylons_app/lib/base.py pylons_app/model/hg_model.py
diffstat 2 files changed, 12 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/pylons_app/lib/base.py	Tue Jul 27 14:53:22 2010 +0200
+++ b/pylons_app/lib/base.py	Tue Jul 27 14:54:41 2010 +0200
@@ -17,7 +17,6 @@
         c.hg_app_version = __version__
         c.hg_app_name = config['hg_app_name']
         c.repo_name = get_repo_slug(request)
-        c.hg_app_user = auth.get_user(session)
         c.cached_repo_list = _get_repos_cached()
         self.sa = meta.Session
     
@@ -27,6 +26,8 @@
         # the request is routed to. This routing information is
         # available in environ['pylons.routes_dict']
         try:
+            #putting this here makes sure that we update permissions every time
+            c.hg_app_user = auth.get_user(session)
             return WSGIController.__call__(self, environ, start_response)
         finally:
             meta.Session.remove()
--- a/pylons_app/model/hg_model.py	Tue Jul 27 14:53:22 2010 +0200
+++ b/pylons_app/model/hg_model.py	Tue Jul 27 14:54:41 2010 +0200
@@ -17,13 +17,11 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # MA  02110-1301, USA.
-
 """
 Created on April 9, 2010
 Model for hg app
 @author: marcink
 """
-
 from beaker.cache import cache_region
 from mercurial import ui
 from mercurial.hgweb.hgwebdir_mod import findrepos
@@ -42,12 +40,12 @@
     sys.stderr.write('You have to import vcs module')
     raise Exception('Unable to import vcs')
 
-def _get_repos_cached_initial(app_globals):
+def _get_repos_cached_initial(app_globals, initial):
     """
     return cached dict with repos
     """
     g = app_globals
-    return HgModel.repo_scan(g.paths[0][0], g.paths[0][1], g.baseui)
+    return HgModel.repo_scan(g.paths[0][0], g.paths[0][1], g.baseui, initial)
 
 @cache_region('long_term', 'cached_repo_list')
 def _get_repos_cached():
@@ -74,7 +72,7 @@
         """
     
     @staticmethod
-    def repo_scan(repos_prefix, repos_path, baseui):
+    def repo_scan(repos_prefix, repos_path, baseui, initial=False):
         """
         Listing of repositories in given path. This path should not be a 
         repository itself. Return a dictionary of repository objects
@@ -115,8 +113,14 @@
                     
                     repos_list[name] = MercurialRepository(path, baseui=baseui)
                     repos_list[name].name = name
-                    dbrepo = sa.query(Repository).get(name)
+                    
+                    dbrepo = None
+                    if not initial:
+                        dbrepo = sa.query(Repository)\
+                            .filter(Repository.repo_name == name).scalar()
+                            
                     if dbrepo:
+                        log.info('Adding db instance to cached list')
                         repos_list[name].dbrepo = dbrepo
                         repos_list[name].description = dbrepo.description
                         repos_list[name].contact = dbrepo.user.full_contact