Permalink
Browse files

Minor fixes

  • Loading branch information...
1 parent 888f598 commit 3b5fc5ad2c852cf7beba1020779d48a06ffaae26 @lexqt committed May 11, 2012
View
@@ -612,7 +612,7 @@ def get_data(db):
((0, 'Global admin syllabus', 'Global syllabus record for administration'),)),
('metagroups',
('id', 'name', 'year', 'active'),
- ((0, 'Global admin meagroup', 3000, True),)),
+ ((0, 'Global admin metagroup', 3000, True),)),
('metagroup_syllabus_rel',
('metagroup_id', 'syllabus_id'),
((0, 0),)),
View
@@ -99,12 +99,13 @@ def get_user_roles(self, username):
if cursor.rowcount:
roles.append(UserRole.ADMIN)
- return [(r, UserRole.label(r)) for r in roles]
+ return roles
- def get_user_projects(self, username, role=UserRole.DEVELOPER, pid_only=False):
+ def get_user_projects(self, username, role=UserRole.DEVELOPER, with_names=False):
db = self.env.get_read_db()
cursor = db.cursor()
+ # TODO: do not query name if not with_names
if role == UserRole.DEVELOPER:
query = '''
SELECT project_id, project_name
@@ -127,7 +128,7 @@ def get_user_projects(self, username, role=UserRole.DEVELOPER, pid_only=False):
cursor.execute(query, (username,))
projects = cursor.fetchall()
- if not pid_only:
+ if with_names:
return projects
return [r[0] for r in projects]
@@ -309,12 +310,12 @@ def has_role(self, username, role, obj_id=None):
return role in self.get_user_roles(username)
if role == UserRole.DEVELOPER:
# TODO: make it more efficient...
- return obj_id in self.get_user_projects(username, role, pid_only=True)
+ return obj_id in self.get_user_projects(username, role)
elif role == UserRole.GROUP_MANAGER:
return self.has_group_manager(username, obj_id)
elif role == UserRole.PROJECT_MANAGER:
# TODO: make it more efficient...
- return obj_id in self.get_user_projects(username, UserRole.MANAGER, pid_only=True)
+ return obj_id in self.get_user_projects(username, UserRole.MANAGER)
return False
View
@@ -208,16 +208,17 @@ def process_request(self, req):
def step_preprocess(step):
if step == STEP_SET_ROLE:
- data['roles'] = self.pm.get_user_roles(req.authname)
- if not data['roles']:
+ roles = self.pm.get_user_roles(req.authname)
+ if not roles:
raise TracError(tag(tag_(
'User has no roles. Can not continue login.'
' You may %(logout)s to continue work as anonymous user.',
logout=tag.a(_('logout'), href=req.href.logout())
)))
+ data['roles'] = [(r, UserRole.label(r)) for r in roles]
elif step == STEP_SET_PROJECT:
role = int(s['role'])
- data['projects'] = self.pm.get_user_projects(req.authname, role)
+ data['projects'] = self.pm.get_user_projects(req.authname, role, with_names=True)
if 'project' not in req.args:
prev_project_id = s.get('project')
data['prev_project'] = int(prev_project_id) if prev_project_id is not None else None
@@ -363,7 +363,7 @@ def pre_process_request(self, req, handler):
# TODO: what about user role?
req.data['role'] = None
for role in (UserRole.DEVELOPER, UserRole.MANAGER):
- pids = self.pm.get_user_projects(req.authname, role=role, pid_only=True)
+ pids = self.pm.get_user_projects(req.authname, role)
if pid in pids:
req.data['role'] = role
self.ps.set_request_data(req, pid)
@@ -207,7 +207,7 @@ def render_admin_panel(self, req, category, page, path_info, area, area_id):
all_repos.update(rm.get_all_repositories(project_id=project_id))
if not projects:
- projects = pm.get_user_projects(req.authname, role)
+ projects = pm.get_user_projects(req.authname, role, with_names=True)
db_provider = self.env[DbRepositoryProvider]
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
#
+# Copyright (C) 2012 Aleksey A. Porfirov
# Copyright (C)2005-2009 Edgewall Software
# Copyright (C) 2005 Christopher Lenz <cmlenz@gmx.de>
# All rights reserved.
@@ -18,7 +19,7 @@
import time
from trac.admin import AdminCommandError, IAdminCommandProvider, get_dir_list
-from trac.config import ListOption, Option
+from trac.config import ListOption, Option, OrderedExtensionsOption
from trac.core import *
from trac.resource import IResourceManager, Resource, ResourceNotFound
from trac.util.concurrency import threading
@@ -309,7 +310,9 @@ class RepositoryManager(Component):
implements(IRequestFilter, IResourceManager)
connectors = ExtensionPoint(IRepositoryConnector)
- providers = ExtensionPoint(IRepositoryProvider)
+ providers = OrderedExtensionsOption('trac', 'repository_provider', IRepositoryProvider,
+ 'DbRepositoryProvider', include_missing=False,
+ doc='IRepositoryProvider extension list')
change_listeners = ExtensionPoint(IRepositoryChangeListener)
repository_type = Option('trac', 'repository_type', 'svn',
@@ -499,7 +502,7 @@ def get_realm_id(self, realm):
# not used
def get_repositories(self):
- """Retrieve repositories specified in TracIni.
+ """NOT USED. Retrieve repositories specified in TracIni.
The `[repositories]` section can be used to specify a list
of repositories.
@@ -228,7 +228,14 @@ def make_ticket_comment(self, repos, changeset):
def _update_tickets(self, tickets, changeset, comment, date):
"""Update the tickets with the given comment."""
- pids = self.pm.get_user_projects(changeset.author, pid_only=True)
+ roles = self.pm.get_user_roles(changeset.author)
+ if not roles:
+ self.log.info("Updating tickets canceled because changeset author "
+ "has no user roles in the system")
+ return
+ pids = set()
+ for role in roles:
+ pids |= set(self.pm.get_user_projects(changeset.author, role))
rpid = changeset.repos.pid
perm = PermissionCache(self.env, changeset.author)
for tkt_id, cmds in tickets.iteritems():
@@ -245,13 +252,13 @@ def do_update(db):
(tkt_id, rpid, pid))
ticket[0] = None
return
- syllabus_id = self.pm.get_project_syllabus(pid)
if pid not in pids:
self.log.warn("Updating ticket #%d canceled: user %s is not a developer in project #%d" %
(tkt_id, changeset.author, pid))
ticket[0] = None
return
refs_done = False
+ syllabus_id = self.pm.get_project_syllabus(pid)
allow_commands = self.allow_commands.syllabus(syllabus_id)
all_refs = self.all_refs.syllabus(syllabus_id)
for cmd in cmds:

0 comments on commit 3b5fc5a

Please sign in to comment.