示例#1
0
    def test_perm_source(self):
        user = User.objects.create(username='******')
        self.client.json_post(reverse('siteapi:perm_list'),
                              data={
                                  'scope': 'app1',
                                  'name': '登录'
                              })
        perm_uid = 'app_app1_denglu'
        for uid in [
                '1-1',
                '1-1-1',
                '1-1-1-1',
                '1-2-1',
                '1-3',
        ]:
            dept = Dept.objects.get(uid=uid)
            DeptMember.objects.create(user=user, owner=dept)
        for uid in [
                '1-1',
                '1-1-1-1',
                '1-3',
        ]:
            dept_perm = DeptPerm.objects.get(perm__uid=perm_uid,
                                             owner__uid=uid)
            dept_perm.permit()

        for uid in [
                '1',
                '1-1-2',
                '1-2',
                '1-2-2',
                '1-3-1',
        ]:
            group = Group.objects.get(uid=uid)
            GroupMember.objects.create(user=user, owner=group)
        for uid in [
                '1',
                '1-2',
                '1-3-1',
        ]:
            group_perm = GroupPerm.objects.get(perm__uid=perm_uid,
                                               owner__uid=uid)
            group_perm.permit()

        flush_all_perm()
        res = self.client.get(
            reverse('siteapi:user_perm_detail', args=('test', perm_uid)))
        expect = {
            'perm': {
                'perm_id': 3,
                'uid': 'app_app1_denglu',
                'name': '登录',
                'remark': '',
                'scope': 'app1',
                'action': 'denglu',
                'subject': 'app',
            },
            'status':
            0,
            'dept_perm_value':
            True,
            'group_perm_value':
            True,
            'node_perm_value':
            True,
            'value':
            True,
            'source': [{
                'name': '1-1',
                'uid': '1-1',
                'node_uid': 'd_1-1',
                'node_subject': 'dept',
            }, {
                'name': '1-1-1-1',
                'uid': '1-1-1-1',
                'node_uid': 'd_1-1-1-1',
                'node_subject': 'dept',
            }, {
                'name': '1-3',
                'uid': '1-3',
                'node_uid': 'd_1-3',
                'node_subject': 'dept',
            }, {
                'name': '1',
                'uid': '1',
                'node_uid': 'g_1',
                'node_subject': 'root',
            }, {
                'name': '1-2',
                'uid': '1-2',
                'node_uid': 'g_1-2',
                'node_subject': 'root',
            }, {
                'name': '1-3-1',
                'uid': '1-3-1',
                'node_uid': 'g_1-3-1',
                'node_subject': 'root',
            }]
        }
        self.assertEqual(expect, res.json())
示例#2
0
def flush_all_perm_in_db():
    '''
    刷新数据库中部门、组、用户的权限
    不是必须
    '''
    flush_perm.flush_all_perm()