feat: 为CK页面增加标签筛选
This commit is contained in:
@@ -163,6 +163,7 @@ def _visible_cookie_tasks_query(db: Session, current: User):
|
||||
@router.get("")
|
||||
def list_cookies(
|
||||
search: str = Query(""),
|
||||
tag: str = Query(""),
|
||||
account_names: str = Query(""),
|
||||
page: int | None = Query(None, ge=1),
|
||||
page_size: int = Query(20, ge=1, le=200),
|
||||
@@ -180,6 +181,7 @@ def list_cookies(
|
||||
joinedload(LoginTask.account).joinedload(Account.assigned_user),
|
||||
)
|
||||
search_text = (search or "").strip()
|
||||
tag_value = (tag or "").strip()
|
||||
selected_names = _parse_account_names(account_names)
|
||||
can_view_all = user_has_permission(current, "login:view_all")
|
||||
account_joined = not can_view_all
|
||||
@@ -188,6 +190,11 @@ def list_cookies(
|
||||
query = query.join(Account, LoginTask.account_id == Account.id)
|
||||
account_joined = True
|
||||
query = query.filter(Account.username.in_(selected_names))
|
||||
if tag_value:
|
||||
if not account_joined:
|
||||
query = query.join(Account, LoginTask.account_id == Account.id)
|
||||
account_joined = True
|
||||
query = query.filter(Account.tag == tag_value)
|
||||
if search_text:
|
||||
pattern = f"%{search_text}%"
|
||||
if not account_joined:
|
||||
@@ -195,6 +202,7 @@ def list_cookies(
|
||||
account_joined = True
|
||||
query = query.outerjoin(User, Account.assigned_to == User.id).filter(or_(
|
||||
Account.username.ilike(pattern),
|
||||
Account.tag.ilike(pattern),
|
||||
User.username.ilike(pattern),
|
||||
))
|
||||
|
||||
@@ -276,6 +284,7 @@ def cookies_summary(
|
||||
@router.get("/operations")
|
||||
def list_cookie_operations(
|
||||
search: str = Query(""),
|
||||
tag: str = Query(""),
|
||||
page: int = Query(1, ge=1),
|
||||
page_size: int = Query(20, ge=1, le=200),
|
||||
db: Session = Depends(get_db),
|
||||
@@ -287,8 +296,14 @@ def list_cookie_operations(
|
||||
if user_has_permission(current, "login:view_all"):
|
||||
query = query.join(Account, LoginTask.account_id == Account.id)
|
||||
search_text = (search or "").strip()
|
||||
tag_value = (tag or "").strip()
|
||||
if tag_value:
|
||||
query = query.filter(Account.tag == tag_value)
|
||||
if search_text:
|
||||
query = query.filter(Account.username.ilike(f"%{search_text}%"))
|
||||
query = query.filter(or_(
|
||||
Account.username.ilike(f"%{search_text}%"),
|
||||
Account.tag.ilike(f"%{search_text}%"),
|
||||
))
|
||||
|
||||
total = query.order_by(None).count()
|
||||
tasks = (
|
||||
@@ -302,6 +317,7 @@ def list_cookie_operations(
|
||||
{
|
||||
"id": task.id,
|
||||
"account_username": task.account.username if task.account else "",
|
||||
"tag": task.account.tag if task.account else "",
|
||||
"ck_check_status": task.ck_check_status or "",
|
||||
"ck_checked_at": _fmt_dt(task.ck_checked_at),
|
||||
"created_at": _fmt_dt(task.finished_at),
|
||||
@@ -314,6 +330,26 @@ def list_cookie_operations(
|
||||
}
|
||||
|
||||
|
||||
@router.get("/operations/tags")
|
||||
def list_cookie_operation_tags(
|
||||
db: Session = Depends(get_db),
|
||||
current: User = Depends(get_current_user),
|
||||
):
|
||||
"""返回当前用户可操作 CK 记录对应的标签,不跨越账号分配范围。"""
|
||||
_require_cookie_operation_perm(current)
|
||||
query = _visible_cookie_tasks_query(db, current)
|
||||
if user_has_permission(current, "login:view_all"):
|
||||
query = query.join(Account, LoginTask.account_id == Account.id)
|
||||
rows = (
|
||||
query.filter(Account.tag != "", Account.tag.isnot(None))
|
||||
.with_entities(Account.tag)
|
||||
.distinct()
|
||||
.order_by(Account.tag.asc())
|
||||
.all()
|
||||
)
|
||||
return [tag for tag, in rows if tag]
|
||||
|
||||
|
||||
@router.get("/duplicates")
|
||||
def find_duplicate_cookies(
|
||||
db: Session = Depends(get_db),
|
||||
|
||||
Reference in New Issue
Block a user