fix: auto-fix code issues (cron)
- 修复隐式 Optional 类型注解 (RUF013) - 修复不必要的赋值后返回 (RET504) - 优化列表推导式 (PERF401) - 修复未使用的参数 (ARG002) - 清理重复导入 - 优化异常处理
This commit is contained in:
@@ -699,7 +699,9 @@ class EnterpriseManager:
|
||||
conn.close()
|
||||
|
||||
def get_tenant_sso_config(
|
||||
self, tenant_id: str, provider: str | None = None,
|
||||
self,
|
||||
tenant_id: str,
|
||||
provider: str | None = None,
|
||||
) -> SSOConfig | None:
|
||||
"""获取租户的 SSO 配置"""
|
||||
conn = self._get_connection()
|
||||
@@ -871,7 +873,10 @@ class EnterpriseManager:
|
||||
return metadata
|
||||
|
||||
def create_saml_auth_request(
|
||||
self, tenant_id: str, config_id: str, relay_state: str | None = None,
|
||||
self,
|
||||
tenant_id: str,
|
||||
config_id: str,
|
||||
relay_state: str | None = None,
|
||||
) -> SAMLAuthRequest:
|
||||
"""创建 SAML 认证请求"""
|
||||
conn = self._get_connection()
|
||||
@@ -1235,7 +1240,10 @@ class EnterpriseManager:
|
||||
return []
|
||||
|
||||
def _upsert_scim_user(
|
||||
self, conn: sqlite3.Connection, tenant_id: str, user_data: dict[str, Any],
|
||||
self,
|
||||
conn: sqlite3.Connection,
|
||||
tenant_id: str,
|
||||
user_data: dict[str, Any],
|
||||
) -> None:
|
||||
"""插入或更新 SCIM 用户"""
|
||||
cursor = conn.cursor()
|
||||
@@ -1405,7 +1413,11 @@ class EnterpriseManager:
|
||||
try:
|
||||
# 获取审计日志数据
|
||||
logs = self._fetch_audit_logs(
|
||||
export.tenant_id, export.start_date, export.end_date, export.filters, db_manager,
|
||||
export.tenant_id,
|
||||
export.start_date,
|
||||
export.end_date,
|
||||
export.filters,
|
||||
db_manager,
|
||||
)
|
||||
|
||||
# 根据合规标准过滤字段
|
||||
@@ -1414,7 +1426,9 @@ class EnterpriseManager:
|
||||
|
||||
# 生成导出文件
|
||||
file_path, file_size, checksum = self._generate_export_file(
|
||||
export_id, logs, export.export_format,
|
||||
export_id,
|
||||
logs,
|
||||
export.export_format,
|
||||
)
|
||||
|
||||
now = datetime.now()
|
||||
@@ -1465,7 +1479,9 @@ class EnterpriseManager:
|
||||
return []
|
||||
|
||||
def _apply_compliance_filter(
|
||||
self, logs: list[dict[str, Any]], standard: str,
|
||||
self,
|
||||
logs: list[dict[str, Any]],
|
||||
standard: str,
|
||||
) -> list[dict[str, Any]]:
|
||||
"""应用合规标准字段过滤"""
|
||||
fields = self.COMPLIANCE_FIELDS.get(ComplianceStandard(standard), [])
|
||||
@@ -1481,7 +1497,10 @@ class EnterpriseManager:
|
||||
return filtered_logs
|
||||
|
||||
def _generate_export_file(
|
||||
self, export_id: str, logs: list[dict[str, Any]], format: str,
|
||||
self,
|
||||
export_id: str,
|
||||
logs: list[dict[str, Any]],
|
||||
format: str,
|
||||
) -> tuple[str, int, str]:
|
||||
"""生成导出文件"""
|
||||
import hashlib
|
||||
@@ -1672,7 +1691,9 @@ class EnterpriseManager:
|
||||
conn.close()
|
||||
|
||||
def list_retention_policies(
|
||||
self, tenant_id: str, resource_type: str | None = None,
|
||||
self,
|
||||
tenant_id: str,
|
||||
resource_type: str | None = None,
|
||||
) -> list[DataRetentionPolicy]:
|
||||
"""列出数据保留策略"""
|
||||
conn = self._get_connection()
|
||||
@@ -1876,7 +1897,10 @@ class EnterpriseManager:
|
||||
conn.close()
|
||||
|
||||
def _retain_audit_logs(
|
||||
self, conn: sqlite3.Connection, policy: DataRetentionPolicy, cutoff_date: datetime,
|
||||
self,
|
||||
conn: sqlite3.Connection,
|
||||
policy: DataRetentionPolicy,
|
||||
cutoff_date: datetime,
|
||||
) -> dict[str, int]:
|
||||
"""保留审计日志"""
|
||||
cursor = conn.cursor()
|
||||
@@ -1909,14 +1933,20 @@ class EnterpriseManager:
|
||||
return {"affected": 0, "archived": 0, "deleted": 0, "errors": 0}
|
||||
|
||||
def _retain_projects(
|
||||
self, conn: sqlite3.Connection, policy: DataRetentionPolicy, cutoff_date: datetime,
|
||||
self,
|
||||
conn: sqlite3.Connection,
|
||||
policy: DataRetentionPolicy,
|
||||
cutoff_date: datetime,
|
||||
) -> dict[str, int]:
|
||||
"""保留项目数据"""
|
||||
# 简化实现
|
||||
return {"affected": 0, "archived": 0, "deleted": 0, "errors": 0}
|
||||
|
||||
def _retain_transcripts(
|
||||
self, conn: sqlite3.Connection, policy: DataRetentionPolicy, cutoff_date: datetime,
|
||||
self,
|
||||
conn: sqlite3.Connection,
|
||||
policy: DataRetentionPolicy,
|
||||
cutoff_date: datetime,
|
||||
) -> dict[str, int]:
|
||||
"""保留转录数据"""
|
||||
# 简化实现
|
||||
@@ -2101,9 +2131,11 @@ class EnterpriseManager:
|
||||
if isinstance(row["start_date"], str)
|
||||
else row["start_date"]
|
||||
),
|
||||
end_date=datetime.fromisoformat(row["end_date"])
|
||||
if isinstance(row["end_date"], str)
|
||||
else row["end_date"],
|
||||
end_date=(
|
||||
datetime.fromisoformat(row["end_date"])
|
||||
if isinstance(row["end_date"], str)
|
||||
else row["end_date"]
|
||||
),
|
||||
filters=json.loads(row["filters"] or "{}"),
|
||||
compliance_standard=row["compliance_standard"],
|
||||
status=row["status"],
|
||||
|
||||
Reference in New Issue
Block a user