示例#1
0
def get_group(id=None, name=None):
    try:
        if id:
            return Group.get(Group.id==id)
        elif name:
            return Group.get(Group.name==name)
        else:
            raise ValueError('nither `id` or `name` was given')
    except Group.DoesNotExist:
        raise NotFoundException("no group could be found with these attributes")
示例#2
0
文件: api.py 项目: ael-code/libreant
def get_group(id=None, name=None):
    try:
        if id:
            return Group.get(Group.id==id)
        elif name:
            return Group.get(Group.name==name)
        else:
            raise ValueError('nither `id` or `name` was given')
    except Group.DoesNotExist:
        raise NotFoundException("no group could be found with these attributes")
示例#3
0
 def test_assign_user_to_multiple_group(self):
     rebels = Group.create(name='rebels')
     aliens = Group.create(name='aliens')
     allGroups = [aliens, rebels]
     # https://en.wikipedia.org/wiki/They_Live
     user = User.create(name='doubtful')
     user.groups.add(allGroups)
     belongsID = [g.id for g in user.groups]
     allGroupsID = [g.id for g in allGroups]
     eq_((set(belongsID), len(belongsID)), (set(allGroupsID), len(allGroupsID)))
示例#4
0
 def test_assign_user_to_multiple_group(self):
     rebels = Group.create(name='rebels')
     aliens = Group.create(name='aliens')
     allGroups = [aliens, rebels]
     # https://en.wikipedia.org/wiki/They_Live
     user = User.create(name='doubtful')
     user.groups.add(allGroups)
     belongsID = [g.id for g in user.groups]
     allGroupsID = [g.id for g in allGroups]
     eq_((set(belongsID), len(belongsID)),
         (set(allGroupsID), len(allGroupsID)))
示例#5
0
 def populate(self):
     with self.udb.atomic():
         cap1 = Capability.create(domain='res1', action=Action.READ)
         cap2 = Capability.create(domain='res2', action=Action.UPDATE)
         grp1 = Group.create(name='grp2')
         grp2 = Group.create(name='grp1')
         usr = User.create(name='usr')
         grp1.capabilities.add(cap1)
         grp2.capabilities.add(cap2)
         usr.groups.add([grp1, grp2])
     return usr, [cap1, cap2]
示例#6
0
 def test_user_can(self):
     cap1 = Capability.create(domain=Capability.simToReg('volumes/*'),
                              action=Action.CREATE | Action.READ)
     cap2 = Capability.create(domain=Capability.simToReg('volumes/123'),
                              action=Action.UPDATE)
     grp1 = Group.create(name='grp2')
     grp2 = Group.create(name='grp1')
     usr = User.create(name='usr')
     grp1.capabilities.add(cap1)
     grp2.capabilities.add(cap2)
     usr.groups.add([grp1, grp2])
     self.assertTrue(usr.can('volumes/61273', action=Action.CREATE))
     self.assertTrue(usr.can('volumes/123', Action.CREATE | Action.READ))
     self.assertFalse(usr.can('volumes/82828', Action.DELETE))
     self.assertFalse(usr.can('volumes/123', Action.DELETE))
示例#7
0
 def test_assign_user_to_group(self):
     anons = Group.create(name='anons')
     jhondohe = User.create(name='jhondhoe', password='******')
     anons.users.add(jhondohe)
     anons.save()
     eq_(jhondohe.groups.count(), 1)
     eq_(jhondohe.groups.get().id, anons.id)
示例#8
0
 def test_assign_capability_to_group(self):
     cap = Capability.create(domain='res', action=Action.DELETE)
     anons = Group.create(name='anons')
     anons.capabilities.add(cap)
     anons.save()
     eq_(anons.capabilities.count(), 1)
     eq_(anons.capabilities.get(), cap)
示例#9
0
 def test_assign_user_to_group(self):
     anons = Group.create(name='anons')
     jhondohe = User.create(name='jhondhoe', password='******')
     anons.users.add(jhondohe)
     anons.save()
     eq_(jhondohe.groups.count(), 1)
     eq_(jhondohe.groups.get().id, anons.id)
示例#10
0
 def test_remove_user_from_group(self):
     anons = Group.create(name='anons')
     jhondohe = User.create(name='jhondhoe', password='******')
     anons.users.add(jhondohe)
     anons.save()
     anons.users.remove(jhondohe)
     anons.save()
     eq_(jhondohe.groups.count(), 0)
     eq_(UserToGroup.select().count(), 0)
示例#11
0
 def test_remove_user_from_group(self):
     anons = Group.create(name='anons')
     jhondohe = User.create(name='jhondhoe', password='******')
     anons.users.add(jhondohe)
     anons.save()
     anons.users.remove(jhondohe)
     anons.save()
     eq_(jhondohe.groups.count(), 0)
     eq_(UserToGroup.select().count(), 0)
示例#12
0
 def test_assign_duplicate_user_to_group(self):
     anons = Group.create(name='anons')
     jhondohe = User.create(name='jhondhoe', password='******')
     anons.users.add(jhondohe)
     anons.save()
     with self.assertRaises(IntegrityError):
         anons.users.add(jhondohe)
         anons.save()
     eq_(jhondohe.groups.count(), 1)
     eq_(jhondohe.groups.get().id, anons.id)
示例#13
0
 def test_assign_duplicate_user_to_group(self):
     anons = Group.create(name='anons')
     jhondohe = User.create(name='jhondhoe', password='******')
     anons.users.add(jhondohe)
     anons.save()
     with self.assertRaises(IntegrityError):
         anons.users.add(jhondohe)
         anons.save()
     eq_(jhondohe.groups.count(), 1)
     eq_(jhondohe.groups.get().id, anons.id)
示例#14
0
 def test_assign_same_capability_to_group(self):
     cap = Capability.create(domain='res', action=Action.DELETE)
     anons = Group.create(name='anons')
     anons.capabilities.add(cap)
     anons.save()
     with self.assertRaises(IntegrityError):
         anons.capabilities.add(cap)
         anons.save()
     eq_(anons.capabilities.count(), 1)
     eq_(anons.capabilities.get(), cap)
示例#15
0
 def test_group_can(self):
     cap1 = Capability.create(domain=Capability.simToReg('volumes/*'),
                              action=Action.CREATE | Action.READ)
     cap2 = Capability.create(domain=Capability.simToReg('users/123'),
                              action=Action.CREATE | Action.DELETE)
     grp = Group.create(name='grp2')
     grp.capabilities.add([cap1, cap2])
     self.assertTrue(grp.can('volumes/123', Action.CREATE | Action.READ))
     self.assertFalse(grp.can('volumes/82828', Action.DELETE))
     self.assertTrue(grp.can('users/123', Action.DELETE))
     self.assertFalse(grp.can('users/123', Action.UPDATE))
示例#16
0
 def test_group_unique_name(self):
     Group.create(name='cyclists')
     with self.assertRaises(IntegrityError):
         Group.create(name='cyclists')
示例#17
0
 def test_group_creation(self):
     newGroup = Group.create(name='chefs')
     Group.get(Group.name == newGroup.name)
     eq_(Group.select().count(), 1)
示例#18
0
def add_group(name):
    try:
        return Group.create(name=name)
    except IntegrityError:
        raise ConflictException("a group with the same name already exists")
示例#19
0
def delete_group(id):
    if not Group.delete().where(Group.id == id).execute():
        raise NotFoundException('no group could be found with this id')
示例#20
0
文件: api.py 项目: ael-code/libreant
def delete_group(id):
    if not Group.delete().where(Group.id == id).execute():
        raise NotFoundException('no group could be found with this id')
示例#21
0
文件: api.py 项目: ael-code/libreant
def add_group(name):
    try:
        return Group.create(name=name)
    except IntegrityError:
        raise ConflictException("a group with the same name already exists")
示例#22
0
 def test_group_creation(self):
     newGroup = Group.create(name='chefs')
     Group.get(Group.name == newGroup.name)
     eq_(Group.select().count(), 1)
示例#23
0
def get_groups():
    return Group.select()
示例#24
0
 def test_group_unique_name(self):
     Group.create(name='cyclists')
     with self.assertRaises(IntegrityError):
         Group.create(name='cyclists')