From 0aad162cad955ad6a153ace50afec54bdfb01937 Mon Sep 17 00:00:00 2001 From: cssxsh Date: Sat, 12 Aug 2023 14:00:53 +0800 Subject: [PATCH] [console] Deprecate PermitteeId.hasChild and replace with PermitteeId.isChildOf (#2762) * fix: hasChild * fix: docs * feat: contains * add: api dump * fix: isChildOf --- .../compatibility-validation/jvm/api/jvm.api | 2 ++ .../AbstractConcurrentPermissionService.kt | 6 +++--- .../mirai-console/src/permission/PermitteeId.kt | 12 +++++++++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/mirai-console/backend/mirai-console/compatibility-validation/jvm/api/jvm.api b/mirai-console/backend/mirai-console/compatibility-validation/jvm/api/jvm.api index 8561def1fd..9ff25a02d4 100644 --- a/mirai-console/backend/mirai-console/compatibility-validation/jvm/api/jvm.api +++ b/mirai-console/backend/mirai-console/compatibility-validation/jvm/api/jvm.api @@ -1784,6 +1784,7 @@ public abstract interface class net/mamoe/mirai/console/permission/PermitteeId { public static fun getAllParentsWithSelf (Lnet/mamoe/mirai/console/permission/PermitteeId;)Lkotlin/sequences/Sequence; public abstract fun getDirectParents ()[Lnet/mamoe/mirai/console/permission/PermitteeId; public static fun hasChild (Lnet/mamoe/mirai/console/permission/PermitteeId;Lnet/mamoe/mirai/console/permission/PermitteeId;)Z + public static fun isChildOf (Lnet/mamoe/mirai/console/permission/PermitteeId;Lnet/mamoe/mirai/console/permission/PermitteeId;)Z } public final class net/mamoe/mirai/console/permission/PermitteeId$Companion { @@ -1796,6 +1797,7 @@ public final class net/mamoe/mirai/console/permission/PermitteeId$Companion { public final synthetic fun getPermitteeId (Lnet/mamoe/mirai/contact/User;)Lnet/mamoe/mirai/console/permission/AbstractPermitteeId$ExactUser; public final synthetic fun getPermitteeIdOnTemp (Lnet/mamoe/mirai/contact/Member;)Lnet/mamoe/mirai/console/permission/AbstractPermitteeId$ExactGroupTemp; public final fun hasChild (Lnet/mamoe/mirai/console/permission/PermitteeId;Lnet/mamoe/mirai/console/permission/PermitteeId;)Z + public final fun isChildOf (Lnet/mamoe/mirai/console/permission/PermitteeId;Lnet/mamoe/mirai/console/permission/PermitteeId;)Z } public abstract interface class net/mamoe/mirai/console/plugin/NotYetLoadedPlugin : net/mamoe/mirai/console/plugin/Plugin { diff --git a/mirai-console/backend/mirai-console/src/internal/permission/AbstractConcurrentPermissionService.kt b/mirai-console/backend/mirai-console/src/internal/permission/AbstractConcurrentPermissionService.kt index 53c5bee190..ac9fc410f7 100644 --- a/mirai-console/backend/mirai-console/src/internal/permission/AbstractConcurrentPermissionService.kt +++ b/mirai-console/backend/mirai-console/src/internal/permission/AbstractConcurrentPermissionService.kt @@ -13,7 +13,7 @@ import net.mamoe.mirai.console.data.PluginDataExtensions import net.mamoe.mirai.console.permission.* import net.mamoe.mirai.console.permission.Permission.Companion.parentsWithSelf import net.mamoe.mirai.console.permission.PermitteeId.Companion.allParentsWithSelf -import net.mamoe.mirai.console.permission.PermitteeId.Companion.hasChild +import net.mamoe.mirai.console.permission.PermitteeId.Companion.isChildOf internal abstract class AbstractConcurrentPermissionService

: PermissionService

{ protected abstract val permissions: MutableMap @@ -75,7 +75,7 @@ internal abstract class AbstractConcurrentPermissionService

: Pe override fun getPermittedPermissions(permitteeId: PermitteeId): Sequence

= sequence { for ((permissionIdentifier, permissibleIdentifiers) in grantedPermissionsMap) { - val granted = permissibleIdentifiers.any { permitteeId.hasChild(it) } + val granted = permissibleIdentifiers.any { permitteeId.isChildOf(it) } if (granted) get(permissionIdentifier)?.let { yield(it) } } @@ -84,7 +84,7 @@ internal abstract class AbstractConcurrentPermissionService

: Pe internal fun getPermittedPermissionsAndSource(permitteeId: PermitteeId): Sequence> = sequence { for ((permissionIdentifier, permissibleIdentifiers) in grantedPermissionsMap) { permissibleIdentifiers.forEach { pid -> - if (permitteeId.hasChild(pid)) { + if (permitteeId.isChildOf(pid)) { get(permissionIdentifier)?.let { yield(pid to it) } } } diff --git a/mirai-console/backend/mirai-console/src/permission/PermitteeId.kt b/mirai-console/backend/mirai-console/src/permission/PermitteeId.kt index f514fe4ae8..e20d628bcc 100644 --- a/mirai-console/backend/mirai-console/src/permission/PermitteeId.kt +++ b/mirai-console/backend/mirai-console/src/permission/PermitteeId.kt @@ -48,13 +48,19 @@ public interface PermitteeId { public companion object { /** - * 当 [this] 或 [this] 的任意一个直接或间接父 [PermitteeId.asString] 与 `this.asString` 相同时返回 `true` + * 当 [this] 或 [this] 的任意一个直接或间接父 [PermitteeId.asString] 与 `parent.asString` 相同时返回 `true` + * + * @since 2.16 */ @JvmStatic - public fun PermitteeId.hasChild(child: PermitteeId): Boolean { - return allParentsWithSelf.any { it.asString() == child.asString() } // asString is for compatibility issue with external implementations + public fun PermitteeId.isChildOf(parent: PermitteeId): Boolean { + return allParentsWithSelf.any { it.asString() == parent.asString() } // asString is for compatibility issue with external implementations } + @JvmStatic + @DeprecatedSinceMirai(warningSince = "2.16") + public fun PermitteeId.hasChild(child: PermitteeId): Boolean = isChildOf(child) + /** * 获取所有直接或间接父类的 [PermitteeId]. */