Skip to content

Commit

Permalink
Add audit templates
Browse files Browse the repository at this point in the history
  • Loading branch information
shuofan committed Nov 16, 2021
1 parent 2e137a7 commit 8f7e083
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
12 changes: 6 additions & 6 deletions apistructs/audits.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,12 @@ const (
UpdateAppNotifyGroupTemplate TemplateName = "updateAppNotifyGroup"

// ========================Test Platform================================
QaTestEnvCreateTemplate TemplateName = "qaTestEnvCreate"
QaTestEnvUpdateTemplate TemplateName = "qaTestEnvUpdate"
QaTestEnvDeleteTemplate TemplateName = "qaTestEnvDelete"
ArchiveTestplanTemplate TemplateName = "archiveTestPlan"
UnarchiveTestPlanTemplate TemplateName = "unarchiveTestPlan"
UpdateAutoTestSpaceTemplate TemplateName = "updateAutoTestSpace"
QaTestEnvCreateTemplate TemplateName = "qaTestEnvCreate"
QaTestEnvUpdateTemplate TemplateName = "qaTestEnvUpdate"
QaTestEnvDeleteTemplate TemplateName = "qaTestEnvDelete"
ArchiveTestplanTemplate TemplateName = "archiveTestPlan"
UnarchiveTestPlanTemplate TemplateName = "unarchiveTestPlan"
UpdateAutoTestSpaceTemplatePrefix string = "updateAutoTestSpace"
// ========================cmdb==========================================
CreateCertificatesTemplate TemplateName = "createCertificates"
DeleteCertificatesTemplate TemplateName = "deleteCertificates"
Expand Down
13 changes: 13 additions & 0 deletions apistructs/autotest_space.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ const (
TestSpaceCompleted AutoTestSpaceArchiveStatus = "Completed"
)

func (s AutoTestSpaceArchiveStatus) GetZhName() string {
switch s {
case TestSpaceInit:
return "未开始"
case TestSpaceInProgress:
return "进行中"
case TestSpaceCompleted:
return "已完成"
default:
return ""
}
}

func (s AutoTestSpaceArchiveStatus) Valid() bool {
switch s {
case TestSpaceInit, TestSpaceInProgress, TestSpaceCompleted:
Expand Down
9 changes: 4 additions & 5 deletions modules/dop/services/autotest_v2/space.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,19 +160,19 @@ func getChangedFields(autoTestSpace *dao.AutoTestSpace, req apistructs.AutoTestS
changedField := make(map[string][]string)
if len(req.Name) > 0 {
if req.Name != autoTestSpace.Name {
changedField["name"] = []string{autoTestSpace.Name, req.Name}
changedField["Name"] = []string{autoTestSpace.Name, req.Name}
}
autoTestSpace.Name = req.Name
}
if len(req.ArchiveStatus) > 0 {
if req.ArchiveStatus != autoTestSpace.ArchiveStatus {
changedField["archiveStatus"] = []string{string(autoTestSpace.ArchiveStatus), string(req.ArchiveStatus)}
changedField["ArchiveStatus"] = []string{autoTestSpace.ArchiveStatus.GetZhName(), req.ArchiveStatus.GetZhName()}
}
autoTestSpace.ArchiveStatus = req.ArchiveStatus
}
if len(req.Description) > 0 {
if req.Description != autoTestSpace.Description {
changedField["description"] = []string{autoTestSpace.Description, req.Description}
changedField["Description"] = []string{autoTestSpace.Description, req.Description}
}
autoTestSpace.Description = req.Description
}
Expand All @@ -198,11 +198,10 @@ func (svc *Service) createAudits(space *dao.AutoTestSpace, changedField map[stri
Result: "success",
StartTime: now,
EndTime: now,
TemplateName: apistructs.UpdateAutoTestSpaceTemplate,
TemplateName: apistructs.TemplateName(apistructs.UpdateAutoTestSpaceTemplatePrefix + i),
Context: map[string]interface{}{
"projectName": project.Name,
"spaceName": space.Name,
"field": i,
"from": v[0],
"to": v[1],
},
Expand Down
22 changes: 18 additions & 4 deletions pkg/erda-configs/audit/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -1939,11 +1939,25 @@
"en": "Change MySQL account [@preMysqlUsername] -> [@mysqlUsername] for runtime [@runtimeName](runtimeDetailRoot) in [@projectName](project) / [@appName](app)"
}
},
"updateAutoTestSpace": {
"desc": "更新自动化测试空间",
"updateAutoTestSpaceName": {
"desc": "更新自动化测试空间名称",
"success": {
"zh": "在 [@projectName](project) 项目中, 更新了测试空间 [@spaceName] 的[@field], 由 [@from] 变成 [@to] ",
"en": "Update auto test space [@spaceName] [@field] from [@from] to [@to] in project [@projectName](project)"
"zh": "在 [@projectName](project) 项目中, 更新了测试空间 [@spaceName] 的名称, 由 [@from] 变成 [@to] ",
"en": "Update auto test space [@spaceName] name from [@from] to [@to] in project [@projectName](project)"
}
},
"updateAutoTestSpaceDescription": {
"desc": "更新自动化测试空间描述",
"success": {
"zh": "在 [@projectName](project) 项目中, 更新了测试空间 [@spaceName] 的描述, 由 [@from] 变成 [@to] ",
"en": "Update auto test space [@spaceName] description from [@from] to [@to] in project [@projectName](project)"
}
},
"updateAutoTestSpaceArchiveStatus": {
"desc": "更新自动化测试空间状态",
"success": {
"zh": "在 [@projectName](project) 项目中, 更新了测试空间 [@spaceName] 的状态, 由 [@from] 变成 [@to] ",
"en": "Update auto test space [@spaceName] archiveStatus from [@from] to [@to] in project [@projectName](project)"
}
}
}

0 comments on commit 8f7e083

Please sign in to comment.