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

pref:完善获取服务跳转地址权限校验 #11567 #11568

Merged
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 @@ -27,6 +27,8 @@

package com.tencent.devops.project.service

import com.tencent.devops.common.auth.api.AuthProjectApi
import com.tencent.devops.common.auth.code.PipelineAuthServiceCode
import com.tencent.devops.common.redis.RedisOperation
import com.tencent.devops.common.service.gray.Gray
import com.tencent.devops.project.dao.FavoriteDao
Expand All @@ -43,5 +45,16 @@ class SampleUserProjectServiceServiceImpl(
serviceDao: ServiceDao,
favoriteDao: FavoriteDao,
gray: Gray,
redisOperation: RedisOperation
) : AbsUserProjectServiceServiceImpl(dslContext, serviceTypeDao, serviceDao, favoriteDao, gray, redisOperation)
redisOperation: RedisOperation,
authProjectApi: AuthProjectApi,
pipelineAuthServiceCode: PipelineAuthServiceCode
) : AbsUserProjectServiceServiceImpl(
dslContext,
serviceTypeDao,
serviceDao,
favoriteDao,
gray,
redisOperation,
authProjectApi,
pipelineAuthServiceCode
)
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ package com.tencent.devops.project.service.impl
import com.tencent.devops.common.api.exception.ErrorCodeException
import com.tencent.devops.common.api.util.DateTimeUtil
import com.tencent.devops.common.api.util.MessageUtil
import com.tencent.devops.common.auth.api.AuthProjectApi
import com.tencent.devops.common.auth.code.PipelineAuthServiceCode
import com.tencent.devops.common.redis.RedisOperation
import com.tencent.devops.common.service.gray.Gray
import com.tencent.devops.common.service.utils.SpringContextUtil
Expand Down Expand Up @@ -62,7 +64,9 @@ abstract class AbsUserProjectServiceServiceImpl @Autowired constructor(
private val serviceDao: ServiceDao,
private val favoriteDao: FavoriteDao,
private val gray: Gray,
private val redisOperation: RedisOperation
private val redisOperation: RedisOperation,
private val authProjectApi: AuthProjectApi,
private val pipelineAuthServiceCode: PipelineAuthServiceCode
) : UserProjectServiceService {

override fun getService(userId: String, serviceId: Long): Result<ServiceVO> {
Expand Down Expand Up @@ -307,6 +311,21 @@ abstract class AbsUserProjectServiceServiceImpl @Autowired constructor(
}

override fun getServiceUrl(userId: String, projectId: String?, serviceId: Long): Result<String> {
if (!projectId.isNullOrBlank()) {
// 检查用户是否有该项目的权限
val hasPermission = authProjectApi.isProjectUser(
user = userId,
serviceCode = pipelineAuthServiceCode,
projectCode = projectId,
group = null
)
if (!hasPermission) {
throw ErrorCodeException(
errorCode = ProjectMessageCode.USER_NOT_PROJECT_USER,
params = arrayOf(userId, projectId)
)
}
}
val serviceResult = getService(userId, serviceId)
var serviceVO = serviceResult.data ?: throw ErrorCodeException(
errorCode = serviceResult.code.toString(), defaultMessage = serviceResult.message
Expand Down