From 59b09486217964f8028f0109c380c319af6858c4 Mon Sep 17 00:00:00 2001 From: zzz833708 <498605991@qq.com> Date: Wed, 25 Sep 2024 14:45:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=A3=80=E7=B4=A2=E8=BF=87=E6=BB=A4?= =?UTF-8?q?=E4=BA=A4=E4=BA=92=E4=BC=98=E5=8C=96=E7=81=B0=E5=BA=A6=E5=BC=80?= =?UTF-8?q?=E5=85=B3=E9=AA=8C=E8=AF=81=20-=20=E6=8C=89=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=81=B0=E5=BA=A6=E9=9C=80=E6=B1=82=20#10101?= =?UTF-8?q?58081119856279?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bklog/apps/log_search/views/meta_views.py | 2 +- bklog/apps/utils/db.py | 11 ++++++++++- bklog/home_application/views.py | 7 ++++--- bklog/log_adapter/home/views.py | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/bklog/apps/log_search/views/meta_views.py b/bklog/apps/log_search/views/meta_views.py index d28a22c2a..9a361741a 100644 --- a/bklog/apps/log_search/views/meta_views.py +++ b/bklog/apps/log_search/views/meta_views.py @@ -155,7 +155,7 @@ def get_index_settings(self, request): """ my_setting = copy.copy(mysetting(request)) [my_setting.pop(key) for key in FILTER_KEY_LIST] - data = get_toggle_data() + data = get_toggle_data(request) return Response({**my_setting, **data}) @list_route(methods=["GET"], url_path="projects/mine") diff --git a/bklog/apps/utils/db.py b/bklog/apps/utils/db.py index d6b2a33f4..b7b76c02a 100644 --- a/bklog/apps/utils/db.py +++ b/bklog/apps/utils/db.py @@ -96,7 +96,7 @@ def array_chunk(data, size=100): return [data[i : i + size] for i in range(0, len(data), size)] -def get_toggle_data(): +def get_toggle_data(request): toggle_list = FeatureToggleObject.toggle_list(**{"is_viewed": True}) field_analysis_config, __ = FeatureToggle.objects.get_or_create( name=FIELD_ANALYSIS_CONFIG, @@ -107,6 +107,15 @@ def get_toggle_data(): "biz_id_white_list": [], }, ) + # 获取用户名 + username = request.user.username + for toggle in toggle_list: + config = toggle.feature_config + if isinstance(config, dict): + # 获取用户白名单 + user_list = config.get("user_white_list", []) + if username in user_list: + toggle.status = "on" data = { # 实时日志最大长度 "REAL_TIME_LOG_MAX_LENGTH": "20000", diff --git a/bklog/home_application/views.py b/bklog/home_application/views.py index 89c973a00..01f260735 100644 --- a/bklog/home_application/views.py +++ b/bklog/home_application/views.py @@ -21,11 +21,11 @@ """ +from blueapps.account.decorators import login_exempt from django.conf import settings -from django.shortcuts import render from django.http import HttpResponse, JsonResponse +from django.shortcuts import render from django.utils.translation import ugettext as _ -from blueapps.account.decorators import login_exempt # 开发框架中通过中间件默认是需要登录态的,如有不需要登录的,可添加装饰器login_exempt # 装饰器引入 from blueapps.account.decorators import login_exempt @@ -38,7 +38,7 @@ def home(request): """ 首页 """ - return render(request, settings.VUE_INDEX, get_toggle_data()) + return render(request, settings.VUE_INDEX, get_toggle_data(request)) def bkdata_auth(request): @@ -93,6 +93,7 @@ def healthz(request): @login_exempt def metrics(request): from django_prometheus import exports + from settings import PROMETHEUS_METRICS_TOKEN token = request.GET.get("token") diff --git a/bklog/log_adapter/home/views.py b/bklog/log_adapter/home/views.py index 8cda88c31..2eeb4c81c 100644 --- a/bklog/log_adapter/home/views.py +++ b/bklog/log_adapter/home/views.py @@ -244,7 +244,7 @@ def external(request): setattr(request, "COOKIES", {k: v for k, v in request.COOKIES.items() if k != "bk_token"}) else: logger.error(f"外部用户({external_user})或空间(ID:{space_uid})不存在, request.META: {request.META}") - response = render(request, settings.VUE_INDEX, get_toggle_data()) + response = render(request, settings.VUE_INDEX, get_toggle_data(request)) response.set_cookie("space_uid", space_uid) response.set_cookie("external_user", external_user) return response