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