mirror of
https://github.com/langgenius/dify.git
synced 2026-05-05 09:58:04 +08:00
Merge branch 'main' into fix/chore-fix
This commit is contained in:
@ -10,7 +10,7 @@ from models.base import Base
|
||||
from .types import StringUUID
|
||||
|
||||
|
||||
class AccountStatus(str, enum.Enum):
|
||||
class AccountStatus(enum.StrEnum):
|
||||
PENDING = "pending"
|
||||
UNINITIALIZED = "uninitialized"
|
||||
ACTIVE = "active"
|
||||
@ -111,6 +111,10 @@ class Account(UserMixin, Base):
|
||||
def is_admin_or_owner(self):
|
||||
return TenantAccountRole.is_privileged_role(self._current_tenant.current_role)
|
||||
|
||||
@property
|
||||
def is_admin(self):
|
||||
return TenantAccountRole.is_admin_role(self._current_tenant.current_role)
|
||||
|
||||
@property
|
||||
def is_editor(self):
|
||||
return TenantAccountRole.is_editing_role(self._current_tenant.current_role)
|
||||
@ -124,12 +128,12 @@ class Account(UserMixin, Base):
|
||||
return self._current_tenant.current_role == TenantAccountRole.DATASET_OPERATOR
|
||||
|
||||
|
||||
class TenantStatus(str, enum.Enum):
|
||||
class TenantStatus(enum.StrEnum):
|
||||
NORMAL = "normal"
|
||||
ARCHIVE = "archive"
|
||||
|
||||
|
||||
class TenantAccountRole(str, enum.Enum):
|
||||
class TenantAccountRole(enum.StrEnum):
|
||||
OWNER = "owner"
|
||||
ADMIN = "admin"
|
||||
EDITOR = "editor"
|
||||
@ -150,6 +154,10 @@ class TenantAccountRole(str, enum.Enum):
|
||||
def is_privileged_role(role: str) -> bool:
|
||||
return role and role in {TenantAccountRole.OWNER, TenantAccountRole.ADMIN}
|
||||
|
||||
@staticmethod
|
||||
def is_admin_role(role: str) -> bool:
|
||||
return role and role == TenantAccountRole.ADMIN
|
||||
|
||||
@staticmethod
|
||||
def is_non_owner_role(role: str) -> bool:
|
||||
return role and role in {
|
||||
|
||||
@ -23,7 +23,7 @@ from .model import App, Tag, TagBinding, UploadFile
|
||||
from .types import StringUUID
|
||||
|
||||
|
||||
class DatasetPermissionEnum(str, enum.Enum):
|
||||
class DatasetPermissionEnum(enum.StrEnum):
|
||||
ONLY_ME = "only_me"
|
||||
ALL_TEAM = "all_team_members"
|
||||
PARTIAL_TEAM = "partial_members"
|
||||
|
||||
@ -1,16 +1,16 @@
|
||||
from enum import Enum
|
||||
from enum import StrEnum
|
||||
|
||||
|
||||
class CreatedByRole(str, Enum):
|
||||
class CreatedByRole(StrEnum):
|
||||
ACCOUNT = "account"
|
||||
END_USER = "end_user"
|
||||
|
||||
|
||||
class UserFrom(str, Enum):
|
||||
class UserFrom(StrEnum):
|
||||
ACCOUNT = "account"
|
||||
END_USER = "end-user"
|
||||
|
||||
|
||||
class WorkflowRunTriggeredFrom(str, Enum):
|
||||
class WorkflowRunTriggeredFrom(StrEnum):
|
||||
DEBUGGING = "debugging"
|
||||
APP_RUN = "app-run"
|
||||
|
||||
@ -9,6 +9,7 @@ from typing import TYPE_CHECKING, Optional
|
||||
if TYPE_CHECKING:
|
||||
from models.workflow import Workflow
|
||||
|
||||
from enum import StrEnum
|
||||
from typing import Any, Literal
|
||||
|
||||
import sqlalchemy as sa
|
||||
@ -38,7 +39,7 @@ class DifySetup(Base):
|
||||
setup_at = db.Column(db.DateTime, nullable=False, server_default=db.text("CURRENT_TIMESTAMP(0)"))
|
||||
|
||||
|
||||
class AppMode(str, Enum):
|
||||
class AppMode(StrEnum):
|
||||
COMPLETION = "completion"
|
||||
WORKFLOW = "workflow"
|
||||
CHAT = "chat"
|
||||
@ -74,7 +75,7 @@ class App(Base):
|
||||
name = db.Column(db.String(255), nullable=False)
|
||||
description = db.Column(db.Text, nullable=False, server_default=db.text("''::character varying"))
|
||||
mode = db.Column(db.String(255), nullable=False)
|
||||
icon_type = db.Column(db.String(255), nullable=True)
|
||||
icon_type = db.Column(db.String(255), nullable=True) # image, emoji
|
||||
icon = db.Column(db.String(255))
|
||||
icon_background = db.Column(db.String(255))
|
||||
app_model_config_id = db.Column(StringUUID, nullable=True)
|
||||
@ -261,8 +262,8 @@ class AppModelConfig(Base):
|
||||
return app
|
||||
|
||||
@property
|
||||
def model_dict(self):
|
||||
return json.loads(self.model) if self.model else None
|
||||
def model_dict(self) -> dict:
|
||||
return json.loads(self.model) if self.model else {}
|
||||
|
||||
@property
|
||||
def suggested_questions_list(self) -> list:
|
||||
@ -610,11 +611,8 @@ class Conversation(Base):
|
||||
app_model_config = (
|
||||
db.session.query(AppModelConfig).filter(AppModelConfig.id == self.app_model_config_id).first()
|
||||
)
|
||||
|
||||
if not app_model_config:
|
||||
return {}
|
||||
|
||||
model_config = app_model_config.to_dict()
|
||||
if app_model_config:
|
||||
model_config = app_model_config.to_dict()
|
||||
|
||||
model_config["model_id"] = self.model_id
|
||||
model_config["provider"] = self.model_provider
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
from datetime import datetime, timezone
|
||||
from datetime import UTC, datetime
|
||||
|
||||
from celery import states
|
||||
|
||||
@ -17,8 +17,8 @@ class CeleryTask(Base):
|
||||
result = db.Column(db.PickleType, nullable=True)
|
||||
date_done = db.Column(
|
||||
db.DateTime,
|
||||
default=lambda: datetime.now(timezone.utc).replace(tzinfo=None),
|
||||
onupdate=lambda: datetime.now(timezone.utc).replace(tzinfo=None),
|
||||
default=lambda: datetime.now(UTC).replace(tzinfo=None),
|
||||
onupdate=lambda: datetime.now(UTC).replace(tzinfo=None),
|
||||
nullable=True,
|
||||
)
|
||||
traceback = db.Column(db.Text, nullable=True)
|
||||
@ -38,4 +38,4 @@ class CeleryTaskSet(Base):
|
||||
id = db.Column(db.Integer, db.Sequence("taskset_id_sequence"), autoincrement=True, primary_key=True)
|
||||
taskset_id = db.Column(db.String(155), unique=True)
|
||||
result = db.Column(db.PickleType, nullable=True)
|
||||
date_done = db.Column(db.DateTime, default=lambda: datetime.now(timezone.utc).replace(tzinfo=None), nullable=True)
|
||||
date_done = db.Column(db.DateTime, default=lambda: datetime.now(UTC).replace(tzinfo=None), nullable=True)
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import json
|
||||
from collections.abc import Mapping, Sequence
|
||||
from datetime import datetime, timezone
|
||||
from datetime import UTC, datetime
|
||||
from enum import Enum
|
||||
from typing import TYPE_CHECKING, Any, Optional, Union
|
||||
|
||||
@ -112,7 +112,7 @@ class Workflow(Base):
|
||||
)
|
||||
updated_by: Mapped[Optional[str]] = mapped_column(StringUUID)
|
||||
updated_at: Mapped[datetime] = mapped_column(
|
||||
sa.DateTime, nullable=False, default=datetime.now(tz=timezone.utc), server_onupdate=func.current_timestamp()
|
||||
sa.DateTime, nullable=False, default=datetime.now(tz=UTC), server_onupdate=func.current_timestamp()
|
||||
)
|
||||
_environment_variables: Mapped[str] = mapped_column(
|
||||
"environment_variables", db.Text, nullable=False, server_default="{}"
|
||||
|
||||
Reference in New Issue
Block a user