class TracForgeLoginModule(LoginModule): """Replacement for LoginModule to slave to another environment.""" master_path = Option('tracforge', 'master_path', doc='Path to master Trac') master_env = property(lambda self: open_environment(self.master_path)) master_href = property(lambda self: Href(self.master_env.base_url)) # INavigationContributor methods def get_active_navigation_item(self, req): return 'login' def get_navigation_items(self, req): if req.authname and req.authname != 'anonymous': yield ('metanav', 'login', 'logged in as %s' % req.authname) yield ('metanav', 'logout', html.A('Logout', href=self.master_href.logout( referer=req.href(req.path_info)))) else: yield ('metanav', 'login', html.A('Login', href=self.master_href.login( referer=req.href(req.path_info)))) # Internal methods def _get_name_for_cookie(self, req, cookie): return LoginModule(self.master_env)._get_name_for_cookie(req, cookie)
def match_request(self, req): if req.path_info.startswith('/projects'): path_info = req.path_info[10:] if path_info: self.log.debug('TracForgeDispatch: Starting WSGI relaunch for %s (%s)', path_info, req.method) project = path_info.split('/', 1)[0] # Check that we aren't trying to recurse (possible link loop) if project == os.path.basename(self.env.path): req.redirect(req.href()) # Assert permissions on the desination environment try: project_env = open_environment(os.path.join(os.path.dirname(self.env.path), project)) except IOError: raise TracError('No such project "%s"'%project) authname = RequestDispatcher(self.env).authenticate(req) project_perm = PermissionCache(project_env, authname) project_perm.assert_permission('PROJECT_VIEW') self.log.debug('TracForgeDispath: Access granted, running relaunch') self.log.debug('TracForgeDispatch: Status of req.args is %r', req.__dict__.get('args', 'NOT FOUND')) #self.log.debug('TracForgeDispatch: wsgi.input contains %s', req.read()) self._send_project(req, path_info) self.log.debug('TracForgeDispatch: Relaunch completed, terminating request') self.log.debug('TracForgeDispatch: Response was %r', req._response) req._tf_print = True raise RequestDone, 'request done'
def _get_env(self): if not self._env: assert self.exists, "Can't use a non-existant project" try: self._env = open_environment(self.env_path) self._valid = True except Exception, e: self._env = BadEnv(self.env_path, e)
def __open_environment(env_path, run_once=False): if run_once: return open_environment(env_path) global env_cache, env_cache_lock env = None env_cache_lock.acquire() try: if not env_path in env_cache: env_cache[env_path] = open_environment(env_path) env = env_cache[env_path] finally: env_cache_lock.release() # Re-parse the configuration file if it changed since the last the time it # was parsed env.config.parse_if_needed() return env
def _send_index(self, environ, start_response): projects = [] for env_name in os.listdir(self.path): env_path = os.path.join(self.path, env_name) try: env = open_environment(env_path) env_perm = PermissionCache(PermissionSystem(env).get_user_permissions(environ.get("REMOTE_USER", "anonymous"))) if env_perm.has_permission('WIKI_VIEW'): projects.append({ 'name': env.project_name, 'description': env.project_description, # XXX: get rid of the double / in the beginning 'href': construct_url(environ, path_info="/"+env_name), }) except Exception: pass projects.sort(lambda x, y: cmp(x['name'].lower(), y['name'].lower())) start_response("200 OK", [('content-type', 'text/html')]) return self.template.render({"projects":projects}, format='xhtml', template = "wsgiplugin.index")
def process_request(self, req): parent_dir = os.path.dirname(self.env.path) #env_paths = dict([(filename, os.path.join(parent_dir, filename)) # for filename in os.listdir(parent_dir)]) projects = [] for env_name in os.listdir(parent_dir): env_path = os.path.join(parent_dir, env_name) # Don't list this environment if env_path == self.env.path: continue try: env = open_environment(env_path) try: #self.log.debug(env.path) env_perm = PermissionCache(env, req.authname) #self.log.debug(env_perm.perms) if env_perm.has_permission('PROJECT_VIEW'): projects.append({ 'name': env.project_name, 'description': env.project_description, 'href': req.href.projects(env_name), }) except Exception, e: # Only show errors to admins to prevent excessive disclosure if req.perm.has_permission('TRACFORGE_ADMIN'): projects.append({ 'name': env.project_name, 'description': to_unicode(e) }) except Exception, e: if req.perm.has_permission('TRACFORGE_ADMIN'): projects.append({ 'name': env_path, 'description': to_unicode(e), })
def process_request(self, req): raise TracError('How did I get here?') path_info = req.path_info[10:] if path_info: project = path_info.split('/', 1)[0] # Check that we aren't trying to recurse (possible link loop) if project == os.path.basename(self.env.path): req.redirect(req.href()) # Assert permissions on the desination environment project_path = os.path.join(os.path.dirname(self.env.path), project) try: project_env = open_environment(project_path) except IOError: raise TracError('No such project "%s" at %s'% (project,project_path)) project_perm = PermissionCache(project_env, req.authname) project_perm.assert_permission('PROJECT_VIEW') return self._send_project(req, path_info) else: return self._send_index(req)
def accessor(self, *args, **kwords): val = super(EnvironmentOption, self).accessor(*args, **kwords) assert val, 'You must configure a valid Trac environment path for [%s] %s' % ( self.section, self.name) return open_environment(val)
def accessor(self, *args, **kwords): val = super(EnvironmentOption, self).accessor(*args, **kwords) assert val, "You must configure a valid Trac environment path for [%s] %s" % (self.section, self.name) return open_environment(val)