Skip to content
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 @@ -73,4 +73,19 @@ interface ServiceBkRepoResource {
@QueryParam("enabled")
enabled: Boolean
): Result<Boolean>

@Operation(summary = "更新项目共享制品开关")
@Path("/{projectId}/share/enabled")
@POST
fun updateShareEnabled(
@Parameter(description = "用户ID", required = true)
@HeaderParam(AUTH_HEADER_USER_ID)
userId: String,
@Parameter(description = "项目ID", required = true)
@PathParam("projectId")
projectId: String,
@Parameter(description = "是否允许共享制品", required = true)
@QueryParam("enabled")
enabled: Boolean
): Result<Boolean>
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,12 @@ class ServiceBkRepoResourceImpl(
): Result<Boolean> {
return Result(bkRepoClient.enableProject(userId, projectId, enabled))
}

override fun updateShareEnabled(
userId: String,
projectId: String,
enabled: Boolean
): Result<Boolean> {
return Result(bkRepoClient.updateProjectShareEnabled(userId, projectId, enabled))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,19 @@ class BkRepoClient constructor(
return true
}

fun updateProjectShareEnabled(userId: String, projectId: String, enabled: Boolean): Boolean {
logger.info("updateProjectShareEnabled, userId: $userId, projectId: $projectId, enabled: $enabled")
val url = "${getGatewayUrl()}/bkrepo/api/service/repository/api/project/$projectId/share/enabled" +
"?enabled=$enabled"
val request = Request.Builder()
.url(url)
.headers(getCommonHeaders(userId, projectId).toHeaders())
.put("".toRequestBody(JSON_MEDIA_TYPE))
.build()
doRequest(request).resolveResponse<Response<Void>>()
return true
}

private fun createGenericRepo(
userId: String,
projectId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ data class ProjectProperties(
@get:Schema(title = "构建日志归档阈值(单位:万)")
var loggingLineLimit: Int? = null,
@get:Schema(title = "是否启用观察员模式", required = false)
val remotedevObserver: Boolean? = null
val remotedevObserver: Boolean? = null,
@get:Schema(title = "是否允许共享制品", required = false)
var enableShareArtifact: Boolean? = true
) {
/**
* 接受前端请求时,只复制前端展示修改的值,由op控制的值不能修改
Expand All @@ -79,7 +81,8 @@ data class ProjectProperties(
pipelineDialect = pipelineDialect,
enablePipelineNameTips = enablePipelineNameTips,
pipelineNameFormat = pipelineNameFormat,
loggingLineLimit = loggingLineLimit
loggingLineLimit = loggingLineLimit,
enableShareArtifact = enableShareArtifact
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available.
*
* Copyright (C) 2019 Tencent. 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.devops.project.pojo

import com.fasterxml.jackson.core.type.TypeReference
import com.tencent.devops.common.api.util.JsonUtil
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.Test

class ProjectPropertiesTest {

@Test
fun `enableShareArtifact default value should be true`() {
val properties = ProjectProperties()
assertEquals(true, properties.enableShareArtifact)
}

@Test
fun `enableShareArtifact can be set to false`() {
val properties = ProjectProperties(enableShareArtifact = false)
assertEquals(false, properties.enableShareArtifact)
}

@Test
fun `enableShareArtifact can be set to null`() {
val properties = ProjectProperties(enableShareArtifact = null)
assertNull(properties.enableShareArtifact)
}

@Test
fun `userCopy should copy enableShareArtifact`() {
val original = ProjectProperties(enableShareArtifact = true)
val update = ProjectProperties(enableShareArtifact = false)
val result = original.userCopy(update)
assertEquals(false, result.enableShareArtifact)
}

@Test
fun `userCopy should preserve enableShareArtifact when update is null`() {
val original = ProjectProperties(enableShareArtifact = false)
val update = ProjectProperties(enableShareArtifact = null)
val result = original.userCopy(update)
assertNull(result.enableShareArtifact)
}

@Test
fun `enableShareArtifact should serialize and deserialize correctly`() {
val properties = ProjectProperties(enableShareArtifact = false)
val json = JsonUtil.toJson(properties)
val deserialized = JsonUtil.to(json, object : TypeReference<ProjectProperties>() {})
assertEquals(false, deserialized.enableShareArtifact)
}

@Test
fun `enableShareArtifact default should serialize and deserialize correctly`() {
val properties = ProjectProperties()
val json = JsonUtil.toJson(properties)
val deserialized = JsonUtil.to(json, object : TypeReference<ProjectProperties>() {})
assertEquals(true, deserialized.enableShareArtifact)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class SimpleProjectExtService @Autowired constructor(
logoAddress: String?
) {
client.get(ServiceBkRepoResource::class).createProjectResource(userId, projectCreateInfo.englishName)
// 同步共享制品开关配置到 BkRepo,默认为 true
val enableShareArtifact = projectCreateInfo.properties?.enableShareArtifact ?: true
updateShareArtifact(userId, projectCreateInfo.englishName, enableShareArtifact)
}

override fun createOldAuthProject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,13 @@ class ProjectApprovalService @Autowired constructor(
)
}
}
// 同步共享制品开关变更到 BkRepo
projectExtService.syncShareArtifactIfChanged(
userId = applicant,
projectId = projectId,
oldProperties = projectProperties,
newProperties = updateProjectProperties
)
}

fun updateRejectOrRevoke(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ package com.tencent.devops.project.service

import com.tencent.devops.project.pojo.ProjectCreateExtInfo
import com.tencent.devops.project.pojo.ProjectCreateInfo
import com.tencent.devops.project.pojo.ProjectProperties

/**
* 外部项目服务类
Expand Down Expand Up @@ -62,4 +63,23 @@ interface ProjectExtService {
projectId: String,
enabled: Boolean
): Boolean

/**
* 更新项目共享制品开关
*/
fun updateShareArtifact(
userId: String,
projectId: String,
enabled: Boolean
): Boolean

/**
* 检测并同步共享制品开关变更到 BkRepo
*/
fun syncShareArtifactIfChanged(
userId: String,
projectId: String,
oldProperties: ProjectProperties?,
newProperties: ProjectProperties?
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.tencent.devops.project.service.impl

import com.tencent.devops.artifactory.api.service.ServiceBkRepoResource
import com.tencent.devops.common.client.Client
import com.tencent.devops.project.pojo.ProjectProperties
import com.tencent.devops.project.service.ProjectExtService
import org.springframework.beans.factory.annotation.Autowired

Expand All @@ -13,4 +14,22 @@ abstract class AbsProjectExtServiceImpl : ProjectExtService {
client.get(ServiceBkRepoResource::class).enableProject(userId, projectId, enabled)
return true
}

override fun updateShareArtifact(userId: String, projectId: String, enabled: Boolean): Boolean {
client.get(ServiceBkRepoResource::class).updateShareEnabled(userId, projectId, enabled)
return true
}

override fun syncShareArtifactIfChanged(
userId: String,
projectId: String,
oldProperties: ProjectProperties?,
newProperties: ProjectProperties?
) {
val newEnabled = newProperties?.enableShareArtifact ?: return
val oldEnabled = oldProperties?.enableShareArtifact ?: true
if (oldEnabled != newEnabled) {
updateShareArtifact(userId, projectId, newEnabled)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ import com.tencent.devops.project.service.ProjectService
import com.tencent.devops.project.service.ShardingRoutingRuleAssignService
import com.tencent.devops.project.util.ProjectUtils
import com.tencent.devops.project.util.exception.ProjectNotExistException
import jakarta.ws.rs.NotFoundException
import org.glassfish.jersey.media.multipart.FormDataContentDisposition
import org.jooq.DSLContext
import org.jooq.impl.DSL
Expand All @@ -126,7 +127,6 @@ import org.springframework.dao.DuplicateKeyException
import java.io.File
import java.io.InputStream
import java.util.regex.Pattern
import jakarta.ws.rs.NotFoundException

@Suppress("ALL")
abstract class AbsProjectServiceImpl @Autowired constructor(
Expand Down Expand Up @@ -231,6 +231,9 @@ abstract class AbsProjectServiceImpl @Autowired constructor(
needValidate = createExtInfo.needValidate!!,
projectCreateInfo = projectCreateInfo
)
projectCreateInfo.properties?.let {
it.enableShareArtifact = false
}
val userDeptDetail = getDeptInfo(userId)
var projectId = defaultProjectId
val subjectScopes = projectCreateInfo.subjectScopes!!.ifEmpty {
Expand Down Expand Up @@ -625,6 +628,13 @@ abstract class AbsProjectServiceImpl @Autowired constructor(
)
}
}
// 同步共享制品开关变更到 BkRepo
projectExtService.syncShareArtifactIfChanged(
userId = userId,
projectId = englishName,
oldProperties = properties,
newProperties = projectUpdateInfo.properties
)
}
// 记录项目更新记录
val projectUpdateHistoryInfo = ProjectUpdateHistoryInfo(
Expand Down