diff --git a/api/core/plugin/entities/bundle.py b/api/core/plugin/entities/bundle.py index 0cf85c0548..83d72d5dfa 100644 --- a/api/core/plugin/entities/bundle.py +++ b/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 diff --git a/api/core/plugin/entities/plugin.py b/api/core/plugin/entities/plugin.py index a374e647c7..d603f37b3d 100644 --- a/api/core/plugin/entities/plugin.py +++ b/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 diff --git a/api/core/plugin/entities/plugin_daemon.py b/api/core/plugin/entities/plugin_daemon.py index 17ce71d01a..db5ee42b83 100644 --- a/api/core/plugin/entities/plugin_daemon.py +++ b/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" diff --git a/api/core/tools/entities/tool_entities.py b/api/core/tools/entities/tool_entities.py index 35afea5f91..7e0e251477 100644 --- a/api/core/tools/entities/tool_entities.py +++ b/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 diff --git a/api/models/account.py b/api/models/account.py index 9eb52573d3..230cac8061 100644 --- a/api/models/account.py +++ b/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"