Skip to content

Commit

Permalink
Merge pull request TencentBlueKing#8149 from stubenhuang/issue-view-g…
Browse files Browse the repository at this point in the history
…roup-7101

feat: 流水线组及流水线列表页优化 TencentBlueKing#7101
  • Loading branch information
bkci-bot authored Dec 19, 2022
2 parents d8d28e0 + d99fcc3 commit c294f89
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ package com.tencent.devops.auth.api.service

import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_BK_TOKEN
import com.tencent.devops.common.api.auth.AUTH_HEADER_GIT_TYPE
import com.tencent.devops.common.api.auth.AUTH_HEADER_USER_ID
import com.tencent.devops.common.api.pojo.Result
import com.tencent.devops.common.auth.api.pojo.BKAuthProjectRolesResources
import com.tencent.devops.common.auth.api.pojo.BkAuthGroup
Expand Down Expand Up @@ -133,6 +134,21 @@ interface ServiceProjectAuthResource {
projectCode: String
): Result<Boolean>

@GET
@Path("/projectIds/{projectId}/checkManager")
@ApiOperation("判断是否是项目管理员或CI管理员")
fun checkManager(
@HeaderParam(AUTH_HEADER_DEVOPS_BK_TOKEN)
@ApiParam("认证token", required = true)
token: String,
@ApiParam(name = "用户名", required = true)
@HeaderParam(AUTH_HEADER_USER_ID)
userId: String,
@PathParam("projectId")
@ApiParam("项目Id", required = true)
projectId: String
): Result<Boolean>

@POST
@Path("/{projectCode}/createUser")
@ApiOperation("添加用户到指定项目指定分组")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,16 @@ interface UserProjectMemberResource {
@ApiParam(name = "待搜用户", required = true)
searchUserId: String
): Result<List<ManagerRoleGroupInfo>?>

@GET
@Path("/projectIds/{projectId}/checkManager")
@ApiOperation("判断是否是项目管理员或CI管理员")
fun checkManager(
@ApiParam(name = "用户名", required = true)
@HeaderParam(AUTH_HEADER_USER_ID)
userId: String,
@PathParam("projectId")
@ApiParam("项目Id", required = true)
projectId: String
): Result<Boolean>
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@ import com.tencent.bk.sdk.iam.dto.manager.vo.ManagerGroupMemberVo
import com.tencent.devops.auth.api.user.UserProjectMemberResource
import com.tencent.devops.auth.pojo.dto.RoleMemberDTO
import com.tencent.devops.auth.pojo.vo.ProjectMembersVO
import com.tencent.devops.auth.service.iam.PermissionProjectService
import com.tencent.devops.auth.service.iam.PermissionRoleMemberService
import com.tencent.devops.common.api.pojo.Result
import com.tencent.devops.common.auth.api.pojo.BkAuthGroup
import com.tencent.devops.common.web.RestResource
import org.springframework.beans.factory.annotation.Autowired

@RestResource
class UserProjectMemberResourceImpl @Autowired constructor(
val permissionRoleMemberService: PermissionRoleMemberService
val permissionRoleMemberService: PermissionRoleMemberService,
val permissionProjectService: PermissionProjectService
) : UserProjectMemberResource {
override fun createRoleMember(
userId: String,
Expand Down Expand Up @@ -73,7 +76,8 @@ class UserProjectMemberResourceImpl @Autowired constructor(
roleId = roleId,
page = page,
pageSize = pageSize
))
)
)
}

override fun getProjectAllMember(projectId: Int, page: Int?, pageSize: Int?): Result<ProjectMembersVO?> {
Expand All @@ -88,14 +92,16 @@ class UserProjectMemberResourceImpl @Autowired constructor(
members: String,
type: ManagerScopesEnum
): Result<Boolean> {
Result(permissionRoleMemberService.deleteRoleMember(
userId = userId,
projectId = projectId,
roleId = roleId,
id = members,
type = type,
managerGroup = managerGroup
))
Result(
permissionRoleMemberService.deleteRoleMember(
userId = userId,
projectId = projectId,
roleId = roleId,
id = members,
type = type,
managerGroup = managerGroup
)
)
return Result(true)
}

Expand All @@ -106,4 +112,10 @@ class UserProjectMemberResourceImpl @Autowired constructor(
): Result<List<ManagerRoleGroupInfo>?> {
return Result(permissionRoleMemberService.getUserGroups(projectId, searchUserId))
}

override fun checkManager(userId: String, projectId: String): Result<Boolean> {
val result = permissionProjectService.checkProjectManager(userId, projectId) ||
permissionProjectService.isProjectUser(userId, projectId, BkAuthGroup.CI_MANAGER)
return Result(result)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ class ServiceProjectAuthResourceImpl @Autowired constructor(
)
}

override fun checkManager(token: String, userId: String, projectId: String): Result<Boolean> {
val result = permissionProjectService.checkProjectManager(userId, projectId) ||
permissionProjectService.isProjectUser(userId, projectId, BkAuthGroup.CI_MANAGER)
return Result(result)
}

override fun checkProjectManager(
token: String,
type: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ package com.tencent.devops.common.auth.api.pojo
* 项目角色组
*/
enum class BkAuthGroup(val value: String) {
CIADMIN("ciAdmin"), // CI管理员
CIADMIN("ciAdmin"), // CI管理员 TODO : 看IAM接口找不到这个标志, 用的是ci_manager
MANAGER("manager"), // 管理员
DEVELOPER("developer"), // 开发人员
MAINTAINER("maintainer"), // 运维人员
TESTER("tester"), // 测试人员
PM("pm"), // 产品人员
QC("qc"); // 质量管理员
QC("qc"), // 质量管理员
CI_MANAGER("ci_manager"); // CI 管理员

companion object {
fun get(value: String): BkAuthGroup {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ package com.tencent.devops.process.service.view
import com.fasterxml.jackson.core.type.TypeReference
import com.fasterxml.jackson.databind.ObjectMapper
import com.github.benmanes.caffeine.cache.Caffeine
import com.tencent.devops.auth.api.service.ServiceProjectAuthResource
import com.tencent.devops.common.api.exception.ErrorCodeException
import com.tencent.devops.common.api.util.HashUtil
import com.tencent.devops.common.api.util.Watcher
import com.tencent.devops.common.api.util.timestamp
import com.tencent.devops.common.auth.api.AuthPermission
import com.tencent.devops.common.client.Client
import com.tencent.devops.common.client.ClientTokenService
import com.tencent.devops.common.pipeline.enums.ChannelCode
import com.tencent.devops.common.redis.RedisOperation
import com.tencent.devops.common.service.utils.LogUtils
Expand All @@ -59,7 +60,6 @@ import com.tencent.devops.process.pojo.classify.PipelineViewPreview
import com.tencent.devops.process.pojo.classify.enums.Logic
import com.tencent.devops.process.service.view.lock.PipelineViewGroupLock
import com.tencent.devops.process.utils.PIPELINE_VIEW_UNCLASSIFIED
import com.tencent.devops.project.api.service.ServiceProjectResource
import org.apache.commons.lang3.StringUtils
import org.jooq.DSLContext
import org.jooq.impl.DSL
Expand All @@ -80,7 +80,8 @@ class PipelineViewGroupService @Autowired constructor(
private val dslContext: DSLContext,
private val redisOperation: RedisOperation,
private val objectMapper: ObjectMapper,
private val client: Client
private val client: Client,
private val clientTokenService: ClientTokenService
) {
private val allPipelineInfoCache = Caffeine.newBuilder()
.maximumSize(10)
Expand Down Expand Up @@ -638,7 +639,8 @@ class PipelineViewGroupService @Autowired constructor(
}

fun hasPermission(userId: String, projectId: String) =
client.get(ServiceProjectResource::class).hasPermission(userId, projectId, AuthPermission.MANAGE).data ?: false
client.get(ServiceProjectAuthResource::class)
.checkManager(clientTokenService.getSystemToken(null)!!, userId, projectId).data ?: false

fun listView(userId: String, projectId: String, projected: Boolean?, viewType: Int?): List<PipelineNewViewSummary> {
val views = pipelineViewDao.list(dslContext, userId, projectId, projected, viewType)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.tencent.devops.process.service.view

import com.tencent.devops.auth.api.service.ServiceProjectAuthResource
import com.tencent.devops.common.api.exception.ErrorCodeException
import com.tencent.devops.common.api.pojo.Result
import com.tencent.devops.common.api.util.HashUtil
import com.tencent.devops.common.client.ClientTokenService
import com.tencent.devops.common.test.BkCiAbstractTest
import com.tencent.devops.model.process.Tables.T_PIPELINE_INFO
import com.tencent.devops.model.process.Tables.T_PIPELINE_VIEW
Expand All @@ -25,8 +28,6 @@ import com.tencent.devops.process.pojo.classify.PipelineViewForm
import com.tencent.devops.process.pojo.classify.PipelineViewPipelineCount
import com.tencent.devops.process.pojo.classify.PipelineViewPreview
import com.tencent.devops.process.utils.PIPELINE_VIEW_UNCLASSIFIED
import com.tencent.devops.project.api.service.ServiceProjectResource
import com.tencent.devops.project.pojo.Result
import io.mockk.every
import io.mockk.justRun
import io.mockk.mockk
Expand All @@ -46,6 +47,7 @@ class PipelineViewGroupServiceTest : BkCiAbstractTest() {
private val pipelineViewGroupDao: PipelineViewGroupDao = mockk()
private val pipelineViewTopDao: PipelineViewTopDao = mockk()
private val pipelineInfoDao: PipelineInfoDao = mockk()
private val clientTokenService: ClientTokenService = mockk()

private val self: PipelineViewGroupService = spyk(
PipelineViewGroupService(
Expand All @@ -57,7 +59,8 @@ class PipelineViewGroupServiceTest : BkCiAbstractTest() {
dslContext = dslContext,
redisOperation = redisOperation,
objectMapper = objectMapper,
client = client
client = client,
clientTokenService = clientTokenService
),
recordPrivateCalls = true
)
Expand Down Expand Up @@ -828,11 +831,16 @@ class PipelineViewGroupServiceTest : BkCiAbstractTest() {

@Nested
inner class HasPermission {
@BeforeEach
fun beforeEach() {
every { clientTokenService.getSystemToken(any()) } returns ""
}

@Test
@DisplayName("返回值测试1")
fun test_1() {
every {
client.mockGet(ServiceProjectResource::class).hasPermission(any(), any(), any())
client.mockGet(ServiceProjectAuthResource::class).checkManager(any(), any(), any())
} returns Result(true)
self.hasPermission("test", "test").let {
Assertions.assertEquals(true, it)
Expand All @@ -843,7 +851,7 @@ class PipelineViewGroupServiceTest : BkCiAbstractTest() {
@DisplayName("返回值测试2")
fun test_2() {
every {
client.mockGet(ServiceProjectResource::class).hasPermission(any(), any(), any())
client.mockGet(ServiceProjectAuthResource::class).checkManager(any(), any(), any())
} returns Result(false)
self.hasPermission("test", "test").let {
Assertions.assertEquals(false, it)
Expand Down

0 comments on commit c294f89

Please sign in to comment.