Changeset - 3171614c0067
[Not reviewed]
default
0 5 0
Marcin Kuzminski - 15 years ago 2010-07-28 02:25:47
marcin@python-works.com
Added permissions check on repo switcher,
and cached that for super short cache.
repo switcher css updates
5 files changed with 31 insertions and 11 deletions:
0 comments (0 inline, 0 general)
pylons_app/lib/base.py
Show inline comments
 
@@ -2,25 +2,27 @@
 

	
 
Provides the BaseController class for subclassing.
 
"""
 
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):
 
    
 
    def __before__(self):
 
        c.hg_app_version = __version__
 
        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):
 
        """Invoke the Controller"""
 
        # WSGIController.__call__ dispatches to the Controller method
 
        # the request is routed to. This routing information is
pylons_app/model/hg_model.py
Show inline comments
 
#!/usr/bin/env python
 
# 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
 
# of the License or (at your opinion) any later version of the license.
 
# 
 
# This program is distributed in the hope that it will be useful,
 
@@ -22,16 +22,18 @@ 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
 
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
 
log = logging.getLogger(__name__)
 

	
 
try:
 
@@ -53,12 +55,21 @@ def _get_repos_cached():
 
    return cached dict with repos
 
    """
 
    log.info('getting all repositories list')
 
    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)
 
    return list(reversed(list(HgModel().get_repo(repo_name))))
 

	
 
class HgModel(object):
pylons_app/public/css/style.css
Show inline comments
 
@@ -3194,12 +3194,21 @@ table.code-browser .browser-dir {
 
    border: 0px;
 
    font-style: italic;
 
    cursor: pointer;
 
}
 
 
/* -----------------------------------------------------------
 
    REPO SWITCHER
 
----------------------------------------------------------- */
 
 
#switch_repos{
 
	position: absolute;
 
	height: 25px;
 
	z-index: 1;
 
}
 
/* -----------------------------------------------------------
 
    BREADCRUMBS
 
----------------------------------------------------------- */
 
 
.breadcrumbs{
 
	border:medium none;
 
	color:#FFFFFF;
pylons_app/templates/base/base.html
Show inline comments
 
@@ -88,21 +88,19 @@
 
                        YAHOO.util.Dom.setStyle('repo_switcher','background','');
 
                        YAHOO.util.Dom.removeClass('repo_switcher','selected');
 
                        YAHOO.util.Dom.get('repo_switcher').removeAttribute('style');
 
                    }
 
                    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;
 
                })
 
               });
 
            </script>
 
            		
 
		   ##REGULAR MENU            
 
@@ -112,15 +110,15 @@
 
					<a id="repo_switcher" title="${_('Switch repository')}" href="#">
 
                    <span class="icon">
 
                        <img src="/images/icons/database.png" alt="${_('Products')}" />
 
                    </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>
 
					</div>			
 
				</li>
 
				
pylons_app/templates/index.html
Show inline comments
 
@@ -48,13 +48,13 @@
 
			        <th class="left">${_('RSS')}</th>
 
			        <th class="left">${_('Atom')}</th>
 
	            </tr>
 
            </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:
 
					                <img alt="${_('private')}" src="/images/icons/lock.png"/>
 
					             %else:
 
					                <img alt="${_('public')}" src="/images/icons/lock_open.png"/>
0 comments (0 inline, 0 general)