Ejemplo n.º 1
0
    def addpermission(self, req, repos):
        name = req.post.get('name')
        type = req.post.get('type')
        path = req.post.get('path')
        vcs_type = repos.vcs_type

        default_perm = ''
        if vcs_type == "git":
            if path != "/":
                default_perm = "w"
            else:
                default_perm = "r"

        if type == 'group':
            name = name.lower()
            try:
                group.Group(name)
            except UnknownGroupError as e:
                import re
                if re.findall('[^a-zA-Z0-9_-]', name):
                    return XMLStatusResponse(
                        'addPermission', False,
                        'Invalid characters in groupname %s' % name)
                group.add(name)

        permissions.add(repos.name, repos.vcs_type, path, name, type,
                        default_perm)

        if not repos.has_path_permissions:
            path = path.lstrip('/')

        return XMLStatusResponse('addPermission', True,
                                 ('User', 'Group')[type == 'group'] +
                                 ' %s added to path %s' % (name, path))
Ejemplo n.º 2
0
	def testRemoveGroup(self):
		group.add("foo")
		foo = group.Group("foo")
		fake_admin = Mock()
		fake_admin.is_admin = True
		foo.remove()
		self.assert_("foo" not in [x.name for x in group.list(fake_admin)])
Ejemplo n.º 3
0
 def testRemoveGroup(self):
     group.add("foo")
     foo = group.Group("foo")
     fake_admin = Mock()
     fake_admin.is_admin = True
     foo.remove()
     self.assert_("foo" not in [x.name for x in group.list(fake_admin)])
Ejemplo n.º 4
0
	def add(self, req, path, localvars):
		base_url = options.url_path('base_url_submin')
		groupname = ''

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

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

			url = base_url + '/groups/show/' + groupname

			try:
				group.add(groupname)
			except IOError:
				return ErrorResponse('File permission denied', request=req)
			except GroupExistsError:
				return self.showAddForm(req, groupname, 'Group %s already exists' % groupname)

			return Redirect(url, req)

		return self.showAddForm(req, groupname)
Ejemplo n.º 5
0
    def add(self, req, path, localvars):
        base_url = options.url_path('base_url_submin')
        groupname = ''

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

            groupname = req.post.get('groupname').strip().lower()
            if re.findall('[^a-zA-Z0-9_-]', groupname):
                return self.showAddForm(req, groupname,
                                        'Invalid characters in groupname')
            if groupname == '':
                return self.showAddForm(req, groupname,
                                        'Groupname not supplied')

            url = base_url + '/groups/show/' + groupname

            try:
                group.add(groupname)
            except IOError:
                return ErrorResponse('File permission denied', request=req)
            except GroupExistsError:
                return self.showAddForm(req, groupname,
                                        'Group %s already exists' % groupname)

            return Redirect(url, req)

        return self.showAddForm(req, groupname)
Ejemplo n.º 6
0
    def testAddMember(self):
        from submin.models import user
        user.add("testUser", email="[email protected]", password="******")
        group.add("testGroup")
        u = user.User("testUser")
        g = group.Group("testGroup")

        g.add_member(u)
        self.assert_("testUser" in g.members())
Ejemplo n.º 7
0
	def testAddMember(self):
		from submin.models import user
		user.add("testUser", email="[email protected]", password="******")
		group.add("testGroup")
		u = user.User("testUser")
		g = group.Group("testGroup")

		g.add_member(u)
		self.assert_("testUser" in g.members())
Ejemplo n.º 8
0
 def testNotificationWithEmptyGroupPermission(self):
     self.addRepository("repos", "svn")
     group.add("untrusted")
     untrusted = group.Group("untrusted")
     untrusted.add_member(self.u)
     permissions.add("repos", "svn", "/", "untrusted", "group", "")
     self.assertRaises(
         UserPermissionError, self.u.set_notifications, [{"name": "repos", "vcs": "svn", "enabled": True}], self.u
     )
     n = self.u.notifications()
     self.assertEquals(n, {})
Ejemplo n.º 9
0
 def testRemoveMember(self):
     from submin.models import user
     user.add("testUser1", email="[email protected]", password="******")
     user.add("testUser2", email="[email protected]", password="******")
     group.add("testGroup")
     u1 = user.User("testUser1")
     u2 = user.User("testUser2")
     g = group.Group("testGroup")
     g.add_member(u1)
     g.add_member(u2)
     g.remove_member(u2)
     self.assert_("testUser2" not in g.members())
Ejemplo n.º 10
0
	def testRemoveMember(self):
		from submin.models import user
		user.add("testUser1", email="[email protected]", password="******")
		user.add("testUser2", email="[email protected]", password="******")
		group.add("testGroup")
		u1 = user.User("testUser1")
		u2 = user.User("testUser2")
		g = group.Group("testGroup")
		g.add_member(u1)
		g.add_member(u2)
		g.remove_member(u2)
		self.assert_("testUser2" not in g.members())
Ejemplo n.º 11
0
	def write_groups(self, config):
		from submin.models import group
		from submin.models import user

		# get filename
		authz_file = config.get('svn', 'authz_file')

		# read file
		cp = self.read_ini(authz_file)

		# get groups
		groups = cp.options('groups')
		for groupname in groups:
			members = [x.strip() for x in cp.get('groups', groupname).split(',')]
			try:
				g = group.add(groupname)
			except GroupExistsError:
				g = group.Group(groupname)

			for member in members:
				u = user.User(member)
				try:
					g.add_member(u)
				except MemberExistsError:
					pass
				if groupname == "submin-admins":
					u.is_admin = True
Ejemplo n.º 12
0
    def write_groups(self, config):
        from submin.models import group
        from submin.models import user

        # get filename
        authz_file = config.get('svn', 'authz_file')

        # read file
        cp = self.read_ini(authz_file)

        # get groups
        groups = cp.options('groups')
        for groupname in groups:
            members = [
                x.strip() for x in cp.get('groups', groupname).split(',')
            ]
            try:
                g = group.add(groupname)
            except GroupExistsError:
                g = group.Group(groupname)

            for member in members:
                u = user.User(member)
                try:
                    g.add_member(u)
                except MemberExistsError:
                    pass
                if groupname == "submin-admins":
                    u.is_admin = True
Ejemplo n.º 13
0
	def testListRepositoriesAll(self):
		"""Test listRepositories, which checks for valid permissions of repositories"""
		self._createRepos([x['name'] for x in self.repositories])
		mock_admin = Mock()
		mock_admin.is_admin = True
		u = user.add('bar', '[email protected]', send_mail=False)
		g = group.add('baz') # no members in this group
		g = group.add('quux')
		g.add_member(u)
		permissions.add('foo', 'svn', '/', 'bar', 'user', 'r')
		permissions.add('subdirs', 'svn', '/trunk', 'quux', 'group', 'rw')
		# 'bar' is not part of group 'baz', so 'example' should not be listed
		permissions.add('example', 'svn', '/', 'baz', 'group', 'r')

		result = repository.Repository.list(u)
		copy = self.repositories[:]
		copy = sorted([d for d in self.repositories if d.get('name') == 'foo' or d.get('name') == 'subdirs'])
		self.assertEquals(result, copy)
Ejemplo n.º 14
0
    def testListRepositoriesAll(self):
        """Test listRepositories, which checks for valid permissions of repositories"""
        self._createRepos([x['name'] for x in self.repositories])
        mock_admin = Mock()
        mock_admin.is_admin = True
        u = user.add('bar', '[email protected]', send_mail=False)
        g = group.add('baz')  # no members in this group
        g = group.add('quux')
        g.add_member(u)
        permissions.add('foo', 'svn', '/', 'bar', 'user', 'r')
        permissions.add('subdirs', 'svn', '/trunk', 'quux', 'group', 'rw')
        # 'bar' is not part of group 'baz', so 'example' should not be listed
        permissions.add('example', 'svn', '/', 'baz', 'group', 'r')

        result = repository.Repository.list(u)
        copy = self.repositories[:]
        copy = sorted([
            d for d in self.repositories
            if d.get('name') == 'foo' or d.get('name') == 'subdirs'
        ])
        self.assertEquals(result, copy)
Ejemplo n.º 15
0
        if report:
            continue

        if not match and last:
            try:
                group.rename(groupname, correct_groupname)
                verboseprint("Renamed group %s to %s" %
                             (groupname, correct_groupname))
                continue
            except GroupExistsError:
                verboseprint("Group %s already exists" % correct_groupname)

        try:
            correct_group = group.Group(correct_groupname)
        except UnknownGroupError:
            correct_group = group.add(correct_groupname)
            verboseprint("Created group %s" % correct_groupname)

        old_group = group.Group(groupname)
        members = list(old_group.members())
        for member in members:
            try:
                correct_group.add_member(user.User(member))
                verboseprint("Added %s to group %s" %
                             (member, correct_groupname))
            except MemberExistsError:
                verboseprint("User %s is already a member of group %s" %
                             (member, correct_groupname))

        params = [
            permission_by_group['repository'], permission_by_group['vcs'],
Ejemplo n.º 16
0
	def testNonEmptyList(self):
		group.add("test")
		fake_admin = Mock()
		fake_admin.is_admin = True
		self.assertEquals([g for g in group.list(fake_admin)], ["test"])
Ejemplo n.º 17
0
 def testEmptyMemberList(self):
     group.add("foo")
     foo = group.Group("foo")
     self.assertEquals(list(foo.members()), [])
Ejemplo n.º 18
0
	def testGetGroup(self):
		group.add("foo")
		g = group.Group("foo")
		self.assertEquals(g.name, "foo")
Ejemplo n.º 19
0
 def testAddDoubleGroup(self):
     group.add("test")
     self.assertRaises(GroupExistsError, group.add, "test")
Ejemplo n.º 20
0
 def testGetGroup(self):
     group.add("foo")
     g = group.Group("foo")
     self.assertEquals(g.name, "foo")
Ejemplo n.º 21
0
 def testNonEmptyList(self):
     group.add("test")
     fake_admin = Mock()
     fake_admin.is_admin = True
     self.assertEquals([g for g in group.list(fake_admin)], ["test"])
Ejemplo n.º 22
0
	def testAddDoubleGroup(self):
		group.add("test")
		self.assertRaises(GroupExistsError, group.add, "test")
Ejemplo n.º 23
0
	def testEmptyMemberList(self):
		group.add("foo")
		foo = group.Group("foo")
		self.assertEquals(list(foo.members()), [])