fix: riff

This commit is contained in:
Yeuoly 2024-11-25 16:44:08 +08:00
parent 5ff9cee326
commit 49bd1a7a49
No known key found for this signature in database
GPG Key ID: A66E7E320FB19F61
5 changed files with 31 additions and 17 deletions

View File

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

View File

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

View File

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

View File

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

View File

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