예제 #1
0
def perm_const_override():
    import XroadsAuth.permisson_constants as PermConst

    PermConst.DISTRICT_ADMIN = 'District Admin'
    PermConst.SCHOOL_ADMIN = 'School Admin'
    PermConst.CLUB_EDITOR = 'Club Editor'
    PermConst.ROLE_HIERARCHY = PermConst.Hierarchy(District,
                                                   School,
                                                   Club,
                                                   name=PermConst.CLUB_EDITOR)

    # Roles go from highest level to lowest level in ROLES list
    PermConst.ROLES = [
        PermConst.Hierarchy(
            District,
            name=PermConst.DISTRICT_ADMIN,
            poss_perms=['__all__', 'create-school', 'modify-district']),
        PermConst.Hierarchy(District,
                            School,
                            name=PermConst.SCHOOL_ADMIN,
                            poss_perms=[
                                '__all__', 'create-club', 'modify-school',
                                'hide-club', 'view-user-detail', 'hide-school'
                            ]),
        PermConst.Hierarchy(District,
                            School,
                            Club,
                            name=PermConst.CLUB_EDITOR,
                            poss_perms=[
                                '__all__', 'modify-club', 'add-admin',
                                'hide-club', 'answer-questions'
                            ]),
    ]
예제 #2
0
    def test_create_hierarchy(self):
        heirarchy = PermConst.Hierarchy(
            District, School, Club, name="Club Editor")

        assert heirarchy.level_names[0] == 'District'
        assert heirarchy.level_names[1] == 'School'
        assert heirarchy.level_names[2] == 'Club'
예제 #3
0
    def test_to_str(self, perm_const_override):
        test_hier = PermConst.Hierarchy(District, School, Club, name="test_hier", poss_perms=[
            'some_str', 'other_str'])
        perm = Permissions([], hierarchy=test_hier)

        # Putting in a list instead of a set because this test would always fail otherwise. Sets do not preserve order so the str will constantly change
        perm.permissions = ['other_str', 'some_str']

        assert str(perm) == 'perms=[other_str, some_str]'
예제 #4
0
    def test_add_perms_already_all(self, perm_const_override):
        test_hier = PermConst.Hierarchy(District, School, Club, name="test_hier", poss_perms=[
            'some_str', 'other_str'])
        perm = Permissions([], hierarchy=test_hier)

        perm.allow_all_perms()
        perm.add('some_str')

        assert perm.permissions == {'__all__'}
예제 #5
0
    def test_str_matches(self, role_model_instances, perm_const_override):
        district1, school1, club1 = role_model_instances()

        test_hier = PermConst.Hierarchy(District, School, Club, name="test_hier", poss_perms=[
            'some_str', 'other_str'])
        role = Role.create(district1, school1, club1)
        role.hierarchy = test_hier
        role.permissions.hierarchy = test_hier

        perms = role.hierarchy.poss_perms
        role.permissions.add('some_str', 'other_str')

        expected = 'District-1/School-1/Club-1/perms=[some_str, other_str]'
예제 #6
0
 def test_get_hier(self):
     PermConst.ROLES = [
         PermConst.Hierarchy(District, name=PermConst.DISTRICT_ADMIN)
     ]
     assert PermConst.Hierarchy.get_hierarchy(
         PermConst.DISTRICT_ADMIN) == PermConst.ROLES[0]