feat(tasks): 删除任务可选连带删除资产/漏洞/流量/文件(默认不选)
删除弹窗新增四个默认不勾的复选框:
- 删除关联的资产:仅删本任务独有资产,与其他任务共享的仅解除关联(保留)。
- 删除发现的漏洞:删本任务全部 findings。
- 删除测试的流量:按本任务资产的 host 清录制流量(host 无任务标签,会连带清
其他任务命中同一 host 的流量)。
- 删除测试过程中写的文件:删 <workDir>/tasks/<id> 目录(worker 产物 + 上传)。
- db: AssetStore.DeleteByTaskID(独有删+共享解关联)/HostsByTask;DeleteFindingsByTask。
- server: pgDeleteTask 读可选 JSON body {assets,findings,traffic,files},先按 host
清流量(需在删资产前取 host)→删漏洞→删资产→删任务→删文件目录;空 body=只删任务。
- web: api.deleteTask(id,opts);删除弹窗四复选框(默认不选)+说明。
go build/vet、tsc 通过;新增 TestDeleteByTaskID(独有删/共享解关联/host 反查)。
This commit is contained in:
1 parent
2aeb2e49da
commit
4f7c1a199d
6 files changed
+215
-14
No files matched your search
@@ -1053,6 +1053,45 @@ func (s *AssetStore) GetByIDs(ids []int64) ([]*Asset, error) {
|
||||
return scanAssets(rows)
|
||||
}
|
||||
|
||||
// DeleteByTaskID removes a task's assets: hard-deletes assets owned solely by this
|
||||
// task (task_ids = {taskID}) and de-associates the rest (drops this task from their
|
||||
// task_ids, keeping assets shared with other tasks intact). Returns rows deleted.
|
||||
func (s *AssetStore) DeleteByTaskID(taskID int64) (int64, error) {
|
||||
res, err := s.db.Exec(`DELETE FROM assets WHERE task_ids = ARRAY[$1]::bigint[]`, taskID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
n, _ := res.RowsAffected()
|
||||
if _, err := s.db.Exec(`UPDATE assets SET task_ids = array_remove(task_ids, $1) WHERE $1 = ANY(task_ids)`, taskID); err != nil {
|
||||
return n, err
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// HostsByTask returns the distinct hostnames/IPs the task's assets carry (domain,
|
||||
// root_domain, ip) — used to purge host-keyed traffic recorded for that task.
|
||||
func (s *AssetStore) HostsByTask(taskID int64) ([]string, error) {
|
||||
rows, err := s.db.Query(`
|
||||
SELECT DISTINCT h FROM (
|
||||
SELECT NULLIF(domain,'') AS h FROM assets WHERE $1 = ANY(task_ids)
|
||||
UNION SELECT NULLIF(root_domain,'') FROM assets WHERE $1 = ANY(task_ids)
|
||||
UNION SELECT NULLIF(ip,'') FROM assets WHERE $1 = ANY(task_ids)
|
||||
) q WHERE h IS NOT NULL AND h <> ''`, taskID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var out []string
|
||||
for rows.Next() {
|
||||
var h string
|
||||
if err := rows.Scan(&h); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out = append(out, h)
|
||||
}
|
||||
return out, rows.Err()
|
||||
}
|
||||
|
||||
// DeleteByCompanyID hard-deletes all assets belonging to a company. Returns rows deleted.
|
||||
func (s *AssetStore) DeleteByCompanyID(companyID int64) (int64, error) {
|
||||
res, err := s.db.Exec(`DELETE FROM assets WHERE company_id = $1`, companyID)
|
||||
|
||||
Reference in new issue
Block a user