Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/views/policy-attachment.view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,35 @@ import { PolicyAttachment } from '../objects/policy-attachment.object.js';
// and loading it for every row costs the page.
const policyAttachmentViews: UI.View = {
object: PolicyAttachment.name,
// 表单只放人填的字段,两两成对排齐,附件正文紧接在后面;所属制度、现行由所属版本自动带出,字数、token、
// 哈希由导入工具维护。原件现阶段不上传,字段留给后期,单独一组、默认折叠。helpText 覆盖写给 AI 的说明。
form: {
type: 'simple',
modalSize: 'xl',
sections: [
{
name: 'attachment_main',
label: '附件信息',
columns: 2,
fields: [
{ field: 'policy_version', span: 'full', helpText: '' },
{ field: 'label', helpText: '原文里的编号,如「附件1」' },
{ field: 'sort_no', helpText: '' },
{ field: 'title', helpText: '' },
{ field: 'attachment_class', helpText: '' },
{ field: 'body_md', span: 'full', helpText: '规范性附件的全文(Markdown,已脱敏);表单类可以不填' },
],
},
{
name: 'attachment_original',
label: '原件(后期使用)',
columns: 1,
collapsible: true,
collapsed: true,
fields: [{ field: 'original_file', helpText: '' }],
},
],
},
list: {
label: '全部附件',
type: 'grid',
Expand Down
31 changes: 31 additions & 0 deletions src/views/policy-version.view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,37 @@ import { PolicyVersion } from '../objects/policy-version.object.js';

const policyVersionViews: UI.View = {
object: PolicyVersion.name,
// 新建 / 编辑表单只放人填的字段,两两成对排齐,正文紧接在后面。条号索引、字数、token 估算、内容哈希由
// 导入工具(tools/redact)维护,不在表单里。正文原件现阶段不上传,字段留给后期,单独一组、默认折叠。
// 对象字段的 description 写给 AI,表单里用 helpText 覆盖成给人看的短句(不需要提示的字段给空串)。
form: {
type: 'simple',
modalSize: 'xl',
sections: [
{
name: 'version_main',
label: '版本信息',
columns: 2,
fields: [
'policy',
{ field: 'version_no', helpText: '' },
{ field: 'title', span: 'full', helpText: '' },
{ field: 'effective_date', helpText: '' },
{ field: 'version_status', helpText: '' },
{ field: 'change_note', span: 'full', helpText: '' },
{ field: 'body_md', span: 'full', helpText: '脱敏后的正文(Markdown):条文以 **第X条** 开头,章节用 ## 标题' },
],
},
{
name: 'version_original',
label: '原件(后期使用)',
columns: 1,
collapsible: true,
collapsed: true,
fields: [{ field: 'original_file', helpText: '' }],
},
],
},
list: {
label: '全部版本',
type: 'grid',
Expand Down
20 changes: 16 additions & 4 deletions tools/redact/remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,23 @@ def package_targets(api: Api, package: Path, apply: bool) -> List[Dict]:
return list(found.values())


def count_attachments(api: Api, version_id: str) -> int:
"""版本下的附件数,只用于显示。附件子表(brightrule_policy_attachment)是后来的结构;还没部署它的环境里
同样的记录在旧的版本文档表(brightrule_policy_document)。两种都随版本级联删除,删除顺序不受影响。"""
for obj in ('brightrule_policy_attachment', 'brightrule_policy_document'):
try:
return len(api.find(obj, {'policy_version': version_id}, 'id'))
except ApiError as e:
if isinstance(e, AuthError) or 'not registered' not in str(e):
raise
return 0


def plan(api: Api, policy: Dict) -> List[tuple]:
"""删除顺序:条款(挂在制度上,限制删除)→ 版本(附件、以它为来源的关系随之删除)→ 制度。"""
clauses = api.find('brightrule_clause', {'policy': policy['id']}, 'id')
versions = api.find('brightrule_policy_version', {'policy': policy['id']}, 'id,version_no,version_status')
atts = sum(len(api.find('brightrule_policy_attachment', {'policy_version': v['id']}, 'id')) for v in versions)
atts = sum(count_attachments(api, v['id']) for v in versions)
print(f' {policy.get("title")}({policy.get("policy_no") or "无编号"}):版本 {len(versions)} 个、附件 {atts} 个、条款 {len(clauses)} 条')
return ([('brightrule_clause', c['id']) for c in clauses]
+ [('brightrule_policy_version', v['id']) for v in versions]
Expand Down Expand Up @@ -91,10 +103,10 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
progress = Progress(len(policies))
for p in policies:
print(progress.next(), end='')
steps = plan(api, p)
if not args.apply:
continue
try:
steps = plan(api, p)
if not args.apply:
continue
for obj, rid in steps:
api.delete(obj, rid)
print(' 已删除')
Expand Down