コード例 #1
0
ファイル: views.py プロジェクト: Q-skyworker/BK_project
def get_biz_person_list(request, biz_cc_id):
    """
    @summary: 获取业务相关人员信息
    @param request:
    @param biz_cc_id:
    @return:
    """
    original = request.GET.get('original', '')
    role_list = CC_ROLES
    # 模板授权需要去掉运维角色,运维默认有所有权限
    if original == 'tasktmpl_list':
        role_list = [role for role in role_list if
                     role != MAINTAINERS]

        # 并添加职能化人员
        role_list.append(FUNCTOR)

    try:
        prepare_business(request, cc_id=biz_cc_id)
    except Exception as e:
        logger.error('get_biz_person_list error, biz_cc_id=%s, error=%s' % (biz_cc_id, e))

    person_list = []
    for key in role_list:
        name = ROLES_DECS[key]
        group_name = "%s\x00%s" % (biz_cc_id, key)
        group = Group.objects.get(name=group_name)
        user_list = group.user_set.all()
        data_list = []
        for user in user_list:
            openid = user.username
            data_list.append({
                "text": user.full_name,
                "id": openid,
            })
        # if data_list:
        data_list.insert(0, {
            "text": _(u"所有%s") % name,
            "id": key
        })
        person_list.append({
            "text": name,
            "children": data_list
        })
    return JsonResponse({
        "result": True,
        "data": person_list
    })
コード例 #2
0
ファイル: middlewares.py プロジェクト: Q-skyworker/BK_project
    def process_view(self, request, view_func, view_args, view_kwargs):
        """
        If a request path contains biz_cc_id parameter, check if current
        user has perm view_business or return http 403.
        """
        if getattr(view_func, 'login_exempt', False):
            return None
        biz_cc_id = view_kwargs.get('biz_cc_id')
        if biz_cc_id:
            try:
                business = prepare_business(request, cc_id=biz_cc_id)
            except exceptions.Unauthorized:
                # permission denied for target business (irregular request)
                return HttpResponse(status=406)
            except exceptions.Forbidden:
                # target business does not exist (irregular request)
                return HttpResponseForbidden()
            except exceptions.APIError as e:
                ctx = {
                    'system': e.system,
                    'api': e.api,
                    'message': e.message,
                }
                ctx.update(context_processors.get_constant_settings())
                return render_mako_context(request, '503.html', ctx)

            # set time_zone of business
            if business.time_zone:
                request.session['blueking_timezone'] = business.time_zone

            if not request.user.has_perm('view_business', business):
                return HttpResponseForbidden()
コード例 #3
0
    def process_view(self, request, view_func, view_args, view_kwargs):
        """
        If a request path contains biz_cc_id parameter, check if current
        user has perm view_business or return http 403.
        """
        if getattr(view_func, 'login_exempt', False):
            return None
        biz_cc_id = view_kwargs.get('biz_cc_id')
        if biz_cc_id and str(biz_cc_id) != '0':
            try:
                business = prepare_business(request, cc_id=biz_cc_id)
            except exceptions.Unauthorized:
                # permission denied for target business (irregular request)
                return HttpResponse(status=401)
            except exceptions.Forbidden:
                # target business does not exist (irregular request)
                return HttpResponseForbidden()
            except exceptions.APIError as e:
                ctx = {
                    'system': e.system,
                    'api': e.api,
                    'message': e.message,
                }
                logger.error(json.dumps(ctx))
                return HttpResponse(status=503, content=json.dumps(ctx))

            # set time_zone of business
            if business.time_zone:
                request.session['blueking_timezone'] = business.time_zone

            if not request.user.has_perm('view_business', business):
                return HttpResponseForbidden()
コード例 #4
0
ファイル: middlewares.py プロジェクト: zyh1234/bk-sops
    def process_view(self, request, view_func, view_args, view_kwargs):
        """
        If a request path contains biz_cc_id parameter, check if current
        user has perm view_business or return http 403.
        """
        if getattr(view_func, 'login_exempt', False):
            return None
        biz_cc_id = view_kwargs.get(
            'biz_cc_id') or self._get_biz_cc_id_in_rest_request(request)
        if biz_cc_id and str(biz_cc_id) != '0':
            try:
                business = prepare_business(request, cc_id=biz_cc_id)
            except exceptions.Unauthorized:
                # permission denied for target business (irregular request)
                return HttpResponse(status=401)
            except exceptions.Forbidden:
                # target business does not exist (irregular request)
                return HttpResponseForbidden()
            except exceptions.APIError as e:
                ctx = {
                    'system': e.system,
                    'api': e.api,
                    'message': e.message,
                }
                logger.error(json.dumps(ctx))
                return HttpResponse(status=503, content=json.dumps(ctx))

            # set time_zone of business
            if business.time_zone:
                request.session['blueking_timezone'] = business.time_zone

            try:
                if not request.user.has_perm('view_business', business):
                    raise exceptions.Unauthorized(
                        'user[{username}] has no perm view_business of business[{biz}]'
                        .format(username=request.user.username,
                                biz=business.cc_id))
            except Exception as e:
                logger.exception(
                    'user[username={username},type={user_type}] has_perm raise error[{error}]'
                    .format(username=request.user.username,
                            user_type=type(request.user),
                            error=e))
                return HttpResponseForbidden(e.message)