Skip to content

Commit 7f93314

Browse files
committed
feat(unmasking): implement activation and plaintext retrieval for unmasking workflows with new request and response models
1 parent 14cb2ce commit 7f93314

4 files changed

Lines changed: 164 additions & 1 deletion

File tree

api/dms/service/v1/unmasking_workflow.go

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,18 @@ type UnmaskingWorkflowListItem struct {
5757
ApprovalStatus biz.UnmaskingWorkflowApprovalStatus `json:"approval_status" validate:"oneof=pending approved rejected cancelled"`
5858
// 使用情况
5959
UsageStatus biz.UnmaskingWorkflowUsageStatus `json:"usage_status" validate:"oneof=unviewed viewed"`
60-
// 过期时间 (RFC3339)
60+
// 过期时间 (RFC3339),兼容字段:批准前为激活截止,激活后为查看截止
6161
ExpireTime string `json:"expire_time" example:"2024-01-16T10:30:00Z"`
62+
// 激活查看时刻 (RFC3339)
63+
ActivatedAt string `json:"activated_at"`
64+
// 须在此时刻前激活查看 (RFC3339)
65+
ActivationDeadline string `json:"activation_deadline"`
66+
// 明文查看截止 (RFC3339)
67+
ViewValidUntil string `json:"view_valid_until"`
68+
// 申请人明文查看状态
69+
ViewState biz.UnmaskingWorkflowViewState `json:"view_state"`
70+
// 是否可点击激活查看
71+
CanActivate bool `json:"can_activate"`
6272
// 申请理由
6373
ApplyReason string `json:"apply_reason"`
6474
// 当前待处理人
@@ -252,3 +262,55 @@ type CancelUnmaskingWorkflowReply struct {
252262
// Generic reply
253263
base.GenericResp
254264
}
265+
266+
// swagger:parameters ActivateUnmaskingWorkflowView
267+
type ActivateUnmaskingWorkflowViewReq struct {
268+
// swagger:ignore
269+
ProjectUid string `param:"project_uid" json:"project_uid" validate:"required"`
270+
// in: path
271+
// Required: true
272+
WorkflowID string `param:"workflow_id" json:"workflow_id" validate:"required"`
273+
}
274+
275+
// swagger:model ActivateUnmaskingWorkflowViewReply
276+
type ActivateUnmaskingWorkflowViewReply struct {
277+
Data *ActivateUnmaskingWorkflowViewReplyData `json:"data"`
278+
base.GenericResp
279+
}
280+
281+
// swagger:model ActivateUnmaskingWorkflowViewReplyData
282+
type ActivateUnmaskingWorkflowViewReplyData struct {
283+
ViewValidUntil string `json:"view_valid_until"`
284+
ViewState biz.UnmaskingWorkflowViewState `json:"view_state"`
285+
}
286+
287+
// swagger:parameters GetUnmaskingWorkflowPlaintext
288+
type GetUnmaskingWorkflowPlaintextReq struct {
289+
// swagger:ignore
290+
ProjectUid string `param:"project_uid" json:"project_uid" validate:"required"`
291+
// in: path
292+
// Required: true
293+
WorkflowID string `param:"workflow_id" json:"workflow_id" validate:"required"`
294+
}
295+
296+
// swagger:model GetUnmaskingWorkflowPlaintextReply
297+
type GetUnmaskingWorkflowPlaintextReply struct {
298+
Data *GetUnmaskingWorkflowPlaintext `json:"data"`
299+
base.GenericResp
300+
}
301+
302+
// swagger:model GetUnmaskingWorkflowPlaintext
303+
type GetUnmaskingWorkflowPlaintext struct {
304+
ViewState biz.UnmaskingWorkflowViewState `json:"view_state"`
305+
ViewValidUntil string `json:"view_valid_until"`
306+
UnmaskingSQLs []*UnmaskingPlaintextSQLItem `json:"unmasking_sqls"`
307+
}
308+
309+
// swagger:model UnmaskingPlaintextSQLItem
310+
type UnmaskingPlaintextSQLItem struct {
311+
UID string `json:"uid"`
312+
SQLIndexID string `json:"sql_index_id"`
313+
OriginalData *SQLQueryResult `json:"original_data"`
314+
MaskedColumns []string `json:"masked_columns"`
315+
Truncated bool `json:"truncated"`
316+
}

internal/apiserver/service/data_mask_controller.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,82 @@ func (ctl *DMSController) CancelUnmaskingWorkflow(c echo.Context) error {
857857
return NewOkRespWithReply(c, &aV1.CancelUnmaskingWorkflowReply{})
858858
}
859859

860+
// swagger:operation POST /v1/dms/projects/{project_uid}/masking/unmasking-workflows/{workflow_id}/activate Masking ActivateUnmaskingWorkflowView
861+
//
862+
// Activate plaintext view window for applicant.
863+
//
864+
// ---
865+
// parameters:
866+
// - name: project_uid
867+
// in: path
868+
// required: true
869+
// type: string
870+
// - name: workflow_id
871+
// in: path
872+
// required: true
873+
// type: string
874+
//
875+
// responses:
876+
// '200':
877+
// schema:
878+
// "$ref": "#/definitions/ActivateUnmaskingWorkflowViewReply"
879+
// default:
880+
// schema:
881+
// "$ref": "#/definitions/GenericResp"
882+
func (ctl *DMSController) ActivateUnmaskingWorkflowView(c echo.Context) error {
883+
req := &aV1.ActivateUnmaskingWorkflowViewReq{}
884+
if err := bindAndValidateReq(c, req); err != nil {
885+
return NewErrResp(c, err, apiError.BadRequestErr)
886+
}
887+
currentUserUid, err := jwt.GetUserUidStrFromContext(c)
888+
if err != nil {
889+
return NewErrResp(c, err, apiError.UnauthorizedErr)
890+
}
891+
reply, err := ctl.DMS.ActivateUnmaskingWorkflowView(c.Request().Context(), req, currentUserUid)
892+
if err != nil {
893+
return NewErrResp(c, err, apiError.DMSServiceErr)
894+
}
895+
return NewOkRespWithReply(c, reply)
896+
}
897+
898+
// swagger:operation GET /v1/dms/projects/{project_uid}/masking/unmasking-workflows/{workflow_id}/plaintext Masking GetUnmaskingWorkflowPlaintext
899+
//
900+
// Get plaintext query snapshot during active view window.
901+
//
902+
// ---
903+
// parameters:
904+
// - name: project_uid
905+
// in: path
906+
// required: true
907+
// type: string
908+
// - name: workflow_id
909+
// in: path
910+
// required: true
911+
// type: string
912+
//
913+
// responses:
914+
// '200':
915+
// schema:
916+
// "$ref": "#/definitions/GetUnmaskingWorkflowPlaintextReply"
917+
// default:
918+
// schema:
919+
// "$ref": "#/definitions/GenericResp"
920+
func (ctl *DMSController) GetUnmaskingWorkflowPlaintext(c echo.Context) error {
921+
req := &aV1.GetUnmaskingWorkflowPlaintextReq{}
922+
if err := bindAndValidateReq(c, req); err != nil {
923+
return NewErrResp(c, err, apiError.BadRequestErr)
924+
}
925+
currentUserUid, err := jwt.GetUserUidStrFromContext(c)
926+
if err != nil {
927+
return NewErrResp(c, err, apiError.UnauthorizedErr)
928+
}
929+
reply, err := ctl.DMS.GetUnmaskingWorkflowPlaintext(c.Request().Context(), req, currentUserUid)
930+
if err != nil {
931+
return NewErrResp(c, err, apiError.DMSServiceErr)
932+
}
933+
return NewOkRespWithReply(c, reply)
934+
}
935+
860936
// swagger:route GET /v1/dms/projects/{project_uid}/masking/rules/{rule_id} Masking GetMaskingRuleDetail
861937
//
862938
// 获取脱敏规则详情。

internal/data_masking/biz/unmasking_workflow.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,29 @@ const (
229229
UnmaskingActionDownloadOriginalData UnmaskingAction = "download_full_original_data"
230230
// 取消申请
231231
UnmaskingActionCancel UnmaskingAction = "cancel"
232+
// 激活查看原文(工单详情)
233+
UnmaskingActionActivateView UnmaskingAction = "activate_view"
232234
)
233235

234236
func (a UnmaskingAction) String() string {
235237
return string(a)
236238
}
237239

240+
// UnmaskingWorkflowViewState 申请人明文查看状态(详情页展示)
241+
// swagger:enum UnmaskingWorkflowViewState
242+
type UnmaskingWorkflowViewState string
243+
244+
const (
245+
UnmaskingWorkflowViewStateNotActivated UnmaskingWorkflowViewState = "not_activated"
246+
UnmaskingWorkflowViewStateActive UnmaskingWorkflowViewState = "active"
247+
UnmaskingWorkflowViewStateViewExpired UnmaskingWorkflowViewState = "view_expired"
248+
UnmaskingWorkflowViewStateActivationExpired UnmaskingWorkflowViewState = "activation_expired"
249+
)
250+
251+
func (s UnmaskingWorkflowViewState) String() string {
252+
return string(s)
253+
}
254+
238255
// 与 DMS OpRangeType 字符串取值一致,用于 UnmaskingOpPermissionRange 判定。
239256
const (
240257
UnmaskingOpRangeProject = "project"

internal/dms/service/unmasking_workflow_ce.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,11 @@ func (d *DMSService) RejectUnmaskingWorkflow(ctx context.Context, req *v1.Reject
4444
func (d *DMSService) CancelUnmaskingWorkflow(ctx context.Context, req *v1.CancelUnmaskingWorkflowReq, currentUserUid string) error {
4545
return errNotSupportUnmaskingWorkflow
4646
}
47+
48+
func (d *DMSService) ActivateUnmaskingWorkflowView(ctx context.Context, req *v1.ActivateUnmaskingWorkflowViewReq, currentUserUid string) (*v1.ActivateUnmaskingWorkflowViewReply, error) {
49+
return nil, errNotSupportUnmaskingWorkflow
50+
}
51+
52+
func (d *DMSService) GetUnmaskingWorkflowPlaintext(ctx context.Context, req *v1.GetUnmaskingWorkflowPlaintextReq, currentUserUid string) (*v1.GetUnmaskingWorkflowPlaintextReply, error) {
53+
return nil, errNotSupportUnmaskingWorkflow
54+
}

0 commit comments

Comments
 (0)