예제 #1
0
 def add_route(gid, routes):
     with db.auto_commit():
         Group.get_or_404(id=gid, msg='无指定权限组')
         for route_id in routes:
             Route.get_or_404(id=route_id, msg='无指定路由节点')
             Menu.abort_repeat(group_id=gid, route_id=route_id)
             Menu.create(group_id=gid, route_id=route_id)
예제 #2
0
    def get_routes(gid: int) -> dir:
        id2route_node = {
            route.id: dict(route)
            for route in Group.get_or_404(id=gid).route
        }
        id2route_node_clone = id2route_node.copy()

        def add_parent_node(cur_route_node):
            if cur_route_node['parent_id'] == cur_route_node['id'] == 0:
                pass
            else:
                if not (cur_route_node['parent_id'] in id2route_node.keys()
                        or cur_route_node['parent_id'] == 0):
                    parent_route = Route.get_or_404(
                        id=cur_route_node['parent_id'])
                    id2route_node_clone[parent_route.id] = dict(parent_route)
                    add_parent_node(dict(parent_route))

        for route_node in id2route_node.values():
            add_parent_node(route_node)

        t = RouteTree(RouteNode)
        t.generate_by_list(
            [route_node for route_node in id2route_node_clone.values()])
        return t.serialize()['children']
예제 #3
0
 def update_group(id, name, info):
     '''
     :param id: 权限组id
     :param name: 权限组名
     :param info: 权限组名描述
     :return:
     '''
     group = Group.get_or_404(id=id, msg='分组不存在,更新失败')
     group.update(name=name, info=info)
예제 #4
0
def delete_group(id):
    '''删除权限组'''
    group = GroupModel.get_or_404(id=id, msg='分组不存在,删除失败')
    if UserModel.get(group_id=id):
        raise ForbiddenException(msg='分组下存在用户,不可删除')

    # 删除group拥有的权限
    AuthModel.objects.filter(group_id=id).delete()
    group.delete()
    return Success()
예제 #5
0
    def delete_group(id):
        '''
        :param id: 权限组id
        :return:
        '''
        group = Group.get_or_404(id=id, msg='分组不存在,删除失败')
        if User.get(group_id=id):
            raise Forbidden(msg='分组下存在用户,不可删除')

        # 删除group拥有的权限
        with db.auto_commit():
            db.session.query(Auth).filter(Auth.group_id == id).delete(
                synchronize_session=False)
            group.hard_delete(commit=False)
예제 #6
0
 def get_element_by_group(group_id):
     group = Group.get_or_404(id=group_id)
     return group.elements
예제 #7
0
def update_group(id):
    '''更新权限组'''
    form = UpdateGroupValidator().validate_for_api()
    group = GroupModel.get_or_404(id=id, msg='分组不存在,更新失败')
    group.renew(name=form.name.data, info=form.info.data)
    return Success()
예제 #8
0
def get_group(id):
    '''查询一个权限组及其权限'''
    group = GroupModel.get_or_404(id=id, msg='分组不存在')
    group.append('auth_list')
    return Success(group)
예제 #9
0
 def group_name(self):
     try:
         group = GroupModel.get_or_404(id=self.group_id)
         return group.name
     except Exception:
         return ''