Skip to content

Commit

Permalink
feat:支持管理员查看项目成员 #9620
Browse files Browse the repository at this point in the history
  • Loading branch information
fcfang123 committed Aug 15, 2024
1 parent e7bbaf0 commit 820f931
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,38 @@ import java.time.LocalDateTime

@Repository
class AuthAuthorizationDao {
fun batchAddOrUpdate(
fun batchAdd(
dslContext: DSLContext,
resourceAuthorizationList: List<ResourceAuthorizationDTO>
) {
with(TAuthResourceAuthorization.T_AUTH_RESOURCE_AUTHORIZATION) {
dslContext.batch(
resourceAuthorizationList.map { resourceAuthorizationDto ->
val handoverDateTime = Timestamp(resourceAuthorizationDto.handoverTime!!).toLocalDateTime()
dslContext.insertInto(
this,
PROJECT_CODE,
RESOURCE_TYPE,
RESOURCE_CODE,
RESOURCE_NAME,
HANDOVER_FROM,
HANDOVER_FROM_CN_NAME,
HANDOVER_TIME
).values(
resourceAuthorizationDto.projectCode,
resourceAuthorizationDto.resourceType,
resourceAuthorizationDto.resourceCode,
resourceAuthorizationDto.resourceName,
resourceAuthorizationDto.handoverFrom,
resourceAuthorizationDto.handoverFromCnName,
handoverDateTime
)
}
).execute()
}
}

fun migrate(
dslContext: DSLContext,
resourceAuthorizationList: List<ResourceAuthorizationDTO>
) {
Expand Down Expand Up @@ -45,7 +76,7 @@ class AuthAuthorizationDao {
.set(HANDOVER_FROM_CN_NAME, resourceAuthorizationDto.handoverFromCnName)
.set(RESOURCE_NAME, resourceAuthorizationDto.resourceName)
.set(HANDOVER_TIME, handoverDateTime)
.set(UPDATE_TIME, LocalDateTime.now())
.where(CREATE_TIME.eq(UPDATE_TIME))
}
).execute()
}
Expand Down Expand Up @@ -93,6 +124,21 @@ class AuthAuthorizationDao {
}
}

fun delete(
dslContext: DSLContext,
projectCode: String,
resourceType: String,
resourceCodes: List<String>
) {
with(TAuthResourceAuthorization.T_AUTH_RESOURCE_AUTHORIZATION) {
dslContext.deleteFrom(this)
.where(PROJECT_CODE.eq(projectCode))
.and(RESOURCE_TYPE.eq(resourceType))
.and(RESOURCE_CODE.notIn(resourceCodes))
.execute()
}
}

fun get(
dslContext: DSLContext,
projectCode: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class MigrateResourceAuthorizationService @Autowired constructor(
) {
var offset = 0L
val limit = 100L
val resourceAuthorizationIds = mutableListOf<String>()
do {
val resourceAuthorizationData = listResourceAuthorization(
offset = offset,
Expand All @@ -168,7 +169,7 @@ class MigrateResourceAuthorizationService @Autowired constructor(
if (resourceAuthorizationData == null || resourceAuthorizationData.result.isNullOrEmpty()) {
return
}
permissionAuthorizationService.addResourceAuthorization(
permissionAuthorizationService.migrateResourceAuthorization(
resourceAuthorizationList = resourceAuthorizationData.result.map {
ResourceAuthorizationDTO(
projectCode = projectCode,
Expand All @@ -180,8 +181,15 @@ class MigrateResourceAuthorizationService @Autowired constructor(
)
}
)
resourceAuthorizationIds.addAll(resourceAuthorizationData.result.map { it.resourceCode })
offset += limit
} while (resourceAuthorizationData!!.result.size.toLong() == limit)
// 由于生产和灰度不是同时发布,可能会出现生产删除资源,但是授权记录未删除,而导致出现的脏数据,需要进行删除。
permissionAuthorizationService.fixResourceAuthorization(
projectCode = projectCode,
resourceType = resourceType,
resourceAuthorizationIds = resourceAuthorizationIds
)
}

private fun listResourceAuthorization(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ interface PermissionAuthorizationService {
resourceAuthorizationList: List<ResourceAuthorizationDTO>
): Boolean

/**
* 迁移资源授权管理
*/
fun migrateResourceAuthorization(
resourceAuthorizationList: List<ResourceAuthorizationDTO>
): Boolean

/**
* 获取资源授权记录
*/
Expand Down Expand Up @@ -89,6 +96,15 @@ interface PermissionAuthorizationService {
resourceCode: String
): Boolean

/**
* 修复迁移产生的脏数据
*/
fun fixResourceAuthorization(
projectCode: String,
resourceType: String,
resourceAuthorizationIds: List<String>
): Boolean

/**
* 批量重置授权人
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,24 @@ class PermissionAuthorizationServiceImpl constructor(
override fun addResourceAuthorization(resourceAuthorizationList: List<ResourceAuthorizationDTO>): Boolean {
logger.info("add resource authorization:$resourceAuthorizationList")
addHandoverFromCnName(resourceAuthorizationList)
authAuthorizationDao.batchAddOrUpdate(
authAuthorizationDao.batchAdd(
dslContext = dslContext,
resourceAuthorizationList = resourceAuthorizationList
)
return true
}

override fun migrateResourceAuthorization(resourceAuthorizationList: List<ResourceAuthorizationDTO>): Boolean {
logger.info("migrate resource authorization:$resourceAuthorizationList")
addHandoverFromCnName(resourceAuthorizationList)
authAuthorizationDao.migrate(
dslContext = dslContext,
resourceAuthorizationList = resourceAuthorizationList
)
return true
}


override fun getResourceAuthorization(
projectCode: String,
resourceType: String,
Expand Down Expand Up @@ -153,6 +164,21 @@ class PermissionAuthorizationServiceImpl constructor(
return true
}

override fun fixResourceAuthorization(
projectCode: String,
resourceType: String,
resourceAuthorizationIds: List<String>
): Boolean {
logger.info("fix resource authorizations:$projectCode|$resourceType|$resourceAuthorizationIds")
authAuthorizationDao.delete(
dslContext = dslContext,
projectCode = projectCode,
resourceType = resourceType,
resourceCodes = resourceAuthorizationIds
)
return true
}

override fun batchModifyHandoverFrom(
resourceAuthorizationHandoverList: List<ResourceAuthorizationHandoverDTO>
): Boolean {
Expand Down

0 comments on commit 820f931

Please sign in to comment.