Yeuoly 8 ヶ月 前
コミット
49bd1a7a49

+ 2 - 2
api/core/plugin/entities/bundle.py

@@ -1,4 +1,4 @@
-from enum import Enum
+from enum import StrEnum
 
 from pydantic import BaseModel
 
@@ -6,7 +6,7 @@ from core.plugin.entities.plugin import PluginDeclaration, PluginInstallationSou
 
 
 class PluginBundleDependency(BaseModel):
-    class Type(str, Enum):
+    class Type(StrEnum):
         Github = PluginInstallationSource.Github.value
         Marketplace = PluginInstallationSource.Marketplace.value
         Package = PluginInstallationSource.Package.value

+ 4 - 4
api/core/plugin/entities/plugin.py

@@ -1,7 +1,7 @@
 import datetime
+import enum
 import re
 from collections.abc import Mapping
-from enum import Enum
 from typing import Any, Optional
 
 from pydantic import BaseModel, Field, model_validator
@@ -13,7 +13,7 @@ from core.tools.entities.common_entities import I18nObject
 from core.tools.entities.tool_entities import ToolProviderEntity
 
 
-class PluginInstallationSource(str, Enum):
+class PluginInstallationSource(enum.StrEnum):
     Github = "github"
     Marketplace = "marketplace"
     Package = "package"
@@ -55,7 +55,7 @@ class PluginResourceRequirements(BaseModel):
     permission: Optional[Permission]
 
 
-class PluginCategory(str, Enum):
+class PluginCategory(enum.StrEnum):
     Tool = "tool"
     Model = "model"
     Extension = "extension"
@@ -163,7 +163,7 @@ class GenericProviderID:
 
 
 class PluginDependency(BaseModel):
-    class Type(str, Enum):
+    class Type(enum.StrEnum):
         Github = PluginInstallationSource.Github.value
         Marketplace = PluginInstallationSource.Marketplace.value
         Package = PluginInstallationSource.Package.value

+ 2 - 1
api/core/plugin/entities/plugin_daemon.py

@@ -1,3 +1,4 @@
+import enum
 from datetime import datetime
 from enum import Enum
 from typing import Generic, Optional, TypeVar
@@ -119,7 +120,7 @@ class PluginDaemonInnerError(Exception):
         self.message = message
 
 
-class PluginInstallTaskStatus(str, Enum):
+class PluginInstallTaskStatus(enum.StrEnum):
     Pending = "pending"
     Running = "running"
     Success = "success"

+ 3 - 2
api/core/tools/entities/tool_entities.py

@@ -1,4 +1,5 @@
 import base64
+import enum
 from enum import Enum
 from typing import Any, Optional, Union
 
@@ -33,7 +34,7 @@ class ToolLabelEnum(Enum):
     OTHER = "other"
 
 
-class ToolProviderType(str, Enum):
+class ToolProviderType(enum.StrEnum):
     """
     Enum class for tool provider
     """
@@ -205,7 +206,7 @@ class ToolParameterOption(BaseModel):
 
 
 class ToolParameter(BaseModel):
-    class ToolParameterType(str, Enum):
+    class ToolParameterType(enum.StrEnum):
         STRING = CommonParameterType.STRING.value
         NUMBER = CommonParameterType.NUMBER.value
         BOOLEAN = CommonParameterType.BOOLEAN.value

+ 20 - 8
api/models/account.py

@@ -142,7 +142,9 @@ class TenantAccountRole(enum.StrEnum):
 
     @staticmethod
     def is_valid_role(role: str) -> bool:
-        return role and role in {
+        if not role:
+            return False
+        return role in {
             TenantAccountRole.OWNER,
             TenantAccountRole.ADMIN,
             TenantAccountRole.EDITOR,
@@ -152,15 +154,21 @@ class TenantAccountRole(enum.StrEnum):
 
     @staticmethod
     def is_privileged_role(role: str) -> bool:
-        return role and role in {TenantAccountRole.OWNER, TenantAccountRole.ADMIN}
+        if not role:
+            return False
+        return role in {TenantAccountRole.OWNER, TenantAccountRole.ADMIN}
 
     @staticmethod
     def is_admin_role(role: str) -> bool:
-        return role and role == TenantAccountRole.ADMIN
+        if not role:
+            return False
+        return role == TenantAccountRole.ADMIN
 
     @staticmethod
     def is_non_owner_role(role: str) -> bool:
-        return role and role in {
+        if not role:
+            return False
+        return role in {
             TenantAccountRole.ADMIN,
             TenantAccountRole.EDITOR,
             TenantAccountRole.NORMAL,
@@ -169,11 +177,15 @@ class TenantAccountRole(enum.StrEnum):
 
     @staticmethod
     def is_editing_role(role: str) -> bool:
-        return role and role in {TenantAccountRole.OWNER, TenantAccountRole.ADMIN, TenantAccountRole.EDITOR}
+        if not role:
+            return False
+        return role in {TenantAccountRole.OWNER, TenantAccountRole.ADMIN, TenantAccountRole.EDITOR}
 
     @staticmethod
     def is_dataset_edit_role(role: str) -> bool:
-        return role and role in {
+        if not role:
+            return False
+        return role in {
             TenantAccountRole.OWNER,
             TenantAccountRole.ADMIN,
             TenantAccountRole.EDITOR,
@@ -273,12 +285,12 @@ class InvitationCode(db.Model):
 
 
 class TenantPluginPermission(Base):
-    class InstallPermission(str, enum.Enum):
+    class InstallPermission(enum.StrEnum):
         EVERYONE = "everyone"
         ADMINS = "admins"
         NOBODY = "noone"
 
-    class DebugPermission(str, enum.Enum):
+    class DebugPermission(enum.StrEnum):
         EVERYONE = "everyone"
         ADMINS = "admins"
         NOBODY = "noone"