feat: 为CK页面增加标签筛选
This commit is contained in:
@@ -14,6 +14,7 @@ from web.backend.models import Account, LoginTask, User
|
||||
from web.backend.routers.cookies import (
|
||||
check_cookie_operations,
|
||||
get_cookie,
|
||||
list_cookie_operation_tags,
|
||||
list_cookie_operations,
|
||||
list_cookies,
|
||||
)
|
||||
@@ -62,6 +63,7 @@ class CookieOperationTests(unittest.TestCase):
|
||||
def test_support_operation_list_is_scoped_and_never_returns_credentials(self):
|
||||
result = list_cookie_operations(
|
||||
search="",
|
||||
tag="",
|
||||
page=1,
|
||||
page_size=20,
|
||||
db=self.session,
|
||||
@@ -72,6 +74,7 @@ class CookieOperationTests(unittest.TestCase):
|
||||
self.assertEqual(result["items"], [{
|
||||
"id": self.owned_task.id,
|
||||
"account_username": "owned-account",
|
||||
"tag": "",
|
||||
"ck_check_status": "",
|
||||
"ck_checked_at": None,
|
||||
"created_at": None,
|
||||
@@ -85,6 +88,45 @@ class CookieOperationTests(unittest.TestCase):
|
||||
with self.assertRaisesRegex(Exception, "cookie:view"):
|
||||
get_cookie(self.owned_task.id, db=self.session, current=self.support)
|
||||
|
||||
def test_cookie_list_filters_by_account_tag(self):
|
||||
admin = User(username="admin", password_hash="hash", role="super_admin")
|
||||
self.session.add(admin)
|
||||
self.session.query(Account).filter(Account.id == self.owned_task.account_id).update({"tag": "A组"})
|
||||
self.session.query(Account).filter(Account.id == self.other_task.account_id).update({"tag": "B组"})
|
||||
self.session.commit()
|
||||
|
||||
result = list_cookies(
|
||||
search="",
|
||||
tag="A组",
|
||||
account_names="",
|
||||
page=1,
|
||||
page_size=20,
|
||||
include_cookie=False,
|
||||
db=self.session,
|
||||
current=admin,
|
||||
)
|
||||
|
||||
self.assertEqual(result["total"], 1)
|
||||
self.assertEqual([item["id"] for item in result["items"]], [self.owned_task.id])
|
||||
|
||||
def test_support_operation_tag_filter_and_list_stay_scoped(self):
|
||||
self.session.query(Account).filter(Account.id == self.owned_task.account_id).update({"tag": "我的标签"})
|
||||
self.session.query(Account).filter(Account.id == self.other_task.account_id).update({"tag": "别人的标签"})
|
||||
self.session.commit()
|
||||
|
||||
tags = list_cookie_operation_tags(db=self.session, current=self.support)
|
||||
result = list_cookie_operations(
|
||||
search="",
|
||||
tag="别人的标签",
|
||||
page=1,
|
||||
page_size=20,
|
||||
db=self.session,
|
||||
current=self.support,
|
||||
)
|
||||
|
||||
self.assertEqual(tags, ["我的标签"])
|
||||
self.assertEqual(result["total"], 0)
|
||||
|
||||
@patch("web.backend.routers.cookies._check_one_cookie")
|
||||
def test_support_can_check_only_assigned_cookie(self, check_one_cookie):
|
||||
check_one_cookie.return_value = {
|
||||
@@ -119,6 +161,7 @@ class CookieOperationTests(unittest.TestCase):
|
||||
with self.assertRaisesRegex(Exception, "cookie:operate"):
|
||||
list_cookie_operations(
|
||||
search="",
|
||||
tag="",
|
||||
page=1,
|
||||
page_size=20,
|
||||
db=self.session,
|
||||
|
||||
Reference in New Issue
Block a user