def refresh_repo(self, *repo_path): # post-commit hooks use this if not repo_path: return 'No repo specified' repo_path = '/' + '/'.join(repo_path) project, rest = h.find_project(repo_path) if project is None: return 'No project at %s' % repo_path if not rest: return '%s does not include a repo mount point' % repo_path h.set_context(project.shortname, rest[0], neighborhood=project.neighborhood) if c.app is None or not getattr(c.app, 'repo'): return 'Cannot find repo at %s' % repo_path allura.tasks.repo_tasks.refresh.post() return '%r refresh queued.\n' % c.app.repo
def parse_address(addr): userpart, domain = addr.split("@") # remove common domain suffix if not domain.endswith(config.common_suffix): raise exc.AddressException, "Unknown domain: " + domain domain = domain[: -len(config.common_suffix)] path = "/".join(reversed(domain.split("."))) project, mount_point = h.find_project("/" + path) if project is None: raise exc.AddressException, "Unknown project: " + domain if len(mount_point) != 1: raise exc.AddressException, "Unknown tool: " + domain with h.push_config(c, project=project): app = project.app_instance(mount_point[0]) if not app: raise exc.AddressException, "Unknown tool: " + domain return userpart, project, app
def parse_address(addr): userpart, domain = addr.split('@') # remove common domain suffix if not domain.endswith(config.common_suffix): raise exc.AddressException, 'Unknown domain: ' + domain domain = domain[:-len(config.common_suffix)] path = '/'.join(reversed(domain.split('.'))) project, mount_point = h.find_project('/' + path) if project is None: raise exc.AddressException, 'Unknown project: ' + domain if len(mount_point) != 1: raise exc.AddressException, 'Unknown tool: ' + domain with h.push_config(c, project=project): app = project.app_instance(mount_point[0]) if not app: raise exc.AddressException, 'Unknown tool: ' + domain return userpart, project, app
def repo_permissions(self, repo_path=None, username=None, **kw): """Expects repo_path to be a filesystem path like <tool>/<project>.<neighborhood>/reponame[.git] unless the <neighborhood> is 'p', in which case it is <tool>/<project>/reponame[.git] Returns JSON describing this user's permissions on that repo. """ disallow = dict(allow_read=False, allow_write=False, allow_create=False) # Find the user user = M.User.by_username(username) if not user: response.status = 404 return dict(disallow, error='unknown user') if not repo_path: return dict(allow_write=self._auth_repos(user)) parts = [p for p in repo_path.split(os.path.sep) if p] # strip the tool name parts = parts[1:] if '.' in parts[0]: project, neighborhood = parts[0].split('.') else: project, neighborhood = parts[0], 'p' parts = [neighborhood, project] + parts[1:] project_path = '/' + '/'.join(parts) project, rest = h.find_project(project_path) if project is None: log.info("Can't find project at %s from repo_path %s", project_path, repo_path) response.status = 404 return dict(disallow, error='unknown project') c.project = project c.app = project.app_instance(rest[0]) if not c.app: c.app = project.app_instance(os.path.splitext(rest[0])[0]) if c.app is None: log.info("Can't find repo at %s on repo_path %s", rest[0], repo_path) return disallow return dict(allow_read=has_access(c.app, 'read')(user=user), allow_write=has_access(c.app, 'write')(user=user), allow_create=has_access(c.app, 'create')(user=user))
def parse_address(addr): userpart, domain = addr.split('@') # remove common domain suffix for suffix in [config.common_suffix] + aslist(config.common_suffix_alt): if domain.endswith(suffix): domain = domain[:-len(suffix)] break else: raise exc.AddressException, 'Unknown domain: ' + domain path = '/'.join(reversed(domain.split('.'))) project, mount_point = h.find_project('/' + path) if project is None: raise exc.AddressException, 'Unknown project: ' + domain if len(mount_point) != 1: raise exc.AddressException, 'Unknown tool: ' + domain with h.push_config(c, project=project): app = project.app_instance(mount_point[0]) if not app: raise exc.AddressException, 'Unknown tool: ' + domain return userpart, project, app
def test_find_project(): proj, rest = h.find_project('/p/test/foo') assert_equals(proj.shortname, 'test') assert_equals(proj.neighborhood.name, 'Projects') proj, rest = h.find_project('/p/testable/foo') assert proj is None
def push_upstream_context(self): project, rest = h.find_project(self.upstream_repo.name) with h.push_context(project._id): app = project.app_instance(rest[0]) return h.push_context(project._id, app_config_id=app.config._id)
def push_upstream_context(self): project, rest=h.find_project(self.upstream_repo.name) with h.push_context(project._id): app = project.app_instance(rest[0]) return h.push_context(project._id, app_config_id=app.config._id)
def test_find_project(): proj, rest = h.find_project("/p/test/foo") assert_equals(proj.shortname, "test") assert_equals(proj.neighborhood.name, "Projects") proj, rest = h.find_project("/p/testable/foo") assert proj is None