Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f592178d83 | ||
|
|
1ebac24a3b | ||
|
|
875a7bf906 | ||
|
|
bf79191194 | ||
|
|
24ee3078d8 | ||
|
|
302277bad2 | ||
|
|
6724801d60 | ||
|
|
aa2fd609c6 | ||
|
|
6b758c3acd | ||
|
|
d55cc3e216 | ||
|
|
60c9698cdd | ||
|
|
c16bab66ee | ||
|
|
060bcf7f73 |
No files matched your search
@@ -5,6 +5,7 @@ interface AddServerModalProps {
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
name: string;
|
||||
id: string;
|
||||
onSaveServer: (name: string, isDefault: boolean) => Promise<void>;
|
||||
type: "add" | "edit";
|
||||
isDefault: boolean;
|
||||
@@ -13,6 +14,7 @@ export const AddServerModal: React.FC<AddServerModalProps> = ({
|
||||
isOpen,
|
||||
onClose,
|
||||
name,
|
||||
id,
|
||||
onSaveServer,
|
||||
type,
|
||||
isDefault,
|
||||
@@ -49,12 +51,17 @@ export const AddServerModal: React.FC<AddServerModalProps> = ({
|
||||
{type === "add" ? t("Create New Resource Group") : t("Edit Resource Group")}
|
||||
</ModalHeader>
|
||||
<ModalBody>
|
||||
<Input
|
||||
label={t("Resource Group Name")}
|
||||
value={serverName}
|
||||
placeholder={t("Edit Resource Group Name")}
|
||||
onChange={(e) => setServerName(e.target.value)}
|
||||
/>
|
||||
{
|
||||
!['allow-all', 'deny-all'].includes(id) && <>
|
||||
<Input
|
||||
label={t("Resource Group Name")}
|
||||
value={serverName}
|
||||
placeholder={t("Edit Resource Group Name")}
|
||||
onChange={(e) => setServerName(e.target.value)}
|
||||
maxLength={255}
|
||||
/>
|
||||
</>
|
||||
}
|
||||
<div className="flex items-center justify-between p-4 bg-gray-50 rounded-lg">
|
||||
<div className="flex flex-col gap-1">
|
||||
<span className="text-sm font-medium">
|
||||
@@ -73,9 +80,9 @@ export const AddServerModal: React.FC<AddServerModalProps> = ({
|
||||
</div>
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<Button
|
||||
color="danger"
|
||||
variant="light"
|
||||
<Button
|
||||
color="danger"
|
||||
variant="light"
|
||||
onPress={onClose}
|
||||
isDisabled={isLoading}
|
||||
>
|
||||
|
||||
@@ -106,7 +106,7 @@ const GroupServiceTable: React.FC<GroupServiceTableProps> = ({
|
||||
{resourceGroupDetail?.name}
|
||||
</h2>
|
||||
<div className="flex gap-2 h-[32px]">
|
||||
{showOptions && currentGroupId && <>
|
||||
{currentGroupId && <>
|
||||
<Button
|
||||
isIconOnly
|
||||
size="sm"
|
||||
@@ -114,7 +114,9 @@ const GroupServiceTable: React.FC<GroupServiceTableProps> = ({
|
||||
onPress={() => onEditGroup(currentGroupId)}
|
||||
>
|
||||
<Edit2 size={18} />
|
||||
</Button>
|
||||
</Button></>
|
||||
}
|
||||
{showOptions && currentGroupId && <>
|
||||
<Button
|
||||
isIconOnly
|
||||
size="sm"
|
||||
|
||||
@@ -330,6 +330,7 @@ const ResourceGroupManagement: React.FC = () => {
|
||||
setEditingGroup(null);
|
||||
}}
|
||||
name={editingGroup?.name || ""}
|
||||
id={editingGroup?.id || ""}
|
||||
isDefault={editingGroup?.isDefault || false}
|
||||
onSaveServer={handleSaveGroup}
|
||||
type={editingGroup ? "edit" : "add"}
|
||||
|
||||
@@ -78,7 +78,7 @@ def account_login(body: dict = Body(...), auth_service: AuthService = Depends(ge
|
||||
if token:
|
||||
return ResponseUtils.success({"user_token": token})
|
||||
else:
|
||||
return ResponseUtils.error(message="login failed", code=401)
|
||||
return ResponseUtils.error(message="login failed, please enter the correct account or password", code=401)
|
||||
|
||||
|
||||
@router.post("/google/sign", response_model=dict)
|
||||
@@ -95,7 +95,7 @@ def google_login(request: Request, body: dict = Body(...), auth_service: AuthSer
|
||||
if token:
|
||||
return ResponseUtils.success({"user_token": token})
|
||||
else:
|
||||
return ResponseUtils.error(message=f"login failed: {redirect_uri}", code=401)
|
||||
return ResponseUtils.error(message=f"login failed, please check the redirect_uri: {redirect_uri}", code=401)
|
||||
|
||||
|
||||
@router.delete("/logout", response_model=dict)
|
||||
|
||||
@@ -244,5 +244,5 @@ class AuthService:
|
||||
return token
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Google login failed: {e}")
|
||||
logger.error(f"Google login failed, error: {e}")
|
||||
return None
|
||||
@@ -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":
|
||||
|
||||
@@ -293,40 +293,42 @@ class HttpRequestBuilder:
|
||||
"""
|
||||
if not hasattr(tool_config, 'request_body_schema') or not tool_config.request_body_schema or tool_config.method.value not in ["POST", "PUT", "PATCH"]:
|
||||
return None
|
||||
|
||||
try:
|
||||
# First try to parse as parameters list (similar to query/path parameters)
|
||||
request_body = {}
|
||||
body_params = self._safe_parse_params(tool_config.request_body_schema, 'body')
|
||||
if body_params:
|
||||
# If it's a list of parameters, process them like query parameters
|
||||
request_body = {}
|
||||
for param in body_params:
|
||||
if isinstance(param, dict) and "name" in param:
|
||||
param_name = param["name"]
|
||||
if param_name in arguments:
|
||||
request_body[param_name] = arguments[param_name]
|
||||
|
||||
if isinstance(param, dict):
|
||||
name = param.get("name")
|
||||
if name and name in arguments:
|
||||
request_body[name] = arguments[name]
|
||||
else:
|
||||
t = param.get("type")
|
||||
if t == "object":
|
||||
props = param.get("properties")
|
||||
if isinstance(props, dict):
|
||||
for prop_name in props.keys():
|
||||
if prop_name in arguments:
|
||||
request_body[prop_name] = arguments[prop_name]
|
||||
if request_body:
|
||||
# logger.debug(f"Built request body from parameters: {request_body}")
|
||||
return request_body
|
||||
else:
|
||||
# If not a parameters list, try to parse as JSON schema object
|
||||
try:
|
||||
body_schema = json.loads(tool_config.request_body_schema)
|
||||
logger.debug(f"Request body schema: {body_schema}")
|
||||
|
||||
if isinstance(body_schema, dict) and "properties" in body_schema:
|
||||
request_body = {}
|
||||
for prop_name in body_schema["properties"]:
|
||||
try:
|
||||
body_schema = json.loads(tool_config.request_body_schema)
|
||||
if isinstance(body_schema, dict):
|
||||
props = body_schema.get("properties")
|
||||
if isinstance(props, dict):
|
||||
for prop_name in props.keys():
|
||||
if prop_name in arguments:
|
||||
request_body[prop_name] = arguments[prop_name]
|
||||
|
||||
if request_body:
|
||||
# logger.debug(f"Built request body from schema: {request_body}")
|
||||
return request_body
|
||||
except json.JSONDecodeError:
|
||||
logger.warning(f"Failed to parse request body schema as JSON")
|
||||
|
||||
else:
|
||||
for key in body_schema.keys():
|
||||
if key in arguments:
|
||||
request_body[key] = arguments[key]
|
||||
if request_body:
|
||||
return request_body
|
||||
except json.JSONDecodeError:
|
||||
logger.warning(f"Failed to parse request body schema as JSON")
|
||||
|
||||
except Exception as e:
|
||||
logger.warning(f"Request body schema parsing failed: {e}")
|
||||
|
||||
|
||||
@@ -125,6 +125,8 @@ class CacheUtils:
|
||||
else:
|
||||
logger.warning(f"Unexpected cache value type for key {cache_key}: {type(cache_value)}")
|
||||
return None
|
||||
if isinstance(model_data,list):
|
||||
return model_data
|
||||
return SqlalchemyUtils.dict_to_model(model_class, model_data)
|
||||
return None
|
||||
except Exception as e:
|
||||
@@ -145,7 +147,10 @@ class CacheUtils:
|
||||
bool: True if successful, False otherwise
|
||||
"""
|
||||
try:
|
||||
model_dict = SqlalchemyUtils.model_to_dict(model)
|
||||
if isinstance(model, list):
|
||||
return CacheUtils.set_sqlalchemy_list_cache(cache_key, model, expire_time)
|
||||
else:
|
||||
model_dict = SqlalchemyUtils.model_to_dict(model)
|
||||
serialized_data = json.dumps(model_dict, ensure_ascii=False)
|
||||
redis_client.set(cache_key, serialized_data, ex=expire_time)
|
||||
return True
|
||||
@@ -203,11 +208,15 @@ class CacheUtils:
|
||||
if not isinstance(model_list, list):
|
||||
logger.error(f"Expected list for cache key {cache_key}, got {type(model_list)}")
|
||||
return False
|
||||
|
||||
model_dict_list = [SqlalchemyUtils.model_to_dict(model) for model in model_list]
|
||||
serialized_data = json.dumps(model_dict_list, ensure_ascii=False)
|
||||
data = []
|
||||
for model in model_list:
|
||||
if isinstance(model,dict):
|
||||
data.append(SqlalchemyUtils.model_to_dict(model))
|
||||
else:
|
||||
data.append(model)
|
||||
serialized_data = json.dumps(data, ensure_ascii=False)
|
||||
redis_client.set(cache_key, serialized_data, ex=expire_time)
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to set SQLAlchemy list cache for key {cache_key}: {e}")
|
||||
logger.error(f"Failed to set SQLAlchemy list cache for key aaa {cache_key}: {e}")
|
||||
return False
|
||||
Reference in new issue
Block a user