Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat:项目管理员可以在前端页面上查看对应节点下载记录 #1896 [wip] #2228

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ data class OpLogListOption(
@ApiModelProperty("事件类型")
val eventType: EventType,
@ApiModelProperty("sha256校验值")
val sha256: String?,
val sha256: String? = null,
@ApiModelProperty("流水线Id")
val pipelineId: String?,
val pipelineId: String? = null,
@ApiModelProperty("流水线构建Id")
val buildId: String?,
val buildId: String? = null,
@ApiModelProperty("下载用户Id")
val userId: String?,
val userId: String? = null,
@ApiModelProperty("查询起始时间")
val startTime: LocalDateTime = LocalDateTime.now().minusMonths(3L),
@ApiModelProperty("查询截至时间")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,14 @@ import com.tencent.bkrepo.common.artifact.api.ArtifactInfo
import com.tencent.bkrepo.common.artifact.api.ArtifactPathVariable
import com.tencent.bkrepo.common.artifact.api.DefaultArtifactInfo
import com.tencent.bkrepo.common.artifact.constant.ARTIFACT_INFO_KEY
import com.tencent.bkrepo.common.artifact.event.base.EventType
import com.tencent.bkrepo.common.artifact.message.ArtifactMessageCode
import com.tencent.bkrepo.common.artifact.router.Router
import com.tencent.bkrepo.common.artifact.util.PipelineRepoUtils
import com.tencent.bkrepo.common.mongo.dao.util.Pages
import com.tencent.bkrepo.common.operate.api.OperateLogService
import com.tencent.bkrepo.common.operate.api.pojo.OpLogListOption
import com.tencent.bkrepo.common.operate.api.pojo.OperateLog
import com.tencent.bkrepo.common.query.model.QueryModel
import com.tencent.bkrepo.common.security.manager.PermissionManager
import com.tencent.bkrepo.common.security.permission.Permission
Expand All @@ -56,6 +60,7 @@ import com.tencent.bkrepo.generic.artifact.GenericArtifactInfo.Companion.BATCH_M
import com.tencent.bkrepo.generic.artifact.GenericArtifactInfo.Companion.BLOCK_MAPPING_URI
import com.tencent.bkrepo.generic.artifact.GenericArtifactInfo.Companion.GENERIC_MAPPING_URI
import com.tencent.bkrepo.generic.constant.HEADER_UPLOAD_ID
import com.tencent.bkrepo.generic.model.GenericPageRequest
import com.tencent.bkrepo.generic.pojo.BatchDownloadPaths
import com.tencent.bkrepo.generic.pojo.BlockInfo
import com.tencent.bkrepo.generic.pojo.CompressedFileInfo
Expand All @@ -76,13 +81,15 @@ import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import java.time.LocalDateTime

@RestController
class GenericController(
private val uploadService: UploadService,
private val downloadService: DownloadService,
private val permissionManager: PermissionManager,
private val compressedFileService: CompressedFileService,
private val operateLogService: OperateLogService
) {

@PutMapping(GENERIC_MAPPING_URI)
Expand Down Expand Up @@ -219,4 +226,25 @@ class GenericController(
val page = Pages.ofResponse(pageRequest, 0L, downloadService.search(queryModel))
return ResponseBuilder.success(page)
}

@ApiOperation("分页查询下载历史")
@PostMapping("/download/record/page")
fun getDownloadRecord(
lannoy0523 marked this conversation as resolved.
Show resolved Hide resolved
@RequestBody genericPageRequest: GenericPageRequest
): Response<Page<OperateLog>> {
with(genericPageRequest) {
permissionManager.checkProjectPermission(PermissionAction.MANAGE, projectId)
val option = OpLogListOption(
projectId = projectId,
repoName = repoName,
resourceKey = path,
pageNumber = pageNumber,
pageSize = pageSize,
eventType = EventType.NODE_DOWNLOADED,
startTime = LocalDateTime.now().minusYears(1),
endTime = LocalDateTime.now()
)
return ResponseBuilder.success((operateLogService.listPage(option)))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available.
*
* Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
*
* BK-CI 蓝鲸持续集成平台 is licensed under the MIT license.
*
* A copy of the MIT License is included in this file.
*
*
* Terms of the MIT License:
* ---------------------------------------------------
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package com.tencent.bkrepo.generic.model

import com.tencent.bkrepo.common.api.constant.DEFAULT_PAGE_NUMBER
import com.tencent.bkrepo.common.api.constant.DEFAULT_PAGE_SIZE

class GenericPageRequest (
var projectId: String,
var repoName: String,
var path: String,
var pageNumber: Int = DEFAULT_PAGE_NUMBER,
var pageSize: Int = DEFAULT_PAGE_SIZE
)
13 changes: 13 additions & 0 deletions src/frontend/devops-repository/src/store/actions/repoGeneric.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,5 +391,18 @@ export default {
}
}
)
},
// 查询节点下载历史
getDownloadRecord (_, { projectId, repoName, path, pageNumber, pageSize = 15 }) {
return Vue.prototype.$ajax.post(
'generic/download/record/page',
{
projectId: projectId,
repoName: repoName,
path: path,
pageNumber: pageNumber,
pageSize: pageSize
}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
:title="detailSlider.data.name"
@click.native.stop="() => {}"
:quick-close="true"
@hidden="resetHistory"
:width="720">
<template #content>
<bk-tab class="detail-container" type="unborder-card" :active.sync="tabName">
Expand Down Expand Up @@ -86,6 +87,41 @@
</bk-table>
</div>
</bk-tab-panel>
<bk-tab-panel v-if="userInfo.admin || userInfo.manage" name="downloadRecord" :label="$t('downloadHistory')">
<div class="version-metadata display-block" :data-title="$t('downloadHistory')">
<bk-table
:data="downloadRecord"
:outer-border="false"
:row-border="false"
>
<template #empty>
<empty-data :is-loading="detailSlider.loading"></empty-data>
</template>
<bk-table-column :label="$t('downloader')">
<template #default="{ row }">
{{ row.userId }}
</template>
</bk-table-column>
<bk-table-column :label="$t('downloadDate')">
<template #default="{ row }">
{{ formatDate(row.createdDate) }}
</template>
</bk-table-column>
</bk-table>
<div class="p10 bk-page bk-page-align-right bk-page-small">
<bk-pagination
size="small"
:align="pagination.align"
:current.sync="pagination.current"
@change="current => handlerPaginationChange({ current })"
:limit="pagination.limit"
:show-limit="false"
:limit-list="pagination.limitList"
:count="pagination.count"
/>
</div>
</div>
</bk-tab-panel>
</bk-tab>
</template>
</bk-sideslider>
Expand Down Expand Up @@ -140,7 +176,15 @@
},
showIamDenyDialog: false,
showData: {},
hasErr: false
hasErr: false,
downloadRecord: [],
pagination: {
count: 0,
current: 1,
limit: 15,
limitList: [15],
align: 'left'
}
}
},
computed: {
Expand All @@ -164,13 +208,17 @@
}
},
methods: {
...mapActions(['getNodeDetail', 'addMetadata', 'deleteMetadata', 'getPermissionUrl']),
formatDate,
...mapActions(['getNodeDetail', 'addMetadata', 'deleteMetadata', 'getPermissionUrl', 'getDownloadRecord']),
setData (data) {
this.detailSlider = {
...this.detailSlider,
...data
}
this.getDetail()
if (this.userInfo.admin || this.userInfo.manage) {
this.getDownloadHistory()
}
},
getDetail () {
this.detailSlider.loading = true
Expand Down Expand Up @@ -282,6 +330,27 @@
})
this.getDetail()
})
},
getDownloadHistory () {
this.getDownloadRecord({
projectId: this.detailSlider.projectId,
repoName: this.detailSlider.repoName,
path: this.detailSlider.path,
pageNumber: this.pagination.current,
pageSize: this.pagination.limit
}).then(res => {
this.downloadRecord = res.records
this.pagination.count = res.totalRecords
})
},
handlerPaginationChange ({ current = 1 }) {
this.pagination.current = current
this.getDownloadHistory()
},
resetHistory () {
this.downloadRecord = []
this.pagination.count = 0
this.pagination.current = 1
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/frontend/locale/repository/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -873,5 +873,8 @@
"bkci": "BKCI",
"rootDirectoryPermission": "Access Control:",
"rootDirectoryPermissionTip": "After Open, Member access path in the repo need auth.",
"errMsg": "Error Message"
"errMsg": "Error Message",
"downloadHistory": "Download History(Last Year)",
"downloadDate": "Download Date",
"downloader": "Downloader"
}
5 changes: 4 additions & 1 deletion src/frontend/locale/repository/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -874,5 +874,8 @@
"bkci": "蓝盾",
"rootDirectoryPermission": "访问控制:",
"rootDirectoryPermissionTip": "开启之后项目成员访问此仓库下路径需要授权",
"errMsg": "错误信息"
"errMsg": "错误信息",
"downloadHistory": "下载历史(最近一年)",
"downloadDate": "下载时间",
"downloader": "下载用户"
}
Loading