From 1abb0204a2daa3962315a4b817aad98b6bffd56c Mon Sep 17 00:00:00 2001 From: Him188 Date: Wed, 9 Sep 2020 21:53:10 +0800 Subject: [PATCH] Update docs --- .../mirai/console/permission/ExperimentalPermission.kt | 4 +++- .../mirai/console/permission/PermissionService.kt | 10 ++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/ExperimentalPermission.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/ExperimentalPermission.kt index 479bf5d9d..4e0252a7e 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/ExperimentalPermission.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/ExperimentalPermission.kt @@ -12,7 +12,9 @@ package net.mamoe.mirai.console.permission import kotlin.annotation.AnnotationTarget.* /** - * 标记一个实验性的权限系统 API + * 标记一个实验性的权限系统 API. + * + * 权限系统是在 1.0-M4 引入的一个实验性系统, 目前不具有 API 稳定性. */ @Retention(AnnotationRetention.BINARY) @RequiresOptIn(level = RequiresOptIn.Level.WARNING) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionService.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionService.kt index 3b5bef9f9..f7b4e478b 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionService.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionService.kt @@ -30,7 +30,8 @@ public interface PermissionService

{ public fun getGrantedPermissions(permissibleIdentifier: PermissibleIdentifier): Sequence

- public fun testPermission(permissibleIdentifier: PermissibleIdentifier, permissionId: PermissionId): Boolean { + public fun testPermission(permissibleIdentifier: PermissibleIdentifier, permission: P): Boolean { + val permissionId = permission.id val all = this[permissionId]?.parentsWithSelfSequence() ?: return false return getGrantedPermissions(permissibleIdentifier).any { p -> all.any { p.id == it.id } @@ -61,6 +62,11 @@ public interface PermissionService

{ } } +@ExperimentalPermission +public fun

PermissionService

.getOrFail(id: PermissionId): P { + +} + @ExperimentalPermission internal fun PermissionService<*>.allocatePermissionIdForPlugin(name: String, id: String) = PermissionId("plugin.${name.toLowerCase()}", id.toLowerCase()) @@ -85,7 +91,7 @@ public fun PermissibleIdentifier.hasPermission(permission: Permission): Boolean @ExperimentalPermission public fun PermissibleIdentifier.hasPermission(permissionId: PermissionId): Boolean = (PermissionService.INSTANCE as PermissionService).run { - testPermission(this@hasPermission, permissionId) + testPermission(this@hasPermission, get(permissionId) ?: PermissionNotFoundException("")) } @ExperimentalPermission