From 35aab2e7a74ca2a7dca1d58b6c1b67834420b925 Mon Sep 17 00:00:00 2001 From: yaoxuwan Date: Mon, 3 Jul 2023 20:33:15 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20=E5=88=9B=E5=BB=BA=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=97=B6=EF=BC=8C=E5=A2=9E=E5=8A=A0=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E6=9C=AC=E5=9C=B0=E6=9D=83=E9=99=90=E5=8F=82?= =?UTF-8?q?=E6=95=B0=20#879?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/artifact/event/project/ProjectCreatedEvent.kt | 3 ++- .../bkrepo/repository/pojo/project/ProjectCreateRequest.kt | 2 ++ .../bkrepo/repository/listener/ResourcePermissionListener.kt | 3 +++ .../com/tencent/bkrepo/repository/util/ProjectEventFactory.kt | 3 ++- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/backend/common/common-artifact/artifact-api/src/main/kotlin/com/tencent/bkrepo/common/artifact/event/project/ProjectCreatedEvent.kt b/src/backend/common/common-artifact/artifact-api/src/main/kotlin/com/tencent/bkrepo/common/artifact/event/project/ProjectCreatedEvent.kt index fa7d5350e3..4aeef9529a 100644 --- a/src/backend/common/common-artifact/artifact-api/src/main/kotlin/com/tencent/bkrepo/common/artifact/event/project/ProjectCreatedEvent.kt +++ b/src/backend/common/common-artifact/artifact-api/src/main/kotlin/com/tencent/bkrepo/common/artifact/event/project/ProjectCreatedEvent.kt @@ -36,7 +36,8 @@ import com.tencent.bkrepo.common.artifact.event.base.EventType */ data class ProjectCreatedEvent( override val projectId: String, - override val userId: String + override val userId: String, + val createPermission: Boolean ) : ArtifactEvent( type = EventType.PROJECT_CREATED, projectId = projectId, diff --git a/src/backend/repository/api-repository/src/main/kotlin/com/tencent/bkrepo/repository/pojo/project/ProjectCreateRequest.kt b/src/backend/repository/api-repository/src/main/kotlin/com/tencent/bkrepo/repository/pojo/project/ProjectCreateRequest.kt index da4e2d2be8..17634e047d 100644 --- a/src/backend/repository/api-repository/src/main/kotlin/com/tencent/bkrepo/repository/pojo/project/ProjectCreateRequest.kt +++ b/src/backend/repository/api-repository/src/main/kotlin/com/tencent/bkrepo/repository/pojo/project/ProjectCreateRequest.kt @@ -43,6 +43,8 @@ data class ProjectCreateRequest( val displayName: String, @ApiModelProperty("描述", required = true) val description: String? = null, + @ApiModelProperty("创建权限", required = false) + val createPermission: Boolean = true, @ApiModelProperty("操作用户", required = false) val operator: String = SYSTEM_USER ) : ProjectRequest diff --git a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/listener/ResourcePermissionListener.kt b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/listener/ResourcePermissionListener.kt index 12eab2133f..9471fa3aba 100644 --- a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/listener/ResourcePermissionListener.kt +++ b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/listener/ResourcePermissionListener.kt @@ -56,6 +56,9 @@ class ResourcePermissionListener( */ fun handle(event: ProjectCreatedEvent) { with(event) { + if (!createPermission) { + return + } if (isAuthedNormalUser(userId) && isNeedLocalPermission(projectId)) { val projectManagerRoleId = roleResource.createProjectManage(projectId).data!! userResource.addUserRole(userId, projectManagerRoleId) diff --git a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/util/ProjectEventFactory.kt b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/util/ProjectEventFactory.kt index 39c6b8c3b7..611fda52d6 100644 --- a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/util/ProjectEventFactory.kt +++ b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/util/ProjectEventFactory.kt @@ -15,7 +15,8 @@ object ProjectEventFactory { with(request) { return ProjectCreatedEvent( projectId = name, - userId = operator + userId = operator, + createPermission = createPermission ) } } From 0b1b265fa7966b582d7f669d3bc0f0572657ec3e Mon Sep 17 00:00:00 2001 From: yaoxuwan Date: Tue, 4 Jul 2023 10:26:16 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20=E5=88=9B=E5=BB=BA=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=97=B6=EF=BC=8C=E5=A2=9E=E5=8A=A0=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E6=9C=AC=E5=9C=B0=E6=9D=83=E9=99=90=E5=8F=82?= =?UTF-8?q?=E6=95=B0=20#879?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../replica/edge/EdgePullReplicaExecutor.kt | 8 ++++- .../repository/service/ProjectServiceTest.kt | 30 +++++++++---------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/backend/replication/biz-replication/src/main/kotlin/com/tencent/bkrepo/replication/replica/edge/EdgePullReplicaExecutor.kt b/src/backend/replication/biz-replication/src/main/kotlin/com/tencent/bkrepo/replication/replica/edge/EdgePullReplicaExecutor.kt index 857ef14d3a..d7fdb65d56 100644 --- a/src/backend/replication/biz-replication/src/main/kotlin/com/tencent/bkrepo/replication/replica/edge/EdgePullReplicaExecutor.kt +++ b/src/backend/replication/biz-replication/src/main/kotlin/com/tencent/bkrepo/replication/replica/edge/EdgePullReplicaExecutor.kt @@ -183,7 +183,13 @@ class EdgePullReplicaExecutor( localProjectId: String, localRepoName: String, ): RepositoryDetail { - val projectCreateRequest = ProjectCreateRequest(localProjectId, localProjectId, null, centerRepo.createdBy) + val projectCreateRequest = ProjectCreateRequest( + name = localProjectId, + displayName = localProjectId, + description = null, + createPermission = true, + operator = centerRepo.createdBy + ) try { projectClient.createProject(projectCreateRequest) } catch (e: RemoteErrorCodeException) { diff --git a/src/backend/repository/biz-repository/src/test/kotlin/com/tencent/bkrepo/repository/service/ProjectServiceTest.kt b/src/backend/repository/biz-repository/src/test/kotlin/com/tencent/bkrepo/repository/service/ProjectServiceTest.kt index 3d46d68f54..2950218312 100644 --- a/src/backend/repository/biz-repository/src/test/kotlin/com/tencent/bkrepo/repository/service/ProjectServiceTest.kt +++ b/src/backend/repository/biz-repository/src/test/kotlin/com/tencent/bkrepo/repository/service/ProjectServiceTest.kt @@ -70,14 +70,14 @@ class ProjectServiceTest @Autowired constructor( @Test @DisplayName("测试创建项目") fun `test create project`() { - val request = ProjectCreateRequest(UT_PROJECT_ID, UT_PROJECT_DISPLAY, UT_PROJECT_DESC, UT_USER) + val request = ProjectCreateRequest(UT_PROJECT_ID, UT_PROJECT_DISPLAY, UT_PROJECT_DESC, true, UT_USER) projectService.createProject(request) } @Test @DisplayName("测试创建同名项目") fun `should throw exception when project exists`() { - val request = ProjectCreateRequest(UT_PROJECT_ID, UT_PROJECT_DISPLAY, UT_PROJECT_DESC, UT_USER) + val request = ProjectCreateRequest(UT_PROJECT_ID, UT_PROJECT_DISPLAY, UT_PROJECT_DESC, true, UT_USER) projectService.createProject(request) assertThrows { projectService.createProject(request) } } @@ -85,48 +85,48 @@ class ProjectServiceTest @Autowired constructor( @Test @DisplayName("测试非法项目名称") fun `should throw exception with illegal name`() { - var request = ProjectCreateRequest("1", UT_PROJECT_DISPLAY, UT_PROJECT_DESC, UT_USER) + var request = ProjectCreateRequest("1", UT_PROJECT_DISPLAY, UT_PROJECT_DESC, true, UT_USER) assertThrows { projectService.createProject(request) } - request = ProjectCreateRequest("11", UT_PROJECT_DISPLAY, UT_PROJECT_DESC, UT_USER) + request = ProjectCreateRequest("11", UT_PROJECT_DISPLAY, UT_PROJECT_DESC, true, UT_USER) assertThrows { projectService.createProject(request) } - request = ProjectCreateRequest("a".repeat(33), UT_PROJECT_DISPLAY, UT_PROJECT_DESC, UT_USER) + request = ProjectCreateRequest("a".repeat(33), UT_PROJECT_DISPLAY, UT_PROJECT_DESC, true, UT_USER) assertThrows { projectService.createProject(request) } - request = ProjectCreateRequest("test_1", UT_PROJECT_DISPLAY, UT_PROJECT_DESC, UT_USER) + request = ProjectCreateRequest("test_1", UT_PROJECT_DISPLAY, UT_PROJECT_DESC, true, UT_USER) projectService.createProject(request) - request = ProjectCreateRequest("test-1", UT_PROJECT_DISPLAY, UT_PROJECT_DESC, UT_USER) + request = ProjectCreateRequest("test-1", UT_PROJECT_DISPLAY, UT_PROJECT_DESC, true, UT_USER) projectService.createProject(request) - request = ProjectCreateRequest("a1", UT_PROJECT_DISPLAY, UT_PROJECT_DESC, UT_USER) + request = ProjectCreateRequest("a1", UT_PROJECT_DISPLAY, UT_PROJECT_DESC, true, UT_USER) projectService.createProject(request) - request = ProjectCreateRequest("_prebuild", UT_PROJECT_DISPLAY, UT_PROJECT_DESC, UT_USER) + request = ProjectCreateRequest("_prebuild", UT_PROJECT_DISPLAY, UT_PROJECT_DESC, true, UT_USER) projectService.createProject(request) - request = ProjectCreateRequest("CODECC_a1", UT_PROJECT_DISPLAY, UT_PROJECT_DESC, UT_USER) + request = ProjectCreateRequest("CODECC_a1", UT_PROJECT_DISPLAY, UT_PROJECT_DESC, true, UT_USER) projectService.createProject(request) } @Test @DisplayName("测试非法项目显示名") fun `should throw exception with illegal display name`() { - var request = ProjectCreateRequest(UT_PROJECT_ID, "", UT_PROJECT_DESC, UT_USER) + var request = ProjectCreateRequest(UT_PROJECT_ID, "", UT_PROJECT_DESC, true, UT_USER) assertThrows { projectService.createProject(request) } - request = ProjectCreateRequest(UT_PROJECT_ID, "1".repeat(33), UT_PROJECT_DESC, UT_USER) + request = ProjectCreateRequest(UT_PROJECT_ID, "1".repeat(33), UT_PROJECT_DESC, true, UT_USER) assertThrows { projectService.createProject(request) } - request = ProjectCreateRequest(UT_PROJECT_ID, "1".repeat(1), UT_PROJECT_DESC, UT_USER) + request = ProjectCreateRequest(UT_PROJECT_ID, "1".repeat(1), UT_PROJECT_DESC, true, UT_USER) assertThrows { projectService.createProject(request) } - request = ProjectCreateRequest(UT_PROJECT_ID, "1".repeat(32), UT_PROJECT_DESC, UT_USER) + request = ProjectCreateRequest(UT_PROJECT_ID, "1".repeat(32), UT_PROJECT_DESC, true, UT_USER) projectService.createProject(request) removeAllProject() - request = ProjectCreateRequest(UT_PROJECT_ID, "123-abc", UT_PROJECT_DESC, UT_USER) + request = ProjectCreateRequest(UT_PROJECT_ID, "123-abc", UT_PROJECT_DESC, true, UT_USER) projectService.createProject(request) } From d805705568315a7018711ab8f76f49e122655b2c Mon Sep 17 00:00:00 2001 From: yaoxuwan Date: Tue, 4 Jul 2023 12:06:59 +0800 Subject: [PATCH 3/4] =?UTF-8?q?feat:=20=E5=88=9B=E5=BB=BA=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=97=B6=EF=BC=8C=E5=A2=9E=E5=8A=A0=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E6=9C=AC=E5=9C=B0=E6=9D=83=E9=99=90=E5=8F=82?= =?UTF-8?q?=E6=95=B0=20#879?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bkrepo/repository/service/RepositoryServiceTest.kt | 8 +++++++- .../bkrepo/repository/service/ServiceBaseTest.kt | 10 ++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/backend/repository/biz-repository/src/test/kotlin/com/tencent/bkrepo/repository/service/RepositoryServiceTest.kt b/src/backend/repository/biz-repository/src/test/kotlin/com/tencent/bkrepo/repository/service/RepositoryServiceTest.kt index 9980f11c78..bf3a04650c 100644 --- a/src/backend/repository/biz-repository/src/test/kotlin/com/tencent/bkrepo/repository/service/RepositoryServiceTest.kt +++ b/src/backend/repository/biz-repository/src/test/kotlin/com/tencent/bkrepo/repository/service/RepositoryServiceTest.kt @@ -100,7 +100,13 @@ class RepositoryServiceTest @Autowired constructor( fun beforeAll() { initMock() if (!projectService.checkExist(UT_PROJECT_ID)) { - val projectCreateRequest = ProjectCreateRequest(UT_PROJECT_ID, UT_REPO_NAME, UT_REPO_DISPLAY, UT_USER) + val projectCreateRequest = ProjectCreateRequest( + name = UT_PROJECT_ID, + displayName = UT_REPO_NAME, + description = UT_REPO_DISPLAY, + createPermission = true, + operator = UT_USER + ) projectService.createProject(projectCreateRequest) } val request = StorageCredentialsCreateRequest(UT_STORAGE_CREDENTIALS_KEY, storageCredentials, UT_REGION) diff --git a/src/backend/repository/biz-repository/src/test/kotlin/com/tencent/bkrepo/repository/service/ServiceBaseTest.kt b/src/backend/repository/biz-repository/src/test/kotlin/com/tencent/bkrepo/repository/service/ServiceBaseTest.kt index c2a3f3f40d..8e5ea3481b 100644 --- a/src/backend/repository/biz-repository/src/test/kotlin/com/tencent/bkrepo/repository/service/ServiceBaseTest.kt +++ b/src/backend/repository/biz-repository/src/test/kotlin/com/tencent/bkrepo/repository/service/ServiceBaseTest.kt @@ -157,7 +157,13 @@ open class ServiceBaseTest { credentialsKey: String? = null ) { if (!projectService.checkExist(UT_PROJECT_ID)) { - val projectCreateRequest = ProjectCreateRequest(UT_PROJECT_ID, UT_REPO_NAME, UT_REPO_DISPLAY, UT_USER) + val projectCreateRequest = ProjectCreateRequest( + name = UT_PROJECT_ID, + displayName = UT_REPO_NAME, + description = UT_REPO_DISPLAY, + createPermission = true, + operator = UT_USER + ) projectService.createProject(projectCreateRequest) } if (!repositoryService.checkExist(UT_PROJECT_ID, UT_REPO_NAME)) { @@ -180,7 +186,7 @@ open class ServiceBaseTest { projectService: ProjectService, projectId: String = UT_PROJECT_ID ): ProjectInfo { - val projectCreateRequest = ProjectCreateRequest(projectId, UT_REPO_NAME, UT_REPO_DISPLAY, UT_USER) + val projectCreateRequest = ProjectCreateRequest(projectId, UT_REPO_NAME, UT_REPO_DISPLAY, true, UT_USER) return projectService.createProject(projectCreateRequest) } From 31a80f55771f5203e0d90377f757f09788404882 Mon Sep 17 00:00:00 2001 From: yaoxuwan Date: Wed, 2 Aug 2023 17:30:39 +0800 Subject: [PATCH 4/4] =?UTF-8?q?feat:=20=E5=88=9B=E5=BB=BA=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=97=B6=EF=BC=8C=E5=A2=9E=E5=8A=A0=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E6=9C=AC=E5=9C=B0=E6=9D=83=E9=99=90=E5=8F=82?= =?UTF-8?q?=E6=95=B0=20#879?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/pojo/project/UserProjectCreateRequest.kt | 4 +++- .../repository/controller/user/UserProjectController.kt | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/backend/repository/api-repository/src/main/kotlin/com/tencent/bkrepo/repository/pojo/project/UserProjectCreateRequest.kt b/src/backend/repository/api-repository/src/main/kotlin/com/tencent/bkrepo/repository/pojo/project/UserProjectCreateRequest.kt index 582183081e..14ce100c09 100644 --- a/src/backend/repository/api-repository/src/main/kotlin/com/tencent/bkrepo/repository/pojo/project/UserProjectCreateRequest.kt +++ b/src/backend/repository/api-repository/src/main/kotlin/com/tencent/bkrepo/repository/pojo/project/UserProjectCreateRequest.kt @@ -41,5 +41,7 @@ data class UserProjectCreateRequest( @ApiModelProperty("显示名") val displayName: String, @ApiModelProperty("描述") - val description: String + val description: String, + @ApiModelProperty("创建本地权限") + val createPermission: Boolean = true ) : ProjectRequest diff --git a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/controller/user/UserProjectController.kt b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/controller/user/UserProjectController.kt index 5852aef3ab..5cf716c130 100644 --- a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/controller/user/UserProjectController.kt +++ b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/controller/user/UserProjectController.kt @@ -73,7 +73,8 @@ class UserProjectController( name = name, displayName = displayName, description = description, - operator = userId + operator = userId, + createPermission = createPermission ) } projectService.createProject(createRequest)