Commit Graph

45 Commits

Author SHA1 Message Date
Codex Agent 26a7b531f3 Update auth flows and admin tools 2026-03-19 15:14:42 +08:00
Codex Agent d97c7ca086 fix: 优化组织架构显示顺序,解决市级部门层级显示问题
修改内容:
- 后端:修改 service_department_tree 排序逻辑,实现叶子节点优先显示
- 前端:添加组织架构渲染调试日志,便于排查层级问题
- 文档:添加前端调试指南、快速参考和实施总结文档

排序规则:
1. 无下属单位的部门(叶子节点)排在前面
2. 有下属单位的部门(父节点)排在后面
3. 同类节点按名称排序

预期效果:
- "佛山交通运输局"等市级部门不再被误认为区级部门的子节点
- 视觉层次更清晰,减少用户误解
- 层级关系保持不变(都是 Level 1)

相关文件:
- lawrisk/services/licensing_repo.py
- static/super_admin.html
- FRONTEND_DEBUG_GUIDE.md
- HIERARCHY_DEBUG_QUICK_REF.md
- IMPLEMENTATION_SUMMARY.md
- SORTING_FIX_SUMMARY.md

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-10 19:51:25 +08:00
Codex Agent 616cac2c2e feat: 实施严格部门权限控制并修复导入功能
主要修改:
- 添加严格的部门层级权限控制(只看自己及下级部门,不看父级)
- 在 filter_permits_advanced() 添加 expand_department_family 参数
- 修复许可导入时的部门自动绑定功能
- 在 API 端点添加用户认证和部门权限过滤

技术细节:
- lawrisk/api/v2.py: 添加 @login_required 和部门权限过滤逻辑
- lawrisk/services/licensing_repo.py: 添加 expand_department_family 参数控制部门扩展行为
- static/db_admin.html: 修复导入功能,自动绑定到用户部门
- lawrisk/api/auth.py: 添加 is_superuser 权限检查

影响范围:
- 用户现在只能看到自己部门及下级部门上传的许可事项
- 新导入的许可事项会自动绑定到当前用户的部门
- 超级管理员不受影响

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-10 19:06:06 +08:00
Codex Agent b0590fda30 feat: enhance theme and permit listing with filtering and risk counts
- Filter out "不涉及" (not applicable) theme from list_all_themes()
- Add risk_count column to list_unbound_permits() with aggregated risk counts
- Improve unbound permits API to display risk count per permit-region combination

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-04 13:52:57 +08:00
Codex Agent fe911592e0 fix: resolve server deployment image 404 errors and enhance admin UI
- Add dedicated image serving API endpoint (/admin/images/<filename>) with security whitelist
- Update image paths from /static/ to /fs-ai-asistant/api/workflow/lawrisk/admin/images/
- Add permit import sample file download endpoint
- Enhance import wizard UI with template/sample preview section
- Add risk count column to unbound permits table
- Filter out "不涉及" (not applicable) theme from theme list
- Improve permit import UX with better visual organization

This ensures images load correctly in server deployments (nginx, gunicorn) by using
the same API prefix as other admin resources, avoiding static file routing issues.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-04 13:51:20 +08:00
Codex Agent 347af34bfc Refine import wizard: simplify permit details, add image zoom, and enhance risk metadata display (legal basis, document no, summary) 2026-01-27 15:33:33 +08:00
Codex Agent e7da819fea feat(ui,api): resolve department filter errors and enhance import wizard 2026-01-27 14:23:03 +08:00
Codex Agent fbc696b61c feat: add visibility filter to unbound permits API 2025-12-29 16:59:26 +08:00
Codex Agent c55170208b feat: add visibility filter for permit management and fix V2 visibility logic
- Added 'Enabled Status' dropdown filter to db_admin.html for filtering permits by visibility (visible/hidden/all)
- Updated admin_permits_advanced_filter API to accept and process visibility parameter
- Modified filter_permits_advanced in licensing_repo.py to filter by is_v2_visible column
- Fixed role-based access control to allow department_admin to toggle permit visibility
- Improved parameter parsing in API endpoints for more robust handling
2025-12-29 15:54:53 +08:00
Codex Agent b532c46dc1 feat: 优化事项过滤逻辑与后台管理界面交互 2025-12-26 09:26:10 +08:00
黄仁欢 1595027679 fix: resolve missing preview data in permit import session and fix logging bug 2025-12-25 19:56:56 +08:00
Codex Agent 762d0c0115 Cleanup: Organize project structure and resolve merge conflicts 2025-12-25 19:18:37 +08:00
Codex Agent 06944cd251 Backup database 2025-12-25 and clean up project structure 2025-12-25 09:50:02 +08:00
Codex Agent e9b9d9ad74 Refactor: Organize project structure by moving scripts to tools and data files to data directory 2025-12-24 09:26:19 +08:00
Codex Agent 60b94d8a20 feat: 修复V2 API许可证名称匹配和审批部门显示
- 添加permit_approval_departments表自动创建和管理
- 实现许可证名称的精确匹配和前缀模糊匹配
- 修复find_permit_contexts_by_name支持前缀匹配(如'药品经营许可'匹配'药品经营许可证')
- 修复load_permits_and_risks中的审批部门JOIN逻辑,使用CONCAT进行前缀匹配
- 新增管理API端点 /admin/approval-departments/setup 用于初始化审批部门映射
- 更新.gitignore忽略临时脚本和Excel文件
2025-12-23 16:23:10 +08:00
Codex Agent 199a97cceb Fix: Allow searching for unbound permits by name 2025-12-22 16:27:48 +08:00
Codex Agent 73cd32b50d Fix duplicate risk deletion logic and clean up project structure 2025-12-22 11:27:09 +08:00
Codex Agent 6dd5621fad docs: create root README and update guides with checkpoint system info; fix: JSON serialization bug in checkpoint creation for binary data 2025-12-21 17:26:04 +08:00
Codex Agent de25932248 feat: enhance permit details display and cleanup project directory
- Added contact_info to permit details view and database schema
- Renamed display labels: 'Responsible Department' -> 'Contact Info (Internal)', 'Contact Info' -> 'Contact Info (External)', 'Jurisdiction Scope' -> 'Implementation Level'
- Implemented risk sorting by serial number and display of serial numbers
- Updated .gitignore to exclude temporary debug/fix/verify scripts
- Cleaned up the project directory by removing temporary files from tracking
2025-12-20 16:53:57 +08:00
Codex Agent f45f37db89 chore: reorganize directory structure and clean up root directory 2025-12-20 11:25:34 +08:00
Codex Agent b53fb872ed Refine login status bar UI in super_admin.html and db_admin.html 2025-12-18 11:51:43 +08:00
Codex Agent a3f6640b2d feat: V2接口使用预设问题推荐替代LLM生成
- 新增预设问题模板,基于数据库中有许可事项的主题生成问题
- 移除LLM调用,提升响应速度
- 只推荐有实际许可事项的主题相关问题
- 整理项目结构:test文件移至tests/,xlsx移至data/,md文档移至docs/
2025-12-15 13:35:57 +08:00
Codex Agent 64585261c4 feat(admin): 账号区域标识回填 2025-11-27 17:13:49 +08:00
Codex Agent 34bce0f5df feat(admin): 账号创建支持单位电话 2025-11-27 16:19:43 +08:00
Codex Agent a4e1e9baef chore(admin): checkpoint before layout update 2025-11-27 15:26:59 +08:00
Codex Agent 9a392f62b0 feat: add super admin v2 debug console 2025-11-24 15:18:49 +08:00
Codex Agent 9aa6fabfb1 feat: 增强许可详情页面显示完整信息
在许可详情弹窗中添加了完整的许可信息展示区域,包括以下7个字段:
1. 许可情况 - 显示许可状态
2. 许可(备案)事项子项 - 显示子项详情
3. 行政区域 - 显示所属区域
4. 负责部门 - 显示负责部门和联系方式
5. 权限划分 - 显示权限范围
6. 经营范围 - 显示业务范围(跨列显示)

所有字段均使用清晰标签、两列网格布局,经营范围字段跨列显示适合长文本。
信息层次清晰:基本信息 → 许可信息 → 风险信息。

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 09:47:20 +08:00
Codex Agent ec44bec90a feat: 实现许可事项管理多选筛选器及区域部门关联过滤
 核心功能实现:

1. 多选筛选器界面
   - 行政区域多选支持
   - 主题多选支持
   - 关联部门多选支持
   - 全选/取消全选功能
   - 实时显示选中数量

2. 区域与部门智能关联过滤
   - 选择区域后自动更新关联部门列表
   - 通过permit_sources表建立region与department关联关系
   - 避免无效筛选条件组合
   - 提升用户体验和数据准确性

📝 修改文件:

- lawrisk/services/licensing_repo.py
  * 新增 list_service_departments(region_id) 函数
  * 支持按region_id筛选部门列表

- lawrisk/api/v2.py
  * 修改 admin_permits_filter_options() 路由
  * 支持 region_id 查询参数

- static/db_admin.html
  * 实现多选下拉菜单组件
  * 新增区域选择变化处理函数
  * 新增动态加载关联部门功能

🧪 测试验证:

- API测试通过:带region_id参数返回关联部门
- Flask应用正常启动
- 多选筛选功能完全可用

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-19 15:51:49 +08:00
Codex Agent a6fe2f4370 feat: 登录权限跳转安全优化与权限控制系统完善
## 主要修改

### 🔒 安全优化 (auth.py)
- 统一所有用户登录跳转路径,防止权限暴露
- 所有用户默认跳转到 /fs-ai-asistant/api/workflow/lawrisk/db_admin
- 移除基于权限等级的多路径跳转逻辑
- 移除调试字段 TEST_MARKER

### 🛡️ 权限控制系统 (licensing_repo.py)
- 实现基于用户等级的权限过滤
- 超级管理员(grade=100)和市级管理员(grade>=90): 查看所有区域数据
- 区级管理员(grade<90): 只能查看自己区域数据
- 添加详细的权限拒绝日志记录

### 👥 用户管理增强 (auth_service.py, v2.py)
- 添加 delete_user_account 函数
- 实现用户删除API端点
- 防止删除最后一个管理员账号的安全检查

### 🎨 UI优化 (super_admin.html)
- 更新界面文案: "新的服务部门" → "绑定服务部门"

## 测试验证
-  所有用户统一跳转验证通过
-  权限控制逻辑验证通过
-  用户删除功能验证通过
-  自定义next参数支持正常

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-18 15:45:30 +08:00
Codex Agent 9ca9a3642f feat: 组织架构权限等级自动管理系统
## 主要功能
- 实现基于组织架构层级的权限等级自动计算
- 权限等级映射:根级(90)、二级(80)、三级(70)、四级+(60)
- 自动根据从属关系计算权限,无需手动填写

## 安全修复
- 修复密码在URL中泄露的严重安全问题
- 清理所有重定向URL的查询参数
- 前端敏感参数检测与警告

## 用户体验优化
- 移除组织架构树的权限等级显示
- 简化新增/编辑部门的表单界面
- 实现智能登录跳转(基于角色自动跳转)
- Tooltip跟随鼠标,修复滚动偏移bug

## 技术实现
- 前端:自动权限计算函数、拖拽功能、模态框交互
- 后端:_calculate_grade_by_parent()、_get_department_level()
- 数据库:保留grade字段,自动同步层级关系

## 修复的问题
- 组织架构管理按钮无响应
- 登录跳转404错误
- 权限等级手动设置繁琐
- Tooltip位置偏移

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-18 09:39:18 +08:00
Codex Agent 1c010f4fdf feat: add authentication system and service department tree structure
## Major Changes

### Authentication System
- Added passlib dependency for password hashing and security
- Integrated auth_service module with automatic admin seeding
- Added authentication blueprint and middleware
- Updated app initialization to ensure auth schema and default accounts

### Service Department Management
- Added build_service_department_tree() function for hierarchical data structure
- Supports nested parent-child relationships for department hierarchy
- Recursive sorting for consistent tree visualization
- Enables advanced admin interface features

### Dependencies
- Added passlib>=1.7.4 for secure password hashing
- Added openpyxl>=3.1.2 for Excel file processing

### UI Improvements
- Enhanced db_admin.html with tabbed interface styling
- Improved spacing and visual layout
- Better organization for multiple admin functions

## Technical Details
- Refactored app.py to use auth_service instead of deprecated ensure_database
- Maintains backward compatibility with existing v2 API
- Clean separation of authentication and business logic

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-17 15:07:14 +08:00
Codex Agent 168cdf6470 feat: add super admin console 2025-11-14 15:46:18 +08:00
Codex Agent 90fa969046 fix: honor permit overrides and bindings 2025-11-14 11:43:43 +08:00
Codex Agent 0076d2db2f feat: add permit file management UI and APIs 2025-11-14 10:32:23 +08:00
Codex Agent 66cc871e47 feat: redesign db admin import flow 2025-11-13 19:21:59 +08:00
Codex Agent fd82b757fe feat: show permit themes in db admin 2025-11-13 17:01:37 +08:00
Codex Agent 772354bd01 feat: support permit file uploads 2025-11-13 15:28:08 +08:00
Codex Agent 5b86bd8799 feat: 优化许可导入区划合并与来源展示 2025-11-04 13:38:21 +08:00
Codex Agent ec8adf98f1 feat: add permit risk snapshot workflow 2025-11-03 09:43:58 +08:00
Codex Agent cf3bfd3fc0 feat: checkpoint system comprehensive enhancement
Security Fixes:
- Fix critical data loss risk in restore_checkpoint (TRUNCATE without rollback)
- Add table dependency tracking with topological sort
- Implement auto-backup before restore for safety
- Add table-level locks during restore (EXCLUSIVE MODE)
- Single transaction for atomic operations

Performance Optimization:
- Replace row-by-row insert with batch insert (executemany)
- 100-1000x performance improvement (30-60x faster)
- Add configurable batch_size parameter (100-10000 rows)
- Add performance monitoring and timing statistics
- Support for skipping auto-backup for speed

Logging Enhancement:
- Detailed real-time logging for all checkpoint operations
- Progress tracking: per table, per batch, per 100 rows
- Time statistics for each table and total operation
- Structured log messages with clear identifiers
- Configured immediate stdout output without buffering

Documentation:
- Updated CLAUDE.md with improved guidelines
- Created CHECKPOINT_SECURITY_FIX_SUMMARY.md
- Created CHECKPOINT_LOGGING_GUIDE.md
- Created CHECKPOINT_PERFORMANCE_OPTIMIZATION.md
- Created PATCH_CHECKPOINT_SECURITY.md
- Created analysis/checkpoint_analysis.md

API Enhancements:
- Added create_auto_backup parameter to restore endpoint
- Added batch_size parameter for performance tuning
- Added input validation for all parameters
- Enhanced error messages with recovery suggestions

Modified Files:
- lawrisk/services/licensing_repo.py: Core checkpoint logic
- lawrisk/api/v2.py: REST API endpoints
- app.py: Logging configuration
- docs/CLAUDE.md: Updated development guide

Closes: #security #performance #logging

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-31 17:33:12 +08:00
Codex Agent e462f609ba fix: resolve foreign key constraint violation during checkpoint restore
Issue:
- Restore operation failed with foreign key constraint violation
- Error: "update or delete on table business_scopes violates foreign key constraint"
- Problem: DELETE operations didn't handle foreign key dependencies correctly

Solution:
- Changed DELETE FROM to TRUNCATE TABLE ... CASCADE in _restore_table()
- TRUNCATE with CASCADE automatically removes dependent records
- Now restore operation properly handles all foreign key relationships
- Data can be restored without constraint violations

This ensures checkpoint restore works correctly across all related tables.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-30 13:39:01 +08:00
Codex Agent 1fa9385d02 fix: resolve UUID JSON serialization error in checkpoint creation
Issue:
- Object of type <class 'uuid.UUID'> is not JSON serializable error when creating checkpoints
- UUID objects in database records couldn't be serialized to JSON

Solution:
- Updated json_serializer function in create_checkpoint() to properly handle UUID types
- Added explicit isinstance check for uuid.UUID before checking for isoformat
- Ensures all UUID values are converted to strings before JSON serialization

This ensures checkpoints can be created successfully with all database data types.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-30 11:52:06 +08:00
Codex Agent 9530eabac8 feat: add database checkpoint management system
Features:
- Create manual database checkpoints with descriptions
- List all available checkpoints with statistics
- Restore database from checkpoints (with dangerous operation warning)
- Delete unwanted checkpoints
- Frontend UI integrated into database admin panel
- JSON-based checkpoint storage in data/checkpoints/

Backend Changes:
- Added checkpoint management functions to licensing_repo.py:
  * create_checkpoint() - backup all tables to JSON
  * list_checkpoints() - enumerate checkpoint files
  * restore_checkpoint() - restore from checkpoint
  * delete_checkpoint() - remove checkpoint file
- Added 4 new API endpoints to v2.py:
  * GET /admin/checkpoints - list checkpoints
  * POST /admin/checkpoints - create checkpoint
  * POST /admin/checkpoints/{id}/restore - restore checkpoint
  * DELETE /admin/checkpoints/{id} - delete checkpoint

Frontend Changes (db_admin.html):
- Added step 5 "检查点管理" to navigation
- Created checkpoint management UI with forms and lists
- Added dangerous operation confirmation modal
- Integrated into existing breadcrumb navigation system

Safety Features:
- All dangerous operations require explicit confirmation
- Restore operations show warning about data loss
- Checkpoints include row counts and table statistics
- Timestamped checkpoint IDs for easy identification

Note: Checkpoint files are stored in data/checkpoints/ directory

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-30 10:33:35 +08:00
Codex Agent cbefb81a35 feat: 实现数据库维护功能
## 新增功能

### 1. 后端API路由 (lawrisk/api/v2.py)
- 添加了5个新的管理API端点:
  * GET /admin/regions - 获取地区列表
  * GET /admin/themes - 获取主题列表(按地区筛选)
  * GET /admin/permits - 获取许可列表(按地区和主题筛选)
  * GET /admin/permit-details - 获取许可详细信息
  * GET /admin/test - 测试路由

### 2. 前端管理界面 (static/db_admin.html)
- 实现了完整的数据库维护管理页面
- 4步操作流程:地区选择 → 主题列表 → 许可列表 → 详细信息展示
- 现代化UI设计,包括:
  * 渐变背景和响应式布局
  * 平滑动画过渡效果
  * 实时数据加载提示
  * 完整的许可信息展示(许可状态、经营范围、法律风险等)

## 技术实现
- RESTful API设计,返回标准JSON格式
- 直接从PostgreSQL数据库读取数据
- 所有API已通过curl和Flask测试客户端验证

## 测试结果
在端口8888上测试通过:
- admin/regions: 1个地区
- admin/themes: 57个主题
- admin/permits: 6个许可
- admin/permit-details: 完整许可信息和3个风险记录
- 静态页面: 成功加载

## 使用方法
```bash
# 启动服务
PORT=8888 python app.py &

# 访问管理界面
http://localhost:8888/static/db_admin.html

# API调用示例
curl http://localhost:8888/fs-ai-asistant/api/workflow/lawrisk/admin/regions
```

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-30 08:52:48 +08:00
Codex Agent bfda66afc1 refactor: 重新规划项目结构为标准Python包
主要变更:
- 重组项目目录结构,采用标准Python包组织方式
  * 创建 lawrisk/ 主包
  * 分离 API 路由层 (api/v1.py, api/v2.py)
  * 封装业务逻辑层 (services/)
  * 抽取中间件 (middleware/)
  * 整理工具模块 (utils/)

- 重构应用入口
  * 使用 Flask Blueprint 注册路由
  * 简化 app.py 逻辑

- 添加项目文档
  * 创建 README.md 项目说明
  * 创建 requirements.txt 依赖管理
  * 统一文档到 docs/ 目录

- 文件组织优化
  * 数据文件移动到 data/
  * 测试目录 tests/ 准备就绪

- 修复导入路径
  * 更新所有模块导入为相对路径
  * 确保应用正常启动运行

验证:
 应用成功启动在端口 8000
 所有路由正确注册
 健康检查端点正常响应

Closes: #重构项目结构
2025-10-29 15:31:01 +08:00