Esempio n. 1
0
def group_auth_resource_list_data(request):
    try:
        if request.POST.get("group_id_list") is None:
            return JsonResponse({"total": 0, "rows": []})
        group_id_list_form = GroupIdListForm(request.POST)
        group_id_list = group_id_list_form.data.getlist("group_id_list")
        search_form = GridSearchForm(request.POST)
        start, limit, sort_property, sort_direction = search_form.get_search_data()
        group_id_count = len(group_id_list)
        auth_resource_query = (
            GroupResource.objects.all()
            .values("resource_id")
            .annotate(group_count=Count("group"))
            .filter(group__in=group_id_list, group_count=group_id_count)
        )
        if group_id_count == 1:
            auth_resource_query = auth_resource_query.values(
                "resource__app__app_name", "resource__res_code", "resource__res_name", "create_time"
            )
        else:
            auth_resource_query = auth_resource_query.values(
                "resource__app__app_name", "resource__res_code", "resource__res_name"
            )
        if sort_property is not None:
            auth_resource_query = auth_resource_query.order_by(sort_direction + sort_property)
        total_count = auth_resource_query.count()
        resource_list = list(auth_resource_query[start : start + limit])
        return JsonResponse({"total": total_count, "rows": resource_list})
    except Exception as exp:
        logger.exception(exp)
        return JsonResponse({"success": False, "message": "加载数据失败!详细:%s" % exp})
Esempio n. 2
0
def project_list_data(request):
    try:
        search_form = GridSearchForm(request.POST)
        start, limit, sort_property, sort_direction = search_form.get_search_data()
        project_query = Project.objects.all().values('id', 'code', 'name', 'pm')
        if sort_property is not None:
            project_query = project_query.order_by(sort_direction + sort_property)
        total_count = project_query.count()
        project_list = list(project_query[start: start + limit])
        return JsonResponse({'total': total_count, 'rows': project_list})
    except Exception as exp:
        logger.exception(exp)
        return JsonResponse({'success': False, 'message': '加载数据失败!详细:%s' % exp})
Esempio n. 3
0
def user_list_data(request):
    try:
        search_form = GridSearchForm(request.POST)
        start, limit, sort_property, sort_direction = search_form.get_search_data()
        user_query = User.objects.all()
        user_query = user_query.values(*field_names(User))
        if sort_property is not None:
            user_query = user_query.order_by(sort_direction + sort_property)
        total_count = user_query.count()
        user_list = list(user_query[start: start + limit])
        return JsonResponse({'total': total_count, 'rows': user_list})
    except Exception as exp:
        logger.exception(exp)
        return JsonResponse({'success': False, 'message': '加载数据失败!详细:%s' % exp})
Esempio n. 4
0
def app_list_data(request):
    try:
        search_form = GridSearchForm(request.POST)
        start, limit, sort_property, sort_direction = search_form.get_search_data()
        app_query = App.objects.all()
        app_query = app_query.values(*field_names(App))
        if sort_property is not None:
            app_query = app_query.order_by(sort_direction + sort_property)
        total_count = app_query.count()
        app_list = list(app_query[start : start + limit])
        return JsonResponse({"total": total_count, "rows": app_list})
    except Exception as exp:
        logger.exception(exp)
        return JsonResponse({"success": False, "message": "加载数据失败!详细:%s" % exp})
Esempio n. 5
0
def result_list_data(request):
    try:
        search_form = GridSearchForm(request.POST)
        start, limit, sort_property, sort_direction = search_form.get_search_data()
        result_query = AuthResult.objects.all()
        # extra filters here
        result_query = result_query.values('app__app_name', 'res_label', 'resource__res_name', 'user__login_name', 'user__nick_name', 'group__group_code', 'group__group_name')
        if sort_property is not None:
            result_query = result_query.order_by(sort_direction + sort_property)
        total_count = result_query.count()
        result_list = list(result_query[start: start + limit])
        return JsonResponse({'total': total_count, 'rows': result_list})
    except Exception as exp:
        logger.exception(exp)
        return JsonResponse({'success': False, 'message': '加载数据失败!详细:%s' % exp})
Esempio n. 6
0
def admin_list_data(request):
    try:
        search_form = GridSearchForm(request.POST)
        start, limit, sort_property, sort_direction = search_form.get_search_data()
        admin_query = Admin.objects.all()
        # extra filters here
        admin_query = admin_query.values('user__login_name', 'user__nick_name', *field_names(Admin))
        if sort_property is not None:
            admin_query = admin_query.order_by(sort_direction + sort_property)
        total_count = admin_query.count()
        admin_list = list(admin_query[start: start + limit])
        return JsonResponse({'total': total_count, 'rows': admin_list})
    except Exception as exp:
        logger.exception(exp)
        return JsonResponse({'success': False, 'message': '加载数据失败!详细:%s' % exp})
Esempio n. 7
0
def group_list_data(request):
    try:
        search_form = GridSearchForm(request.POST)
        start, limit, sort_property, sort_direction = search_form.get_search_data()
        group_query = Group.objects.all()
        group_query = group_query.annotate(user_count=Count("users")).values(
            "app__app_name", "user_count", *field_names(Group)
        )
        if sort_property is not None:
            group_query = group_query.order_by(sort_direction + sort_property)
        total_count = group_query.count()
        group_list = list(group_query[start : start + limit])
        return JsonResponse({"total": total_count, "rows": group_list})
    except Exception as exp:
        logger.exception(exp)
        return JsonResponse({"success": False, "message": "加载数据失败!详细:%s" % exp})
Esempio n. 8
0
def deptuser_user_list_data(request):
    try:
        search_form = GridSearchForm(request.POST)
        start, limit, sort_property, sort_direction = search_form.get_search_data()
        deptuser_query = DepartmentUser.objects.all()
        dept_id = request.POST.get('dept_id')
        if dept_id is not None and dept_id.strip() != '' and dept_id != '0':
            deptuser_query = deptuser_query.filter(department=dept_id)
        deptuser_query = deptuser_query.values('department__dept_name', 'user__login_name', 'user__nick_name', *field_names(DepartmentUser))
        if sort_property is not None:
            deptuser_query = deptuser_query.order_by(sort_direction + sort_property)
        total_count = deptuser_query.count()
        user_list = list(deptuser_query[start: start + limit])
        return JsonResponse({'total': total_count, 'rows': user_list})
    except Exception as exp:
        logger.exception(exp)
        return JsonResponse({'success': False, 'message': '加载数据失败!详细:%s' % exp})
Esempio n. 9
0
def groupuser_user_list_data(request):
    try:
        search_form = GridSearchForm(request.POST)
        start, limit, sort_property, sort_direction = search_form.get_search_data()
        groupuser_query = GroupUser.objects.all()
        node_id = request.POST.get('node_id')
        if node_id is None or node_id == '0' or node_id.startswith('app_'):
            return JsonResponse(({'total': 0, 'rows': []}))
        else:  # node_id.startswith('group_'):
            group_id = int(node_id.split('_')[1])
            groupuser_query = groupuser_query.filter(group=group_id)
            groupuser_query = groupuser_query.values('group__group_name', 'user__login_name', 'user__nick_name', *field_names(GroupUser))
            if sort_property is not None:
                groupuser_query = groupuser_query.order_by(sort_direction + sort_property)
            total_count = groupuser_query.count()
            user_list = list(groupuser_query[start: start + limit])
            return JsonResponse({'total': total_count, 'rows': user_list})
    except Exception as exp:
        logger.exception(exp)
        return JsonResponse({'success': False, 'message': '加载数据失败!详细:%s' % exp})
Esempio n. 10
0
def dept_list_data(request):
    try:
        search_form = GridSearchForm(request.POST)
        start, limit, sort_property, sort_direction = search_form.get_search_data()
        dept_query = Department.objects.all()
        parent_id = request.POST.get('parentId')
        if parent_id is None or parent_id == '' or parent_id == '0':
            parent_id = None
        else:
            parent_id = int(parent_id)
        dept_query = dept_query.filter(parent=parent_id)
        dept_query = dept_query.values(*field_names(Department))
        if sort_property is not None:
            dept_query = dept_query.order_by(sort_direction + sort_property)
        total_count = dept_query.count()
        dept_list = list(dept_query[start: start + limit])
        return JsonResponse({'total': total_count, 'rows': dept_list})
    except Exception as exp:
        logger.exception(exp)
        return JsonResponse({'success': False, 'message': '加载数据失败!详细:%s' % exp})
Esempio n. 11
0
def resource_list_data(request):
    try:
        search_form = GridSearchForm(request.POST)
        start, limit, sort_property, sort_direction = search_form.get_search_data()
        resource_query = Resource.objects.all()
        app_id = request.POST.get('app_id')
        if app_id is not None and app_id.strip() != '' and app_id != '0':
            resource_query = resource_query.filter(app=app_id)
        if sort_property is not None:
            resource_query = resource_query.order_by(sort_direction + sort_property)
        resource_query = resource_query \
            .annotate(user_count=Count('users', distinct=True)) \
            .annotate(group_count=Count('groups', distinct=True)) \
            .values('app__app_name', 'user_count', 'group_count', *field_names(Resource))
        total_count = resource_query.count()
        resource_list = list(resource_query[start: start + limit])
        return JsonResponse({'total': total_count, 'rows': resource_list})
    except Exception as exp:
        logger.exception(exp)
        return JsonResponse({'success': False, 'message': '加载数据失败!详细:%s' % exp})
Esempio n. 12
0
def resource_auth_group_list_data(request):
    try:
        if request.POST.get('res_id_list') is None:
            return JsonResponse({'total': 0, 'rows': []})
        res_id_list_form = ResourceIdListForm(request.POST)
        res_id_list = res_id_list_form.data.getlist('res_id_list')
        search_form = GridSearchForm(request.POST)
        start, limit, sort_property, sort_direction = search_form.get_search_data()
        res_id_count = len(res_id_list)
        group_query = GroupResource.objects.all().values('group_id').annotate(res_count=Count('resource'))
        group_query = group_query.filter(resource__in=res_id_list, res_count=res_id_count)
        if res_id_count == 1:
            group_query = group_query.values('group_id', 'group__app__app_name', 'group__group_code', 'group__group_name', 'create_time')
        else:
            group_query = group_query.values('group_id', 'group__app__app_name', 'group__group_code', 'group__group_name')
        if sort_property is not None:
            group_query = group_query.order_by(sort_direction + sort_property)
        total_count = group_query.count()
        group_list = list(group_query[start: start + limit])
        return JsonResponse({'total': total_count, 'rows': group_list})
    except Exception as exp:
        logger.exception(exp)
        return JsonResponse({'success': False, 'message': '加载数据失败!详细:%s' % exp})
Esempio n. 13
0
def user_auth_resource_list_data(request):
    try:
        if request.POST.get('user_id_list') is None:
            return JsonResponse({'total': 0, 'rows': []})
        user_id_list_form = UserIdListForm(request.POST)
        user_id_list = user_id_list_form.data.getlist('user_id_list')
        search_form = GridSearchForm(request.POST)
        start, limit, sort_property, sort_direction = search_form.get_search_data()
        user_id_count = len(user_id_list)
        auth_resource_query = UserResource.objects.all() \
            .values('resource_id').annotate(user_count=Count('user')) \
            .filter(user__in=user_id_list, user_count=user_id_count)
        if user_id_count == 1:
            auth_resource_query = auth_resource_query.values('resource__app__app_name', 'resource__res_code', 'resource__res_name', 'create_time')
        else:
            auth_resource_query = auth_resource_query.values('resource__app__app_name', 'resource__res_code', 'resource__res_name')
        if sort_property is not None:
            auth_resource_query = auth_resource_query.order_by(sort_direction + sort_property)
        total_count = auth_resource_query.count()
        resource_list = list(auth_resource_query[start: start + limit])
        return JsonResponse({'total': total_count, 'rows': resource_list})
    except Exception as exp:
        logger.exception(exp)
        return JsonResponse({'success': False, 'message': '加载数据失败!详细:%s' % exp})
Esempio n. 14
0
def resource_auth_user_select_list_data(request):
    try:
        if request.POST.get('res_id_list') is None:
            return JsonResponse({'total': 0, 'rows': []})
        res_id_list_form = ResourceIdListForm(request.POST)
        res_id_list = res_id_list_form.data.getlist('res_id_list')
        search_form = GridSearchForm(request.POST)
        start, limit, sort_property, sort_direction = search_form.get_search_data()
        user_query = User.objects.all()
        res_id_count = len(res_id_list)
        auth_user_id_query = UserResource.objects.all() \
            .values('user_id').annotate(res_count=Count('resource')) \
            .filter(resource__in=res_id_list, res_count=res_id_count) \
            .values('user_id')
        user_query = user_query.exclude(id__in=auth_user_id_query)
        total_count = user_query.count()
        user_query = user_query.values(*field_names(User))
        if sort_property is not None:
            user_query = user_query.order_by(sort_direction + sort_property)
        user_list = list(user_query[start: start + limit])
        return JsonResponse({'total': total_count, 'rows': user_list})
    except Exception as exp:
        logger.exception(exp)
        return JsonResponse({'success': False, 'message': '加载数据失败!详细:%s' % exp})