Permissions

value class Permissions(val perm: UInt)(source)

权限值

权限是一个 unsigned int 值,由比特位代表是否拥有对应的权限。 权限值与对应比特位进行按位与操作,判断是否拥有该权限。

判断是否有某权限

其中: permissions 代表权限值,bitValue 代表某权限比特位,1 << bitValue 代表某权限值。

permissions & (1 << bitValue)  == (1 << bitValue);

注意: 正常角色由上向下排序,这个先后顺序是角色的优先级(position字段)。 如果你有管理员权限,你只能管理优先级比自己低的用户,不能管理优先级等于或比自己高的用户。这个地方的逻辑举例来说是这样的:对于一个公司的hr来说,他是有招员工的权利也有开除员工的权利(类比于管理权限),但是他不能开掉老板,也不是招自己的boss。因此,在使用授予权限,更新等接口时,要注意一下,可能机器人虽然有管理权限,但是也不是什么角色都可以授予,也不是什么人都可以操作。

更多参考文档

Author

ForteScarlet

Constructors

Link copied to clipboard
constructor(permissionType: PermissionType)
constructor(vararg permissionTypes: PermissionType)
constructor(perm: UInt)

Properties

Link copied to clipboard
val perm: UInt

权限具体的值。

Functions

Link copied to clipboard
operator fun contains(permissionsValue: UInt): Boolean
operator fun contains(permissionType: PermissionType): Boolean
operator fun contains(permissions: Permissions): Boolean
fun contains(permissionsValue: UInt, full: Boolean): Boolean
fun contains(permissionType: PermissionType, full: Boolean): Boolean
fun contains(permissions: Permissions, full: Boolean): Boolean

判断提供的权限类型全部存在于当前值中。

Link copied to clipboard
operator fun plus(other: Permissions): Permissions

合并两个权限。