예제 #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))
예제 #2
0
파일: groups.py 프로젝트: andy-deng/submin
	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)])
예제 #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)])
예제 #4
0
파일: groups.py 프로젝트: andy-deng/submin
	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)
예제 #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)
예제 #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())
예제 #7
0
파일: groups.py 프로젝트: andy-deng/submin
	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())
예제 #8
0
파일: users.py 프로젝트: andy-deng/submin
 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, {})
예제 #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())
예제 #10
0
파일: groups.py 프로젝트: andy-deng/submin
	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())
예제 #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
예제 #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
예제 #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)
예제 #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)
예제 #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'],
예제 #16
0
파일: groups.py 프로젝트: andy-deng/submin
	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"])
예제 #17
0
 def testEmptyMemberList(self):
     group.add("foo")
     foo = group.Group("foo")
     self.assertEquals(list(foo.members()), [])
예제 #18
0
파일: groups.py 프로젝트: andy-deng/submin
	def testGetGroup(self):
		group.add("foo")
		g = group.Group("foo")
		self.assertEquals(g.name, "foo")
예제 #19
0
 def testAddDoubleGroup(self):
     group.add("test")
     self.assertRaises(GroupExistsError, group.add, "test")
예제 #20
0
 def testGetGroup(self):
     group.add("foo")
     g = group.Group("foo")
     self.assertEquals(g.name, "foo")
예제 #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"])
예제 #22
0
파일: groups.py 프로젝트: andy-deng/submin
	def testAddDoubleGroup(self):
		group.add("test")
		self.assertRaises(GroupExistsError, group.add, "test")
예제 #23
0
파일: groups.py 프로젝트: andy-deng/submin
	def testEmptyMemberList(self):
		group.add("foo")
		foo = group.Group("foo")
		self.assertEquals(list(foo.members()), [])