Skip to content

Commit

Permalink
feat:项目查看页面运营产品未显示名称问题优化 TencentBlueKing#10668
Browse files Browse the repository at this point in the history
  • Loading branch information
fcfang123 committed Aug 9, 2024
1 parent 4da27e0 commit 8298c7f
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,6 @@ object AuthMessageCode {

const val ERROR_MOA_CREDENTIAL_KEY_VERIFY_FAIL = "2121082" // MOA票据校验失败
const val ERROR_USER_NOT_BELONG_TO_THE_PROJECT = "2121083" // 用户不属于项目

const val ERROR_USER_INFORMATION_NOT_SYNCED = "2121090" // 请等待第二天用户信息同步后再尝试操作,因为新入职用户的信息尚未同步完成。
}
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ class RbacAuthConfiguration {
client: Client,
authResourceCodeConverter: AuthResourceCodeConverter,
permissionService: PermissionService,
itsmService: ItsmService
itsmService: ItsmService,
deptService: DeptService
) = RbacPermissionApplyService(
dslContext = dslContext,
v2ManagerService = v2ManagerService,
Expand All @@ -303,7 +304,8 @@ class RbacAuthConfiguration {
client = client,
authResourceCodeConverter = authResourceCodeConverter,
permissionService = permissionService,
itsmService = itsmService
itsmService = itsmService,
deptService = deptService
)

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.tencent.devops.auth.pojo.vo.AuthApplyRedirectInfoVo
import com.tencent.devops.auth.pojo.vo.AuthRedirectGroupInfoVo
import com.tencent.devops.auth.pojo.vo.ManagerRoleGroupVO
import com.tencent.devops.auth.pojo.vo.ResourceTypeInfoVo
import com.tencent.devops.auth.service.DeptService
import com.tencent.devops.auth.service.GroupUserService
import com.tencent.devops.auth.service.iam.PermissionApplyService
import com.tencent.devops.auth.service.iam.PermissionService
Expand Down Expand Up @@ -62,7 +63,8 @@ class RbacPermissionApplyService @Autowired constructor(
val client: Client,
val authResourceCodeConverter: AuthResourceCodeConverter,
val permissionService: PermissionService,
val itsmService: ItsmService
val itsmService: ItsmService,
val deptService: DeptService
) : PermissionApplyService {
@Value("\${auth.iamSystem:}")
private val systemId = ""
Expand All @@ -89,7 +91,8 @@ class RbacPermissionApplyService @Autowired constructor(
): ManagerRoleGroupVO {
logger.info("RbacPermissionApplyService|listGroups:searchGroupInfo=$searchGroupInfo")
verifyProjectRouterTag(projectId)

// 校验新用户信息是否同步完成
isUserExists(userId)
val projectInfo = authResourceService.get(
projectCode = projectId,
resourceType = AuthResourceType.PROJECT.value,
Expand Down Expand Up @@ -147,6 +150,17 @@ class RbacPermissionApplyService @Autowired constructor(
)
}

private fun isUserExists(userId: String) {
// 校验新用户信息是否同步完成
val userExists = deptService.getUserInfo(userId = "admin", name = userId) != null
if (!userExists) {
logger.warn("user($userId) does not exist")
throw ErrorCodeException(
errorCode = AuthMessageCode.ERROR_USER_INFORMATION_NOT_SYNCED,
)
}
}

private fun buildBkIamPath(
userId: String,
resourceType: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ data class ProjectVO(
val channelCode: String? = null,
@get:Schema(title = "运营产品ID")
val productId: Int? = null,
@get:Schema(title = "运营产品名称")
val productName: String? = null,
@get:Schema(title = "是否可以查看")
val canView: Boolean? = null,
@get:Schema(title = "安装模板权限")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,13 @@ class SimpleProjectServiceImpl @Autowired constructor(
)
}

override fun getProductByProductId(productId: Int): OperationalProductVO? {
return OperationalProductVO(
productId = -1,
productName = "其他"
)
}

override fun getOperationalProductsByBgName(bgName: String): List<OperationalProductVO> {
return listOf(
OperationalProductVO(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ class UserProjectResourceImpl @Autowired constructor(
userId = userId,
englishName = projectId,
accessToken = accessToken
)
?: throw OperationException("project $projectId not found")
) ?: throw OperationException("project $projectId not found")
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ interface ProjectService {

fun getOperationalProducts(): List<OperationalProductVO>

fun getProductByProductId(productId: Int): OperationalProductVO?

fun getOperationalProductsByBgName(bgName: String): List<OperationalProductVO>

fun updateProjectProductId(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,10 @@ abstract class AbsProjectServiceImpl @Autowired constructor(
}
}
val tipsStatus = getAndUpdateTipsStatus(userId = userId, projectId = englishName)
return projectInfo.copy(tipsStatus = tipsStatus)
return projectInfo.copy(
tipsStatus = tipsStatus,
productName = projectInfo.productId?.let { getProductByProductId(it)?.productName }
)
}

protected fun getAndUpdateTipsStatus(userId: String, projectId: String): Int {
Expand Down Expand Up @@ -559,8 +562,8 @@ abstract class AbsProjectServiceImpl @Autowired constructor(
originalProjectName = projectInfo.projectName,
modifiedProjectName = projectUpdateInfo.projectName,
finalNeedApproval = finalNeedApproval,
beforeSubjectScopesStr = projectInfo.subjectScopes,
afterSubjectScopesStr = subjectScopesStr
beforeSubjectScopes = JsonUtil.to(projectInfo.subjectScopes, object : TypeReference<List<SubjectScopeInfo>>() {}),
afterSubjectScopes = subjectScopes,
)) {
modifyProjectAuthResource(resourceUpdateInfo)
}
Expand Down Expand Up @@ -693,11 +696,15 @@ abstract class AbsProjectServiceImpl @Autowired constructor(
originalProjectName: String,
modifiedProjectName: String,
finalNeedApproval: Boolean,
beforeSubjectScopesStr: String,
afterSubjectScopesStr: String
beforeSubjectScopes: List<SubjectScopeInfo>,
afterSubjectScopes: List<SubjectScopeInfo>
): Boolean {
val isSubjectScopesChange = isSubjectScopesChange(
beforeSubjectScopes = beforeSubjectScopes,
afterSubjectScopes = afterSubjectScopes
)
return originalProjectName != modifiedProjectName || finalNeedApproval ||
beforeSubjectScopesStr != afterSubjectScopesStr
isSubjectScopesChange
}

private fun getUpdateApprovalStatus(
Expand Down
1 change: 1 addition & 0 deletions support-files/i18n/auth/message_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
2121074=The access token invalid
2121075=The access token has expired
2121076=The scope invalid
2121090=Please wait until the next day for user information to be synchronized before trying again, as the information of new users has not yet been synchronized.
bkAdministratorNotExpired=Permission has not expired and no action is required
bkAgreeRenew=Agree to renew
bkApproverAgreeRenew=Approver agreed to your permission renewal
Expand Down
1 change: 1 addition & 0 deletions support-files/i18n/auth/message_zh_CN.properties
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
2121077=监控空间不存在
2121078=业务只读组不存在
2121079=业务运维组不存在
2121090=请等待第二天用户信息同步后再尝试操作,因为新入职用户的信息尚未同步完成。
bkAdministratorNotExpired=权限还未过期,不需要操作
bkAgreeRenew=同意续期
bkApproverAgreeRenew=审批人同意了您的权限续期
Expand Down

0 comments on commit 8298c7f

Please sign in to comment.