Esempio n. 1
0
    def add(self, req, path, templatevars):
        base_url = options.url_path('base_url_submin')
        reposname = ''

        if req.post and req.post['repository']:
            import re

            reposname = req.post.get('repository').strip()
            if re.findall('[^a-zA-Z0-9_-]', reposname):
                return self.showAddForm(
                    req, reposname, 'Invalid characters in repository name')

            if "vcs" not in req.post or req.post.get("vcs").strip() == "":
                return self.showAddForm(
                    req, reposname,
                    "No repository type selected. Please select a repository type."
                )

            vcs_type = req.post.get("vcs").strip()

            if reposname == '':
                return self.showAddForm(req, reposname,
                                        'Repository name not supplied')

            if vcs_type not in vcs_list():
                return self.showAddForm(req, reposname,
                                        "Invalid repository type supplied.")

            try:
                a = Repository(reposname, vcs_type)
                return self.showAddForm(
                    req, reposname, 'Repository %s already exists' % reposname)
            except DoesNotExistError:
                pass

            try:
                asking_user = user.User(req.session['user']['name'])
                Repository.add(vcs_type, reposname, asking_user)
            except PermissionError as e:
                return ErrorResponse('could not create repository',
                                     request=req,
                                     details=str(e))

            url = '%s/repositories/show/%s/%s' % (base_url, vcs_type,
                                                  reposname)
            return Redirect(url, req)

        return self.showAddForm(req, reposname)
Esempio n. 2
0
	def listRepositories(self, req):
		try:
			repos = Repository.list(user.User(req.session['user']['name']))
			variables = {'repositories': repos}
			return XMLTemplateResponse("ajax/listrepositories.xml", variables)
		except Exception as e:
			raise
			return XMLStatusResponse('listRepositories', False, 'Failed to get a list: %s' % e)
Esempio n. 3
0
    def show(self, req, vcs_type, path, templatevars):
        import os.path

        u = user.User(req.session['user']['name'])
        try:
            repos = Repository(path[0], vcs_type)

            # Lie if user has no permission to read
            if not u.is_admin and not repository.userHasReadPermissions(
                    u.name, path[0], vcs_type):
                raise DoesNotExistError
        except DoesNotExistError:
            return ErrorResponse('This repository does not exist.',
                                 request=req)

        trac_enabled = options.value('enabled_trac', 'no') != 'no'

        if trac_enabled:
            templatevars['trac_config_ok'] = True
            templatevars['trac_exists'] = False
            try:
                if trac.exists(path[0]):
                    templatevars['trac_exists'] = True
            except MissingConfig as e:
                templatevars['trac_config_ok'] = False
                templatevars['trac_msg'] = \
                 'There is something missing in your config: %s' % str(e)

            trac_base_url = options.url_path('base_url_trac')
            trac_http_url = str(trac_base_url + repos.name)
            templatevars['trac_http_url'] = trac_http_url

        try:
            vcs_url = repos.url()
        except MissingConfig as e:
            vcs_url = ""
            templatevars['vcs_url_error'] = str(e)

        templatevars['vcs_url'] = vcs_url
        templatevars['repository'] = repos
        templatevars['vcs_type'] = vcs_type
        formatted = evaluate_main('repositories.html',
                                  templatevars,
                                  request=req)
        return Response(formatted)
Esempio n. 4
0
    def ajaxhandler(self, req, path):
        reposname = ''

        if len(path) < 3:
            return XMLStatusResponse('', False, 'Invalid path')

        action = path[0]
        vcs_type = path[1]
        reposname = path[2]

        repos = None
        try:
            repos = Repository(reposname, vcs_type)
        except (IndexError, DoesNotExistError):
            return XMLStatusResponse(
                '', False, 'Repository %s does not exist.' % reposname)

        if action == 'delete':
            return self.removeRepository(req, repos)

        if 'getSubdirs' in req.post:
            return self.getsubdirs(req, repos)

        if 'getPermissions' in req.post:
            return self.getpermissions(req, repos)

        if 'getPermissionPaths' in req.post:
            return self.getpermissionpaths(req, repos)

        if 'addPermission' in req.post:
            return self.addpermission(req, repos)

        if 'removePermission' in req.post:
            return self.removepermission(req, repos)

        if 'setPermission' in req.post:
            return self.setpermission(req, repos)

        if 'setCommitEmails' in req.post:
            return self.setCommitEmails(req, repos)

        if 'commitEmailsEnabled' in req.post:
            return self.commitEmailsEnabled(req, repos)

        if 'setTracCommitHook' in req.post:
            return self.setTracCommitHook(req, repos)

        if 'tracCommitHookEnabled' in req.post:
            return self.tracCommitHookEnabled(req, repos)

        if 'tracEnvCreate' in req.post:
            return self.tracEnvCreate(req, repos)

        return XMLStatusResponse('', False, 'Unknown command')
Esempio n. 5
0
def change(repos, repostype, path,
		subject, subjecttype, perm):
	"""Changes permission for repos:path, raises a
	Repository.DoesNotExistError if repos does not exist."""
	from submin.models.repository import Repository
	r = Repository(repos, repostype) # just for the exception
	_assert_permission_allowed(repostype, path, perm)
	storage.change_permission(repos, repostype, path, subject, subjecttype,
			perm)
	trigger_hook('permission-update', repositoryname=repos,
			repository_path=path, vcs_type=repostype)
Esempio n. 6
0
	def show(self, req, vcs_type, path, templatevars):
		import os.path

		u = user.User(req.session['user']['name'])
		try:
			repos = Repository(path[0], vcs_type)

			# Lie if user has no permission to read
			if not u.is_admin and not repository.userHasReadPermissions(u.name, path[0], vcs_type):
				raise DoesNotExistError
		except DoesNotExistError:
			return ErrorResponse('This repository does not exist.', request=req)

		trac_enabled = options.value('enabled_trac', 'no') != 'no'

		if trac_enabled:
			templatevars['trac_config_ok'] = True
			templatevars['trac_exists'] = False
			try:
				if trac.exists(path[0]):
					templatevars['trac_exists'] = True
			except MissingConfig as e:
				templatevars['trac_config_ok'] = False
				templatevars['trac_msg'] = \
					'There is something missing in your config: %s' % str(e)

			trac_base_url = options.url_path('base_url_trac')
			trac_http_url = str(trac_base_url + repos.name)
			templatevars['trac_http_url'] = trac_http_url

		try:
			vcs_url = repos.url()
		except MissingConfig as e:
			vcs_url = ""
			templatevars['vcs_url_error'] = str(e)

		templatevars['vcs_url'] = vcs_url
		templatevars['repository'] = repos
		templatevars['vcs_type'] = vcs_type
		formatted = evaluate_main('repositories.html', templatevars, request=req)
		return Response(formatted)
Esempio n. 7
0
	def add(self, req, path, templatevars):
		base_url = options.url_path('base_url_submin')
		reposname = ''

		if req.post and req.post['repository']:
			import re, commands

			reposname = req.post.get('repository').strip()
			if re.findall('[^a-zA-Z0-9_-]', reposname):
				return self.showAddForm(req, reposname, 'Invalid characters in repository name')

			if "vcs" not in req.post or req.post.get("vcs").strip() == "":
				return self.showAddForm(req, reposname, "No repository type selected. Please select a repository type.")

			vcs_type = req.post.get("vcs").strip()

			if reposname == '':
				return self.showAddForm(req, reposname, 'Repository name not supplied')

			if vcs_type not in vcs_list():
				return self.showAddForm(req, reposname, "Invalid repository type supplied.")

			try:
				a = Repository(reposname, vcs_type)
				return self.showAddForm(req, reposname, 'Repository %s already exists' % reposname)
			except DoesNotExistError:
				pass

			try:
				asking_user = user.User(req.session['user']['name'])
				Repository.add(vcs_type, reposname, asking_user)
			except PermissionError as e:
				return ErrorResponse('could not create repository',
					request=req, details=str(e))

			url = '%s/repositories/show/%s/%s' % (base_url, vcs_type,
					reposname)
			return Redirect(url, req)

		return self.showAddForm(req, reposname)
Esempio n. 8
0
def add(repos, repostype, path, subject, subjecttype, perm):
	"""Sets permission for repos:path, raises a
	Repository.DoesNotExistError if repos does not exist."""
	if repos != "":
		from submin.models.repository import Repository
		r = Repository(repos, repostype) # check if exists

	_assert_permission_allowed(repostype, path, perm)

	storage.add_permission(repos, repostype, path, subject, subjecttype,
			perm)
	trigger_hook('permission-update', repositoryname=repos,
			repository_path=path, vcs_type=repostype)
Esempio n. 9
0
def missing_config_envs(trac_dir):
    """Yields trac_envs that are 1) orphaned or 2) have missing configs
	Orphaned means that there is a trac environment, but no git/svn repository
	Missing configs means that there are some configs missing that Submin
	recommends.
	Each trav_env is a tuple of:
	   (trac_name, connected, missing_options)

	If 'connected' is False, then it is orphaned.

	missing_options is a dict of {section: [missing_option, ...], ...}
	"""
    trac_envs = []
    trac_sync_components = [
        'tracopt.ticket.commit_updater.committicketreferencemacro',
        'tracopt.ticket.commit_updater.committicketupdater',
    ]
    # trac components to enable for each vcs type
    trac_vcs_components = {
        'git': [
            'tracopt.versioncontrol.git.git_fs.csetpropertyrenderer',
            'tracopt.versioncontrol.git.git_fs.gitconnector',
            'tracopt.versioncontrol.git.git_fs.gitwebprojectsrepositoryprovider'
        ],
        'svn': [
            'tracopt.versioncontrol.svn.svn_fs.subversionconnector',
            'tracopt.versioncontrol.svn.svn_prop.subversionmergepropertydiffrenderer',
            'tracopt.versioncontrol.svn.svn_prop.subversionmergepropertyrenderer',
            'tracopt.versioncontrol.svn.svn_prop.subversionpropertyrenderer'
        ]
    }

    # per vcs, for each section, list of:
    # (option, expected_value, fatal_if_different)
    other_options = {
        'git': {
            'ticket': [('commit_ticket_update_check_perms', 'false', False)]
        }
    }

    for root, dirs, files in os.walk(trac_dir):
        for d in dirs:
            if d not in ['.', '..']:
                trac_envs.append(d)
        break

    for trac_env in sorted(trac_envs):
        # We would like to use: trac-admin <env> config get <section> <option>
        # but this does not resolve wildcards and is inefficient (lots of
        # process spawning; one for each option in each repository, also
        # parsing might pose a proble, unless exit codes are honered (didn't
        # check)).
        # So instead, we use ConfigParser to read the ini file and check
        # each option and their wildcards.
        fullpath = os.path.join(trac_dir, trac_env, 'conf', 'trac.ini')
        config = ConfigParser.RawConfigParser()
        config.read(fullpath)

        connected = False
        missing_options = {}
        components = []

        reposdir = config.get('trac', 'repository_dir')
        try:
            repostype = config.get('trac', 'repository_type')
        except ConfigParser.NoOptionError:
            # Assume svn
            repostype = 'svn'

        try:
            repos = Repository(trac_env, repostype)
        except DoesNotExistError as e:
            pass
        else:
            connected = True

            if repos.tracCommitHookEnabled():
                components.extend(trac_sync_components)

        components.extend(trac_vcs_components[repostype])

        all_options = {}
        if repostype in other_options:
            all_options.update(other_options[repostype])
        all_options['components'] = [(x, 'enabled', True) for x in components]

        for section, option_values in all_options.items():
            for option, value, fatal in option_values:
                if not has_option(config, section, option, value):
                    if section not in missing_options:
                        missing_options[section] = []
                    missing = {
                        'option': option,
                        'value': value,
                        'fatal': fatal
                    }
                    missing_options[section].append(missing)

        if len(missing_options) > 0 or not connected:
            yield (trac_env, connected, missing_options)

    return
Esempio n. 10
0
def missing_config_envs(trac_dir):
	"""Yields trac_envs that are 1) orphaned or 2) have missing configs
	Orphaned means that there is a trac environment, but no git/svn repository
	Missing configs means that there are some configs missing that Submin
	recommends.
	Each trav_env is a tuple of:
	   (trac_name, connected, missing_options)

	If 'connected' is False, then it is orphaned.

	missing_options is a dict of {section: [missing_option, ...], ...}
	"""
	trac_envs = []
	trac_sync_components = [
		'tracopt.ticket.commit_updater.committicketreferencemacro',
		'tracopt.ticket.commit_updater.committicketupdater',
	]
	# trac components to enable for each vcs type
	trac_vcs_components = {
		'git': [
			'tracopt.versioncontrol.git.git_fs.csetpropertyrenderer',
			'tracopt.versioncontrol.git.git_fs.gitconnector',
			'tracopt.versioncontrol.git.git_fs.gitwebprojectsrepositoryprovider'
		],
		'svn': [
			'tracopt.versioncontrol.svn.svn_fs.subversionconnector',
			'tracopt.versioncontrol.svn.svn_prop.subversionmergepropertydiffrenderer',
			'tracopt.versioncontrol.svn.svn_prop.subversionmergepropertyrenderer',
			'tracopt.versioncontrol.svn.svn_prop.subversionpropertyrenderer'
		]
	}

	# per vcs, for each section, list of:
	# (option, expected_value, fatal_if_different)
	other_options = {
		'git': {
			'ticket': [('commit_ticket_update_check_perms', 'false', False)]
		}
	}

	for root, dirs, files in os.walk(trac_dir):
		for d in dirs:
			if d not in ['.', '..']:
				trac_envs.append(d)
		break

	for trac_env in sorted(trac_envs):
		# We would like to use: trac-admin <env> config get <section> <option>
		# but this does not resolve wildcards and is inefficient (lots of
		# process spawning; one for each option in each repository, also
		# parsing might pose a proble, unless exit codes are honered (didn't
		# check)).
		# So instead, we use ConfigParser to read the ini file and check
		# each option and their wildcards.
		fullpath = os.path.join(trac_dir, trac_env, 'conf', 'trac.ini')
		config = ConfigParser.RawConfigParser()
		config.read(fullpath)

		connected = False
		missing_options = {}
		components = []

		reposdir = config.get('trac', 'repository_dir')
		try:
			repostype = config.get('trac', 'repository_type')
		except ConfigParser.NoOptionError:
			# Assume svn
			repostype = 'svn'

		try:
			repos = Repository(trac_env, repostype)
		except DoesNotExistError as e:
			pass
		else:
			connected = True

			if repos.tracCommitHookEnabled():
				components.extend(trac_sync_components)

		components.extend(trac_vcs_components[repostype])

		all_options = {}
		if repostype in other_options:
			all_options.update(other_options[repostype])
		all_options['components'] = [(x, 'enabled', True) for x in components]

		for section, option_values in all_options.iteritems():
			for option, value, fatal in option_values:
				if not has_option(config, section, option, value):
					if section not in missing_options:
						missing_options[section] = []
					missing = {'option': option, 'value': value, 'fatal': fatal}
					missing_options[section].append(missing)

		if len(missing_options) > 0 or not connected:
			yield (trac_env, connected, missing_options)

	return
Esempio n. 11
0
    def addRepository(self, reposname, vcstype):
        from submin.models.user import FakeAdminUser

        Repository.add(vcstype, reposname, FakeAdminUser())