##// END OF EJS Templates
Added permissions check on repo switcher,...
marcink -
r373:3171614c default
parent child Browse files
Show More
@@ -5,11 +5,12 b' Provides the BaseController class for su'
5 from pylons import config, tmpl_context as c, request, session
5 from pylons import config, tmpl_context as c, request, session
6 from pylons.controllers import WSGIController
6 from pylons.controllers import WSGIController
7 from pylons.templating import render_mako as render
7 from pylons.templating import render_mako as render
8 from pylons_app import __version__
8 from pylons_app.lib import auth
9 from pylons_app.lib import auth
9 from pylons_app.lib.utils import get_repo_slug
10 from pylons_app.lib.utils import get_repo_slug
10 from pylons_app.model import meta
11 from pylons_app.model import meta
11 from pylons_app.model.hg_model import _get_repos_cached
12 from pylons_app.model.hg_model import _get_repos_cached, \
12 from pylons_app import __version__
13 _get_repos_switcher_cached
13
14
14 class BaseController(WSGIController):
15 class BaseController(WSGIController):
15
16
@@ -18,6 +19,7 b' class BaseController(WSGIController):'
18 c.hg_app_name = config['hg_app_name']
19 c.hg_app_name = config['hg_app_name']
19 c.repo_name = get_repo_slug(request)
20 c.repo_name = get_repo_slug(request)
20 c.cached_repo_list = _get_repos_cached()
21 c.cached_repo_list = _get_repos_cached()
22 c.repo_switcher_list = _get_repos_switcher_cached(c.cached_repo_list)
21 self.sa = meta.Session
23 self.sa = meta.Session
22
24
23 def __call__(self, environ, start_response):
25 def __call__(self, environ, start_response):
@@ -2,7 +2,7 b''
2 # encoding: utf-8
2 # encoding: utf-8
3 # Model for hg app
3 # Model for hg app
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
5
5 #
6 # This program is free software; you can redistribute it and/or
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; version 2
8 # as published by the Free Software Foundation; version 2
@@ -25,10 +25,12 b' Model for hg app'
25 from beaker.cache import cache_region
25 from beaker.cache import cache_region
26 from mercurial import ui
26 from mercurial import ui
27 from mercurial.hgweb.hgwebdir_mod import findrepos
27 from mercurial.hgweb.hgwebdir_mod import findrepos
28 from vcs.exceptions import RepositoryError, VCSError
28 from pylons.i18n.translation import _
29 from pylons_app.lib.auth import HasRepoPermissionAny
29 from pylons_app.model import meta
30 from pylons_app.model import meta
30 from pylons_app.model.db import Repository
31 from pylons_app.model.db import Repository
31 from sqlalchemy.orm import joinedload
32 from sqlalchemy.orm import joinedload
33 from vcs.exceptions import RepositoryError, VCSError
32 import logging
34 import logging
33 import os
35 import os
34 import sys
36 import sys
@@ -56,6 +58,15 b' def _get_repos_cached():'
56 from pylons import app_globals as g
58 from pylons import app_globals as g
57 return HgModel.repo_scan(g.paths[0][0], g.paths[0][1], g.baseui)
59 return HgModel.repo_scan(g.paths[0][0], g.paths[0][1], g.baseui)
58
60
61 @cache_region('super_short_term', 'cached_repos_switcher_list')
62 def _get_repos_switcher_cached(cached_repo_list):
63 repos_lst = []
64 for repo in sorted(x.name.lower() for x in cached_repo_list.values()):
65 if HasRepoPermissionAny('repository.write', 'repository.read', 'repository.admin')(repo, 'main page check'):
66 repos_lst.append(repo)
67
68 return repos_lst
69
59 @cache_region('long_term', 'full_changelog')
70 @cache_region('long_term', 'full_changelog')
60 def _full_changelog_cached(repo_name):
71 def _full_changelog_cached(repo_name):
61 log.info('getting full changelog for %s', repo_name)
72 log.info('getting full changelog for %s', repo_name)
@@ -3197,6 +3197,15 b' table.code-browser .browser-dir {'
3197 }
3197 }
3198
3198
3199 /* -----------------------------------------------------------
3199 /* -----------------------------------------------------------
3200 REPO SWITCHER
3201 ----------------------------------------------------------- */
3202
3203 #switch_repos{
3204 position: absolute;
3205 height: 25px;
3206 z-index: 1;
3207 }
3208 /* -----------------------------------------------------------
3200 BREADCRUMBS
3209 BREADCRUMBS
3201 ----------------------------------------------------------- */
3210 ----------------------------------------------------------- */
3202
3211
@@ -91,15 +91,13 b''
91 }
91 }
92 else{
92 else{
93 YAHOO.util.Dom.setStyle('switch_repos','display','');
93 YAHOO.util.Dom.setStyle('switch_repos','display','');
94 //YAHOO.util.Dom.setStyle('repo_switcher','background','#FFFFFF');
95 //YAHOO.util.Dom.setStyle('repo_switcher','color','#556CB5');
96 YAHOO.util.Dom.addClass('repo_switcher','selected');
94 YAHOO.util.Dom.addClass('repo_switcher','selected');
97 }
95 }
98 });
96 });
99 YAHOO.util.Event.addListener('repos_list','change',function(e){
97 YAHOO.util.Event.addListener('repos_list','change',function(e){
100 var wa = YAHOO.util.Dom.get('repos_list').value;
98 var wa = YAHOO.util.Dom.get('repos_list').value;
101
99
102 var url = "${h.url('summary_home',repo_name='__REPLACE__')}".replace('__REPLACE__',wa);
100 var url = "${h.url('summary_home',repo_name='__REPO__')}".replace('__REPO__',wa);
103 window.location = url;
101 window.location = url;
104 })
102 })
105 });
103 });
@@ -115,9 +113,9 b''
115 </span>
113 </span>
116 <span>&darr;</span>
114 <span>&darr;</span>
117 </a>
115 </a>
118 <div id="switch_repos" style="display:none;position: absolute;height: 25px;z-index: 1">
116 <div id="switch_repos" style="display:none;">
119 <select id="repos_list" size="=10" style="min-width: 150px">
117 <select id="repos_list" size="10">
120 %for repo in sorted(x.name.lower() for x in c.cached_repo_list.values()):
118 %for repo in c.repo_switcher_list:
121 <option value="${repo}">${repo}</option>
119 <option value="${repo}">${repo}</option>
122 %endfor
120 %endfor
123 </select>
121 </select>
@@ -51,7 +51,7 b''
51 </thead>
51 </thead>
52 <tbody>
52 <tbody>
53 %for cnt,repo in enumerate(c.repos_list):
53 %for cnt,repo in enumerate(c.repos_list):
54 %if h.HasRepoPermissionAny('repository.write','repository.read','repository.admin')(repo['name'],'main page check'):
54 %if repo['name'] in c.repo_switcher_list:
55 <tr class="parity${cnt%2}">
55 <tr class="parity${cnt%2}">
56 <td>
56 <td>
57 %if repo['repo'].dbrepo.private:
57 %if repo['repo'].dbrepo.private:
General Comments 0
You need to be logged in to leave comments. Login now