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/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/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/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) 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 ) } } 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) } 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) }