Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

审计增加口令修改记录 #315

Merged
merged 13 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/api/bkuser_core/audit/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class OperationType(AutoLowerEnum):
EXPORT = auto()
RESTORATION = auto()

FORGET_PASSWORD = auto()
RESET_PASSWORD = auto()
MODIFY_PASSWORD = auto()

_choices_labels = (
(CREATE, "创建"),
(UPDATE, "更新"),
Expand All @@ -53,6 +57,9 @@ class OperationType(AutoLowerEnum):
(EXPORT, "导出"),
(IMPORT, "导入"),
(RESTORATION, "恢复"),
(FORGET_PASSWORD, "忘记密码"),
(RESET_PASSWORD, "重置密码"),
(MODIFY_PASSWORD, "修改密码"),
)


Expand Down
3 changes: 3 additions & 0 deletions src/api/bkuser_core/audit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ def _catch_exc(self, request, *args, **kwargs):
if operate_type == OperationType.UPDATE.value:
_params["operator_obj"] = self.get_object()

if getattr(self, "operate_type", None):
_params["operate_type"] = self.operate_type

create_general_log(**_params)
return _result

Expand Down
4 changes: 4 additions & 0 deletions src/api/bkuser_core/profiles/v2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class ProfileViewSet(AdvancedModelViewSet, AdvancedListAPIView):
serializer_class = local_serializers.ProfileSerializer
lookup_field = "username"
filter_backends = [ProfileSearchFilter, filters.OrderingFilter]
operate_type = None

relation_fields = ["departments", "leader", "login_set"]

Expand Down Expand Up @@ -320,6 +321,7 @@ def _update(self, request, partial):
update_summary = {"request": request}
# 密码修改加密
if validated_data.get("password"):
self.operate_type = OperationType.RESET_PASSWORD.value
pending_password = validated_data.get("password")
config_loader = ConfigProvider(category_id=instance.category_id)
try:
Expand Down Expand Up @@ -389,6 +391,7 @@ def destroy(self, request, *args, **kwargs):
"""
return super().destroy(request, *args, **kwargs)

@audit_general_log(operate_type=OperationType.MODIFY_PASSWORD.value)
@swagger_auto_schema(
query_serializer=AdvancedRetrieveSerialzier(),
request_body=local_serializers.ProfileModifyPasswordSerializer,
Expand Down Expand Up @@ -440,6 +443,7 @@ def modify_password(self, request, *args, **kwargs):
)
return Response(data=local_serializers.ProfileMinimalSerializer(instance).data)

@audit_general_log(OperationType.FORGET_PASSWORD.value)
@swagger_auto_schema(
query_serializer=AdvancedRetrieveSerialzier(),
request_body=EmptySerializer,
Expand Down
2 changes: 1 addition & 1 deletion src/api/bkuser_core/user_settings/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SettingsEnableNamespaces(AutoLowerEnum):
(GENERAL, "通用"),
(PASSWORD, "密码"),
(CONNECTION, "连接"),
(FIELDS, "连接"),
(FIELDS, "字段"),
)


Expand Down