Merge remote-tracking branch 'origin/dev' into feature/1.4-liujian
# Conflicts: # services/admin_service/services/user_wallet_history_service.py
This commit is contained in:
commit
fdbb077293
46 files changed
+1647
-126
No files matched your search
@@ -7,6 +7,7 @@ KEY_SUBHEADLINE = "subheadline"
|
||||
KEY_LANGUAGE = "language"
|
||||
KEY_THEME = "theme"
|
||||
KEY_ABOUT_PAGE = "about_page"
|
||||
KEY_TAG_BAR_DISPLAY = "tag_bar_display"
|
||||
KEY_ADMIN_USERNAME = "admin_username"
|
||||
KEY_ADMIN_PASSWORD = "admin_password"
|
||||
KEY_LOGIN_GOOGLE_CLIENT = "login_google_client_id"
|
||||
|
||||
@@ -67,6 +67,7 @@ def get_config(
|
||||
"facebook_image_url": values.get(KEY_FACEBOOK_IMAGE_URL, ""),
|
||||
"social_account_facebook_url": values.get(KEY_SOCIAL_ACCOUNT_FACEBOOK_URL, ""),
|
||||
"social_account_x_url": values.get(KEY_SOCIAL_ACCOUNT_X_URL, ""),
|
||||
"tag_bar_display": values.get(KEY_TAG_BAR_DISPLAY, "false").lower() in ("true", "t", "yes", "y", "1"),
|
||||
},
|
||||
"faq": faq,
|
||||
"embeded_html": embeded_html,
|
||||
|
||||
@@ -272,6 +272,20 @@ def get_mcp_service_simple_list(
|
||||
logger.error(f"Failed to get service simple list: {str(e)}")
|
||||
return ResponseUtils.error(error_msg=error_msg.INTERNAL_ERROR)
|
||||
|
||||
@router.get("/service/tags", summary="Get MCP service tags")
|
||||
def get_mcp_service_tags(
|
||||
request: Request,
|
||||
mcp_manager_service: McpManagerService = Depends(get_mcp_manager),
|
||||
):
|
||||
if not UserUtils.is_admin(request):
|
||||
return ResponseUtils.error(error_msg=error_msg.NO_PERMISSION)
|
||||
try:
|
||||
tags = mcp_manager_service.get_tags_list(enabled_only=False)
|
||||
return ResponseUtils.success(data=tags)
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to get service tags: {str(e)}")
|
||||
return ResponseUtils.error(error_msg=error_msg.INTERNAL_ERROR)
|
||||
|
||||
@router.get("/service/resource_group/list", summary="Get MCP service's resource group list")
|
||||
def get_mcp_service_resource_group_list(
|
||||
request: Request,
|
||||
@@ -362,4 +376,4 @@ def unbind_group(
|
||||
return ResponseUtils.success()
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to unbind resource groups: {str(e)}")
|
||||
return ResponseUtils.error(error_msg=error_msg.INTERNAL_ERROR)
|
||||
return ResponseUtils.error(error_msg=error_msg.INTERNAL_ERROR)
|
||||
@@ -1,4 +1,7 @@
|
||||
from os import stat
|
||||
from typing import Optional, List
|
||||
from fastapi import APIRouter, Depends, Query
|
||||
from services.common.models.user_wallet_history import TransactionType
|
||||
from sqlalchemy import table
|
||||
from sqlalchemy.orm import Session
|
||||
from services.common.database import get_db
|
||||
@@ -59,3 +62,39 @@ def get_user_order_list(
|
||||
)
|
||||
|
||||
return ResponseUtils.success_page(data=result, total=total, page_num=page, page_size=page_size)
|
||||
|
||||
@router.get("/list/by_user", summary="Get user order list by user id")
|
||||
def get_user_order_list_by_user_id(
|
||||
user_id: str = Query(..., description="User ID"),
|
||||
page: int = Query(1, description="Current page number"),
|
||||
page_size: int = Query(15, description="Number of items per page"),
|
||||
order_type: Optional[str] = Query(None, description="Order type"),
|
||||
status: Optional[str] = Query(None, description="Order status"),
|
||||
user_service: UserService = Depends(get_user_service),
|
||||
user_wallet_history_service: UserWalletHistoryService = Depends(get_user_wallet_history_service),
|
||||
):
|
||||
"""Get paginated list of user order history by user id."""
|
||||
user = user_service.get_by_id(user_id)
|
||||
if not user:
|
||||
return ResponseUtils.error(message="not found user", code=404)
|
||||
offset = (page - 1) * page_size
|
||||
order_type_list = []
|
||||
if order_type:
|
||||
# 将字符串转成列表,中间使用逗号分隔
|
||||
ots = order_type.split(",")
|
||||
for ot in ots:
|
||||
ot = ot.strip()
|
||||
if ot == "purchase":
|
||||
order_type_list.append("api_call")
|
||||
elif ot == "recharge":
|
||||
order_type_list.append("deposit")
|
||||
else:
|
||||
order_type_list.append(ot)
|
||||
status_list: Optional[List[int]] = []
|
||||
if status:
|
||||
sl = status.split(",")
|
||||
for s in sl:
|
||||
status_list.append(int(s.strip()))
|
||||
total, orders = user_wallet_history_service.success_order_list_by_user(user_id, offset, page_size, order_type_list, status_list)
|
||||
|
||||
return ResponseUtils.success_page(data=orders, total=total, page_num=page, page_size=page_size)
|
||||
@@ -144,6 +144,7 @@ def get_sysconfig(
|
||||
"social_account_facebook_url": small_values.get(sys_config_key.KEY_SOCIAL_ACCOUNT_FACEBOOK_URL, ""),
|
||||
"social_account_x_url": small_values.get(sys_config_key.KEY_SOCIAL_ACCOUNT_X_URL, ""),
|
||||
"cname_a_ip": cname_a_ip,
|
||||
"tag_bar_display": small_values.get(sys_config_key.KEY_TAG_BAR_DISPLAY, "").lower() in ("true", "t", "yes", "y", "1"),
|
||||
},
|
||||
"account": {
|
||||
"username": admin_username,
|
||||
@@ -219,6 +220,9 @@ def set_sysconfig(
|
||||
facebook_image_url = platform.get("facebook_image_url")
|
||||
social_account_facebook_url = platform.get("social_account_facebook_url")
|
||||
social_account_x_url = platform.get("social_account_x_url")
|
||||
tag_bar_display = platform.get("tag_bar_display")
|
||||
|
||||
|
||||
|
||||
account = body.get("account", {})
|
||||
admin_username = account.get("username")
|
||||
@@ -270,6 +274,7 @@ def set_sysconfig(
|
||||
(sys_config_key.KEY_FACEBOOK_IMAGE_URL, facebook_image_url, "Facebook image URL"),
|
||||
(sys_config_key.KEY_SOCIAL_ACCOUNT_FACEBOOK_URL, social_account_facebook_url, "Facebook URL"),
|
||||
(sys_config_key.KEY_SOCIAL_ACCOUNT_X_URL, social_account_x_url, "X URL"),
|
||||
(sys_config_key.KEY_TAG_BAR_DISPLAY, tag_bar_display, "Tag bar display"),
|
||||
(sys_config_key.KEY_LOGIN_GOOGLE_CLIENT, login_google_client, "Google login client ID"),
|
||||
(sys_config_key.KEY_LOGIN_GOOGLE_SECRET, login_google_secret, "Google login client secret"),
|
||||
(sys_config_key.KEY_LOGIN_GOOGLE_ENABLE, login_google_enable, "Google login enabled"),
|
||||
@@ -318,6 +323,7 @@ def set_sysconfig(
|
||||
"facebook_image_url": facebook_image_url,
|
||||
"social_account_facebook_url": social_account_facebook_url,
|
||||
"social_account_x_url": social_account_x_url,
|
||||
"tag_bar_display": tag_bar_display,
|
||||
}
|
||||
|
||||
# Use background reporting to avoid blocking the main configuration update
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from fastapi import APIRouter, Depends, Request,Body
|
||||
from fastapi import APIRouter, Depends, Request,Body,Query
|
||||
from sqlalchemy.orm import Session
|
||||
from services.common.database import get_db
|
||||
from services.admin_service.constants.user_task import user_task_ids
|
||||
@@ -10,6 +10,9 @@ from services.admin_service.services.user_wallet_service import UserWalletServic
|
||||
from services.admin_service.services.user_task_service import UserTaskService
|
||||
from services.admin_service.services.auth_service import AuthService
|
||||
from services.admin_service.services.resource_group_service import ResourceGroupService
|
||||
from services.admin_service.services.user_wallet_history_service import UserWalletHistoryService
|
||||
|
||||
from typing import Optional,List
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -27,6 +30,10 @@ def get_user_task_service(db: Session = Depends(get_db)) -> UserTaskService:
|
||||
def get_resource_group_service(db: Session = Depends(get_db)) -> ResourceGroupService:
|
||||
return ResourceGroupService(db)
|
||||
|
||||
def get_order_service(db: Session = Depends(get_db)) -> UserWalletHistoryService:
|
||||
return UserWalletHistoryService(db)
|
||||
|
||||
|
||||
@router.get("/info", response_model=dict)
|
||||
def get_user(request: Request, user_wallet: UserWalletService = Depends(get_user_wallet), user_task: UserTaskService = Depends(get_user_task_service), resource_group_service: ResourceGroupService = Depends(get_resource_group_service)):
|
||||
"""Get current user information and wallet balance."""
|
||||
@@ -87,3 +94,37 @@ def update_password(
|
||||
|
||||
return ResponseUtils.error(message="not found user", code=404)
|
||||
|
||||
@router.get("/order/list", summary="Get order list")
|
||||
def get_order_list(
|
||||
request: Request,
|
||||
page: int = Query(1, description="Current page number"),
|
||||
page_size: int = Query(15, description="Number of items per page"),
|
||||
order_type: Optional[str] = Query(None, description="Order type"),
|
||||
status: Optional[str] = Query(None, description="Order status"),
|
||||
user_wallet_history_service: UserWalletHistoryService = Depends(get_order_service),
|
||||
):
|
||||
"""Get order list."""
|
||||
user = UserUtils.get_request_user(request)
|
||||
if not user:
|
||||
return ResponseUtils.error(message="not found user", code=404)
|
||||
offset = (page - 1) * page_size
|
||||
order_type_list = []
|
||||
if order_type:
|
||||
# 将字符串转成列表,中间使用逗号分隔
|
||||
ots = order_type.split(",")
|
||||
for ot in ots:
|
||||
ot = ot.strip()
|
||||
if ot == "purchase":
|
||||
order_type_list.append("api_call")
|
||||
elif ot == "recharge":
|
||||
order_type_list.append("deposit")
|
||||
else:
|
||||
order_type_list.append(ot)
|
||||
status_list: Optional[List[int]] = []
|
||||
if status:
|
||||
sl = status.split(",")
|
||||
for s in sl:
|
||||
status_list.append(int(s.strip()))
|
||||
total, orders = user_wallet_history_service.success_order_list_by_user(user.id, offset, page_size, order_type_list, status_list)
|
||||
|
||||
return ResponseUtils.success_page(data=orders, total=total, page_num=page, page_size=page_size)
|
||||
@@ -29,6 +29,7 @@ def get_public_mcp_services(
|
||||
keyword: Optional[str] = Query(None, description="Search keyword"),
|
||||
page: Optional[int] = Query(1, description="Page number (starts from 1)"),
|
||||
page_size: Optional[int] = Query(10, description="Page size (default 10)"),
|
||||
tag: Optional[str] = Query(None, description="Filter by tag"),
|
||||
mcp_manager_service: McpManagerService = Depends(get_mcp_manager),
|
||||
):
|
||||
"""Get paginated list of public MCP services with keyword search."""
|
||||
@@ -43,12 +44,19 @@ def get_public_mcp_services(
|
||||
|
||||
# Get service list - let any exception bubble up to middleware
|
||||
service_list, total = mcp_manager_service.get_public_services_paginated(
|
||||
keyword=search_keyword, page=validated_page, page_size=validated_page_size
|
||||
keyword=search_keyword, page=validated_page, page_size=validated_page_size, tag=tag
|
||||
)
|
||||
|
||||
logger.info(f"Successfully retrieved {len(service_list)} services")
|
||||
return ResponseUtils.success_page(data=service_list, page_num=validated_page, page_size=validated_page_size, total=total)
|
||||
|
||||
@router.get("/mcp_tags", summary="Get public MCP tags list")
|
||||
def get_public_mcp_tags(
|
||||
mcp_manager_service: McpManagerService = Depends(get_mcp_manager),
|
||||
):
|
||||
tags = mcp_manager_service.get_tags_list(enabled_only=True)
|
||||
return ResponseUtils.success(data=tags)
|
||||
|
||||
|
||||
@router.get("/mcp_service_info", summary="Get public MCP service information")
|
||||
def get_public_mcp_service_info(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from datetime import datetime, timezone
|
||||
from sqlalchemy import func
|
||||
from sqlalchemy.orm import Session
|
||||
from services.common.models.mcp_service import McpService
|
||||
from typing import Optional, Tuple, List
|
||||
@@ -105,7 +106,7 @@ class McpServiceRepository:
|
||||
self.db.refresh(mcp_service)
|
||||
return mcp_service
|
||||
|
||||
def get_public_services_paginated(self, keyword: str, page: int = 1, page_size: int = 10) -> Tuple[List[McpService], int]:
|
||||
def get_public_services_paginated(self, keyword: str, page: int = 1, page_size: int = 10, tag: Optional[str] = None) -> Tuple[List[McpService], int]:
|
||||
"""Get public service list with pagination, supports keyword search"""
|
||||
offset = (page - 1) * page_size
|
||||
|
||||
@@ -114,9 +115,21 @@ class McpServiceRepository:
|
||||
if keyword:
|
||||
keyword = f"%{keyword}%"
|
||||
query = query.filter((McpService.name.like(keyword)) | (McpService.short_description.like(keyword)))
|
||||
if tag:
|
||||
normalized_tag = tag.strip()
|
||||
if normalized_tag:
|
||||
normalized_tags = func.replace(func.replace(McpService.tags, ", ", ","), " ,", ",")
|
||||
query = query.filter(func.find_in_set(normalized_tag, normalized_tags) > 0)
|
||||
|
||||
|
||||
total = query.count()
|
||||
|
||||
services = query.order_by(McpService.created_at.desc()).offset(offset).limit(page_size).all()
|
||||
|
||||
return services, total
|
||||
|
||||
def get_tags_strings(self, enabled_only: bool = False) -> List[str]:
|
||||
query = self.db.query(McpService.tags).filter(McpService.tags.isnot(None)).filter(McpService.tags != "")
|
||||
if enabled_only:
|
||||
query = query.filter(McpService.enabled == 1)
|
||||
return [row[0] for row in query.all() if row and row[0]]
|
||||
@@ -18,8 +18,20 @@ class UserWalletHistoryRepository:
|
||||
|
||||
def __init__(self, db: Session):
|
||||
self.db = db
|
||||
|
||||
def get_by_id(self, transaction_id: str) -> Optional[UserWalletHistory]:
|
||||
"""
|
||||
Get a user wallet history record by ID.
|
||||
|
||||
def add_deposit(self, user_id: str, amount: float, payment_method: str, transaction_id: str = "", status: int = 0) -> UserWalletHistory:
|
||||
Args:
|
||||
transaction_id: Transaction ID
|
||||
|
||||
Returns:
|
||||
Optional[UserWalletHistory]: Found record or None
|
||||
"""
|
||||
return self.db.query(UserWalletHistory).filter(UserWalletHistory.id == transaction_id).first()
|
||||
|
||||
def add_deposit(self, user_id: str, amount: float, payment_method: str, transaction_id: str = "", status: int = 0, balance_after: float = 0.00) -> UserWalletHistory:
|
||||
"""
|
||||
Create a new deposit record.
|
||||
|
||||
@@ -40,7 +52,7 @@ class UserWalletHistoryRepository:
|
||||
user_id=user_id,
|
||||
payment_method=PaymentMethod(payment_method),
|
||||
amount=amount,
|
||||
balance_after=0.00,
|
||||
balance_after=balance_after,
|
||||
type=TransactionType.DEPOSIT,
|
||||
transaction_id=transaction_id,
|
||||
status=status,
|
||||
@@ -81,7 +93,7 @@ class UserWalletHistoryRepository:
|
||||
self.db.refresh(history)
|
||||
return history
|
||||
|
||||
def set_balance(self,user_id: str,amount:float, payment_method: str, transaction_id: str = "", status: int = 0) -> UserWalletHistory:
|
||||
def set_balance(self,user_id: str,amount:float, payment_method: str, transaction_id: str = "", status: int = 0, balance_after: float = 0.00) -> UserWalletHistory:
|
||||
"""
|
||||
Create a new balance record.
|
||||
|
||||
@@ -102,7 +114,7 @@ class UserWalletHistoryRepository:
|
||||
user_id=user_id,
|
||||
payment_method=PaymentMethod(payment_method),
|
||||
amount=amount,
|
||||
balance_after=0.00,
|
||||
balance_after=balance_after,
|
||||
type=TransactionType.RESET,
|
||||
status=status, # 0=new, 1=completed, 2=refunded
|
||||
created_at=now,
|
||||
@@ -253,8 +265,8 @@ class UserWalletHistoryRepository:
|
||||
.all()
|
||||
)
|
||||
return total, history
|
||||
|
||||
def get_by_id(self, history_id: str) -> Optional[UserWalletHistory]:
|
||||
|
||||
def success_order_list_by_user(self, user_id: str, offset: int, limit: int, order_type: Optional[List[str]] = None, status: Optional[List[int]] = None) -> Tuple[int, List[UserWalletHistory]]:
|
||||
"""
|
||||
Get user wallet history record by ID.
|
||||
|
||||
@@ -264,7 +276,25 @@ class UserWalletHistoryRepository:
|
||||
Returns:
|
||||
Optional[UserWalletHistory]: UserWalletHistory object or None
|
||||
"""
|
||||
return self.db.query(UserWalletHistory).filter(UserWalletHistory.id == history_id).first()
|
||||
|
||||
query = self.db.query(UserWalletHistory).filter(
|
||||
UserWalletHistory.user_id == user_id,
|
||||
)
|
||||
if order_type and len(order_type) > 0:
|
||||
query = query.filter(UserWalletHistory.type.in_(order_type))
|
||||
if status and len(status) > 0:
|
||||
query = query.filter(UserWalletHistory.status.in_(status))
|
||||
total = query.count()
|
||||
if total < offset:
|
||||
return total, []
|
||||
history = (
|
||||
query
|
||||
.order_by(UserWalletHistory.created_at.desc())
|
||||
.offset(offset)
|
||||
.limit(limit)
|
||||
.all()
|
||||
)
|
||||
return total, history
|
||||
|
||||
def add_consume_record(self, wallet_history: UserWalletHistory) -> Optional[UserWalletHistory]:
|
||||
"""
|
||||
|
||||
@@ -329,6 +329,31 @@ class McpManagerService:
|
||||
"""Get service list with pagination"""
|
||||
return self.mcp_service_repository.get_all_paginated(page=page, page_size=page_size,keyword=keyword,filter_status=filter_status)
|
||||
|
||||
def get_tags_list(self, enabled_only: bool = False) -> List[str]:
|
||||
tags_strings = self.mcp_service_repository.get_tags_strings(enabled_only=enabled_only)
|
||||
tag_counts: dict[str, int] = {}
|
||||
canonical: dict[str, str] = {}
|
||||
|
||||
for tags_str in tags_strings:
|
||||
normalized_in_service: set[str] = set()
|
||||
for tag in parse_tags_to_array(tags_str):
|
||||
normalized = tag.casefold()
|
||||
if not normalized:
|
||||
continue
|
||||
if normalized in normalized_in_service:
|
||||
continue
|
||||
normalized_in_service.add(normalized)
|
||||
canonical.setdefault(normalized, tag)
|
||||
|
||||
for normalized in normalized_in_service:
|
||||
tag_counts[normalized] = tag_counts.get(normalized, 0) + 1
|
||||
|
||||
sorted_normalized = sorted(
|
||||
tag_counts.keys(),
|
||||
key=lambda normalized: (-tag_counts[normalized], canonical[normalized].casefold()),
|
||||
)
|
||||
return [canonical[normalized] for normalized in sorted_normalized]
|
||||
|
||||
def create_service_from_openapi(self, openapi_data: OpenApiForAI) -> str:
|
||||
# Convert OpenApiForAI info to McpService object and McpToolApi object list, return service ID or exception.
|
||||
try:
|
||||
@@ -488,9 +513,9 @@ class McpManagerService:
|
||||
logger.error(f"Failed to update service from OpenAPI: {str(e)}")
|
||||
raise ValueError(f"Failed to update service from OpenAPI.")
|
||||
|
||||
def get_public_services_paginated(self, keyword: str, page: int = 1, page_size: int = 10) -> Tuple[List[dict], int]:
|
||||
def get_public_services_paginated(self, keyword: str, page: int = 1, page_size: int = 10, tag: Optional[str] = None) -> Tuple[List[dict], int]:
|
||||
"""Get public services list with pagination, returns formatted data with API info"""
|
||||
services, total = self.mcp_service_repository.get_public_services_paginated(keyword, page, page_size)
|
||||
services, total = self.mcp_service_repository.get_public_services_paginated(keyword, page, page_size, tag)
|
||||
|
||||
service_list = []
|
||||
for service in services:
|
||||
|
||||
@@ -403,11 +403,21 @@ class PaymentService:
|
||||
try:
|
||||
if typ == "incr":
|
||||
self.user_wallet_history_repository.add_deposit(
|
||||
user_id=user_id, amount=amount, payment_method=payment_method, transaction_id=transaction_id,status=1
|
||||
user_id=user_id,
|
||||
amount=amount,
|
||||
payment_method=payment_method,
|
||||
transaction_id=transaction_id,
|
||||
status=1,
|
||||
balance_after=new_balance,
|
||||
)
|
||||
elif typ == "set":
|
||||
self.user_wallet_history_repository.set_balance(
|
||||
user_id=user_id, amount=amount, payment_method=payment_method, transaction_id=transaction_id,status=1
|
||||
user_id=user_id,
|
||||
amount=amount,
|
||||
payment_method=payment_method,
|
||||
transaction_id=transaction_id,
|
||||
status=1,
|
||||
balance_after=new_balance,
|
||||
)
|
||||
self._delete_wallet_cache(user_id)
|
||||
logger.info(f"Successfully updated balance for user_id {user_id}: {current_wallet.balance} -> {new_balance}")
|
||||
|
||||
@@ -45,11 +45,12 @@ class ResourceGroupService:
|
||||
def update_group(self, gid: str, body: dict) -> bool:
|
||||
if not gid:
|
||||
raise ValueError("Group ID is required")
|
||||
existing = self.group_repo.get_by_id(gid)
|
||||
if not existing:
|
||||
raise ValueError("Resource group not found")
|
||||
|
||||
try:
|
||||
if gid != "deny-all" and gid != "allow-all":
|
||||
existing = self.group_repo.get_by_id(gid)
|
||||
if not existing:
|
||||
raise ValueError("Resource group not found")
|
||||
patch = ResourceGroup()
|
||||
patch.id = gid
|
||||
patch.name = body.get("name", existing.name)
|
||||
@@ -68,9 +69,10 @@ class ResourceGroupService:
|
||||
def delete_group(self, gid: str, migrate_id: Optional[str] = None) -> bool:
|
||||
try:
|
||||
if migrate_id:
|
||||
migrate_group = self.group_repo.get_by_id(migrate_id)
|
||||
if not migrate_group:
|
||||
raise ValueError("Migrate resource group not found")
|
||||
if migrate_id != "deny-all" and migrate_id != "allow-all":
|
||||
migrate_group = self.group_repo.get_by_id(migrate_id)
|
||||
if not migrate_group:
|
||||
raise ValueError("Migrate resource group not found")
|
||||
self.map_repo.migrate_services(gid, migrate_id, commit=False)
|
||||
current_default = self.sys_repo.get_value_by_key(KEY_DEFAULT_RESOURCE_GROUP)
|
||||
if current_default == gid:
|
||||
@@ -85,7 +87,9 @@ class ResourceGroupService:
|
||||
raise ValueError("Resource group not found")
|
||||
users = self.user_repo.update_resource_group_by_group_id(gid, migrate_id or "deny-all", commit=False)
|
||||
if not users:
|
||||
raise ValueError("Failed to update user resource group")
|
||||
self.db.commit()
|
||||
return True
|
||||
|
||||
for user in users:
|
||||
cache_key = f"xpack:user:{user.id}"
|
||||
self.redis.set(cache_key, user, 600)
|
||||
@@ -177,10 +181,19 @@ class ResourceGroupService:
|
||||
"enabled": True, # 统一为 bool
|
||||
"is_default": "deny-all" == default_group,
|
||||
}
|
||||
if len(data) < page_size:
|
||||
s_index = (page - 1) * page_size
|
||||
e_index = page * page_size
|
||||
if total > s_index and total < e_index:
|
||||
data.append(allow_all)
|
||||
if len(data) < page_size:
|
||||
if total < e_index-1:
|
||||
data.append(deny_all)
|
||||
elif total < s_index and s_index - total == 1:
|
||||
data.append(deny_all)
|
||||
elif total == s_index:
|
||||
data.append(allow_all)
|
||||
data.append(deny_all)
|
||||
|
||||
|
||||
|
||||
return data,total+2
|
||||
|
||||
@@ -353,7 +366,7 @@ class ResourceGroupService:
|
||||
"created_at": str(s.created_at) if s.created_at else None,
|
||||
"updated_at": str(s.updated_at) if s.updated_at else None,
|
||||
}
|
||||
for s in (service_map[sid] for sid in sids)
|
||||
for s in (service_map[sid] for sid in sids if sid in service_map)
|
||||
],total
|
||||
def get_unbind_services(self, gid: str) -> List[dict]:
|
||||
if gid == "deny-all" or gid == "allow-all":
|
||||
|
||||
Reference in new issue
Block a user