Skip to content

Commit

Permalink
feat:同步并分表存储资源组权限数据 TencentBlueKing#10964
Browse files Browse the repository at this point in the history
  • Loading branch information
fcfang123 committed Sep 23, 2024
1 parent ef12544 commit e6196f9
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import org.jooq.DSLContext
import org.jooq.impl.DSL
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Value
import kotlin.math.log

@Suppress("LongParameterList")
class RbacPermissionResourceGroupPermissionService(
Expand Down Expand Up @@ -139,8 +140,8 @@ class RbacPermissionResourceGroupPermissionService(
projectCode = projectCode,
relationId = groupId.toString(),
) ?: return true

val groupPermissionDetails = getGroupPermissionDetailBySystem(systemId, groupId)
logger.debug("sync group permissions:{}|{}|{}", projectCode, groupId, groupPermissionDetails)
// 获取用户组最新的权限
val latestResourceGroupPermissions = groupPermissionDetails.flatMap { permissionDetail ->
permissionDetail.relatedResourceInfos.flatMap { relatedResourceInfo ->
Expand All @@ -167,20 +168,22 @@ class RbacPermissionResourceGroupPermissionService(
}
}
}
logger.debug("sync group | latest group permissions :{}", latestResourceGroupPermissions)
// 获取用户组老权限数据
val oldResourceGroupPermissions = resourceGroupPermissionDao.listByGroupId(
dslContext = dslContext,
projectCode = projectCode,
iamGroupId = groupId
)

logger.debug("sync group | old group permissions :{}", oldResourceGroupPermissions)
val toDeleteRecords = oldResourceGroupPermissions.filter {
!latestResourceGroupPermissions.contains(it)
}
logger.debug("sync group | to delete group permissions :{}", toDeleteRecords)
val toAddRecords = latestResourceGroupPermissions.filter {
!oldResourceGroupPermissions.contains(it)
}

logger.debug("sync group | to add group permissions :{}", toAddRecords)
dslContext.transaction { configuration ->
val transactionContext = DSL.using(configuration)
if (toDeleteRecords.isNotEmpty()) {
Expand All @@ -199,10 +202,12 @@ class RbacPermissionResourceGroupPermissionService(
}

override fun syncProject(projectCode: String): Boolean {
logger.info("sync project group permissions:$projectCode")
val iamGroupIds = authResourceGroupDao.listIamGroupIdsByConditions(
dslContext = dslContext,
projectCode = projectCode
)
logger.debug("sync project group permissions iamGroupIds:{}", iamGroupIds)
iamGroupIds.forEach {
syncGroup(
projectCode = projectCode,
Expand Down

0 comments on commit e6196f9

Please sign in to comment.