feat(weibo): 支持工作台账号转入外部单协作
This commit is contained in:
@@ -45,6 +45,8 @@ from ..schemas import (
|
||||
WeiboWorkbenchBatchImportItem,
|
||||
WeiboWorkbenchBatchImportOut,
|
||||
WeiboWorkbenchBatchImportRequest,
|
||||
WeiboWorkbenchTransferToCollabOut,
|
||||
WeiboWorkbenchTransferToCollabRequest,
|
||||
)
|
||||
from ..services.audit_service import record_audit
|
||||
from ..services.weibo_service import (
|
||||
@@ -607,6 +609,57 @@ def add_workbench_accounts(
|
||||
return {"account_ids": account_ids, "success": True}
|
||||
|
||||
|
||||
@router.post(
|
||||
"/workbench/accounts/transfer-to-collab",
|
||||
response_model=WeiboWorkbenchTransferToCollabOut,
|
||||
)
|
||||
def transfer_workbench_to_collab(
|
||||
req: WeiboWorkbenchTransferToCollabRequest,
|
||||
db: Session = Depends(get_db),
|
||||
current: User = Depends(get_current_user),
|
||||
):
|
||||
"""把当前工作台账号移出,并引导到外部单协作新建订单。"""
|
||||
|
||||
_require_weibo_perm(current, "weibo:workbench")
|
||||
membership = (
|
||||
db.query(WeiboWorkbenchAccount)
|
||||
.filter(
|
||||
WeiboWorkbenchAccount.user_id == current.id,
|
||||
WeiboWorkbenchAccount.account_id == req.account_id,
|
||||
)
|
||||
.first()
|
||||
)
|
||||
if membership is None:
|
||||
raise HTTPException(status_code=404, detail="该账号不在当前微博工作台")
|
||||
|
||||
account = _get_account(db, req.account_id, current)
|
||||
_ensure_enabled(account)
|
||||
if not str(account.cookie or "").strip():
|
||||
raise HTTPException(
|
||||
status_code=400, detail="该账号没有可用 Cookie,无法转入外部单协作"
|
||||
)
|
||||
|
||||
db.delete(membership)
|
||||
db.commit()
|
||||
_record_audit_safely(
|
||||
db,
|
||||
current,
|
||||
action="weibo:workbench:transfer_collab",
|
||||
target=f"weibo_account:{account.id}",
|
||||
detail={
|
||||
"account_id": account.id,
|
||||
"uid": account.uid,
|
||||
"nickname": account.nickname,
|
||||
},
|
||||
)
|
||||
return WeiboWorkbenchTransferToCollabOut(
|
||||
account_id=account.id,
|
||||
uid=account.uid,
|
||||
nickname=account.nickname,
|
||||
game_role_name=account.game_role_name,
|
||||
)
|
||||
|
||||
|
||||
@router.post("/workbench/accounts/remove")
|
||||
def remove_workbench_accounts(
|
||||
req: WeiboWorkbenchAccountsRequest,
|
||||
|
||||
@@ -521,6 +521,18 @@ class WeiboWorkbenchAccountsRequest(BaseModel):
|
||||
account_ids: list[int] = Field(default_factory=list)
|
||||
|
||||
|
||||
class WeiboWorkbenchTransferToCollabRequest(BaseModel):
|
||||
account_id: int = Field(..., gt=0)
|
||||
|
||||
|
||||
class WeiboWorkbenchTransferToCollabOut(BaseModel):
|
||||
success: bool = True
|
||||
account_id: int
|
||||
uid: str = ""
|
||||
nickname: str = ""
|
||||
game_role_name: str = ""
|
||||
|
||||
|
||||
class WeiboWorkbenchBatchImportRequest(BaseModel):
|
||||
text: str = Field(..., min_length=1, max_length=100_000)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user