fix: wildcardの挙動を修正
This commit is contained in:
@@ -13,7 +13,7 @@ data class PermissionNode(
|
||||
val description: String? = null,
|
||||
val defaultValue: PermissionDefault = PermissionDefault.FALSE,
|
||||
val children: Map<PermissionId, Boolean> = emptyMap(),
|
||||
val wildcard: Boolean = true,
|
||||
val wildcard: Boolean = false,
|
||||
val registration: NodeRegistration = NodeRegistration.PERMISSION
|
||||
) {
|
||||
init {
|
||||
|
||||
@@ -7,7 +7,7 @@ internal data class PermissionNodeDraft(
|
||||
var description: String? = null,
|
||||
var defaultValue: PermissionDefault = PermissionDefault.FALSE,
|
||||
val children: MutableMap<PermissionId, Boolean> = linkedMapOf(),
|
||||
var wildcard: Boolean = true,
|
||||
var wildcard: Boolean = false,
|
||||
var registration: NodeRegistration = NodeRegistration.PERMISSION
|
||||
) {
|
||||
fun toNode(): PermissionNode =
|
||||
|
||||
@@ -9,43 +9,25 @@ internal object WildcardAugmentor {
|
||||
|
||||
nodes.values.forEach { node ->
|
||||
if (!node.wildcard) return@forEach
|
||||
if (node.id.value.endsWith(".*")) return@forEach
|
||||
|
||||
val wildcardId = PermissionId.of("${node.id.value}.*")
|
||||
val updatedChildren = node.children.toMutableMap()
|
||||
|
||||
val wildcardId = parentWildcardId(node.id) ?: return@forEach
|
||||
val existing = result[wildcardId]
|
||||
val updatedChildren = (existing?.children ?: emptyMap()).toMutableMap()
|
||||
val alreadyPresent = updatedChildren[node.id] == true
|
||||
if (!alreadyPresent) {
|
||||
updatedChildren[node.id] = true
|
||||
}
|
||||
|
||||
if (existing == null) {
|
||||
result[wildcardId] = PermissionNode(
|
||||
id = wildcardId,
|
||||
description = "Wildcard for ${wildcardId.value}",
|
||||
description = "Wildcard for ${node.id.value}",
|
||||
defaultValue = node.defaultValue,
|
||||
children = updatedChildren,
|
||||
wildcard = false
|
||||
)
|
||||
} else if (!alreadyPresent) {
|
||||
} else {
|
||||
result[wildcardId] = existing.copy(children = updatedChildren)
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure wildcard permissions include descendant wildcard nodes so granting parent.* cascades.
|
||||
val wildcardEntries = result
|
||||
.filterKeys { it.value.endsWith(".*") }
|
||||
.entries
|
||||
.sortedBy { it.key.value.length } // parents before grandparents not necessary but deterministic
|
||||
|
||||
wildcardEntries.forEach { (childWildcardId, _) ->
|
||||
val parentWildcardId = parentWildcardId(childWildcardId) ?: return@forEach
|
||||
val parent = result[parentWildcardId] ?: return@forEach
|
||||
val updatedChildren = parent.children.toMutableMap()
|
||||
if (updatedChildren[childWildcardId] == true) return@forEach
|
||||
updatedChildren[childWildcardId] = true
|
||||
result[parentWildcardId] = parent.copy(children = updatedChildren)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user