Files
curriculum-project-hub/spec/Spec/System/PermissionGrant.lean
T

71 lines
3.6 KiB
Lean4
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import Spec.Prelude
import Spec.System.Permission
/-!
# PermissionGrant —— 授权与设置(ADR-0004)
ADR-0004 的"飞书云文档式"权限:**grant**(`resource × principal × role`)与 **settings**
(各 policy 旋钮)分离;role 决定"谁能"(能力,见 `Permission`),settings 决定"此资源
是否开某类操作"(策略)。本模块把 grant/settings 的结构钉死——`Permission` 已落 role 能
力格,本模块补"授权如何挂到资源/主体上"。
principal 子类型学(user/chat/department/…)与各 policy 值域均为 `OPEN`(ADR 未定,非本
层分歧点)。**role-capability 与 settings-policy 如何组合成最终授权决策**亦 `OPEN`——
ADR-0004 把二者列为分离的闸,但未明文规定组合规则(AND?settings 能否超出 role?),实现
须 surface,不得默认。ADR-0020 另行钉死 TEAM principal 授权 PROJECT resource 时必须
同 organization;该 tenant well-scopedness 见 `Spec.System.Organization`。
-/
namespace Spec.System
variable (I : Identifiers)
variable (ArtifactId Policy : Type)
/-- 受权限调控的资源(`PINNED` 三类, ADR-0004 `resource_type: project | artifact |
project_group`);每类携带其 id,故 resource_id 由 resource_type 决定(结构无洞)。 -/
inductive Resource where
/-- 课程项目(`PINNED` 类别, ADR-0004)。 -/
| project : I.ProjectId Resource
/-- 教研产物(`PINNED` 类别, ADR-0004;id 表示 `OPEN`,语义向 Courseware 半边对齐)。 -/
| artifact : ArtifactId Resource
/-- 飞书项目群(`PINNED` 类别, ADR-0004 `project_group`;chat 标识见
`Identifiers.ChatId`,绑定见 `ProjectGroup`)。 -/
| projectGroup : I.ChatId Resource
/-- 授权项(`PINNED` 结构, ADR-0004 `PermissionGrant`):把一个 role 授予一个 principal 对
某个 resource。role 取自 `Permission.Role`(read/edit/manage 累积格)。principal 表示
`OPEN`(子类型学未定,见 `Identifiers.Principal`)。 -/
structure PermissionGrant where
/-- 被授权的资源(`PINNED`, ADR-0004 `resource_id`)。 -/
resource : Resource I ArtifactId
/-- 被授权的主体(`PINNED` 字段/`OPEN` 表示, ADR-0004 `principal_id`;user/chat/
department/user_group/app 子类型学未定)。 -/
principal : I.Principal
/-- 授予的角色(`PINNED`, ADR-0004 `role`;read⊂edit⊂manage 见 `Permission.Role`)。 -/
role : Role
/-- 资源策略设置(`PINNED` 结构 + 六旋钮, ADR-0004 `PermissionSettings`):与 grant 分离,
控制"此资源是否开某类操作"。六旋钮由 ADR 逐字列名;各旋钮值域 `OPEN`(ADR 未定,非本层
分歧点)。共享同一 opaque `Policy` 类型:契约只钉死"旋钮存在且相互独立",不钉死"各旋钮
值域互异"——值域是实现/后续 ADR 的事。 -/
structure PermissionSettings where
/-- 设置所属资源(`PINNED`, ADR-0004)。 -/
resource : Resource I ArtifactId
/-- 对外分享策略(`PINNED` 旋钮名, ADR-0004 `external_share_policy`;值域 `OPEN`)。 -/
externalShare : Policy
/-- 评论策略(`PINNED` 旋钮名, ADR-0004 `comment_policy`;值域 `OPEN`)。 -/
comment : Policy
/-- 复制/下载策略(`PINNED` 旋钮名, ADR-0004 `copy_download_policy`;值域 `OPEN`)。 -/
copyDownload : Policy
/-- 协作者管理策略(`PINNED` 旋钮名, ADR-0004 `collaborator_management_policy`;
值域 `OPEN`)。 -/
collaboratorMgmt : Policy
/-- agent 触发策略(`PINNED` 旋钮名, ADR-0004 `agent_trigger_policy`;值域 `OPEN`。与
`agentCancel` 分立——"谁能触发"≠"谁能取消",ADR-0004 故意拆开)。 -/
agentTrigger : Policy
/-- agent 取消策略(`PINNED` 旋钮名, ADR-0004 `agent_cancel_policy`;值域 `OPEN`。与
`agentTrigger` 分立,见上)。 -/
agentCancel : Policy
end Spec.System