feat: Wave 2 - API org isolation + factory.html + insights.html
- Add org_id auto-population to articles.py, publishing.py, metrics.py - Add org_id filtering to search_rankings.py geo endpoints - Add org_id to calendar.py create/update/delete endpoints - Add org_id to tasks.py create endpoints - Create factory.html content pipeline page (3-tab: 待创作/进行中/待审查) - Create insights.html analytics page (4-tab: 概览/搜索排名/GEO/平台对比)
This commit is contained in:
@@ -16,10 +16,13 @@ router = APIRouter(prefix="/api/tasks", tags=["tasks"])
|
||||
|
||||
def _check_task_org(task, current_user, db):
|
||||
"""Check if task's topic belongs to user's org"""
|
||||
if current_user.role == "admin" or not task.topic_id:
|
||||
if current_user.role == "admin":
|
||||
return True
|
||||
topic = db.query(Topic).filter(Topic.id == task.topic_id).first()
|
||||
if topic and topic.org_id != current_user.org_id:
|
||||
if task.topic_id:
|
||||
topic = db.query(Topic).filter(Topic.id == task.topic_id).first()
|
||||
if topic and topic.org_id != current_user.org_id:
|
||||
raise HTTPException(status_code=404, detail="任务不存在")
|
||||
elif current_user.role != "admin" and task.org_id != current_user.org_id:
|
||||
raise HTTPException(status_code=404, detail="任务不存在")
|
||||
return True
|
||||
|
||||
@@ -87,7 +90,8 @@ def create_task(
|
||||
topic_id=data.topic_id,
|
||||
stage=data.stage,
|
||||
status="pending",
|
||||
created_by=data.created_by or current_user.username
|
||||
created_by=data.created_by or current_user.username,
|
||||
org_id=current_user.org_id or "default"
|
||||
)
|
||||
db.add(task)
|
||||
db.commit()
|
||||
@@ -438,7 +442,8 @@ def run_creator_task(
|
||||
stage="creator",
|
||||
status="running",
|
||||
started_at=now,
|
||||
created_by=current_user.username
|
||||
created_by=current_user.username,
|
||||
org_id=current_user.org_id or "default"
|
||||
)
|
||||
db.add(task)
|
||||
db.commit()
|
||||
|
||||
Reference in New Issue
Block a user