mirror of
https://github.com/langgenius/dify.git
synced 2026-04-27 11:06:46 +08:00
add resolve comment
This commit is contained in:
parent
9067c2a9c1
commit
e421db4005
@ -84,16 +84,6 @@ workflow_comment_resolve_fields = {
|
|||||||
"resolved": fields.Boolean,
|
"resolved": fields.Boolean,
|
||||||
"resolved_at": TimestampField,
|
"resolved_at": TimestampField,
|
||||||
"resolved_by": fields.String,
|
"resolved_by": fields.String,
|
||||||
"resolved_by_account": fields.Nested(comment_account_fields, allow_null=True),
|
|
||||||
}
|
|
||||||
|
|
||||||
# Comment pagination fields
|
|
||||||
workflow_comment_pagination_fields = {
|
|
||||||
"data": fields.List(fields.Nested(workflow_comment_basic_fields), attribute="data"),
|
|
||||||
"has_more": fields.Boolean,
|
|
||||||
"total": fields.Integer,
|
|
||||||
"page": fields.Integer,
|
|
||||||
"limit": fields.Integer,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Reply creation response fields (simplified)
|
# Reply creation response fields (simplified)
|
||||||
|
|||||||
@ -6,6 +6,7 @@ from sqlalchemy.orm import Session, selectinload
|
|||||||
from werkzeug.exceptions import Forbidden, NotFound
|
from werkzeug.exceptions import Forbidden, NotFound
|
||||||
|
|
||||||
from extensions.ext_database import db
|
from extensions.ext_database import db
|
||||||
|
from libs.datetime_utils import naive_utc_now
|
||||||
from libs.helper import uuid_value
|
from libs.helper import uuid_value
|
||||||
from models import WorkflowComment, WorkflowCommentMention, WorkflowCommentReply
|
from models import WorkflowComment, WorkflowCommentMention, WorkflowCommentReply
|
||||||
|
|
||||||
@ -31,9 +32,9 @@ class WorkflowCommentService:
|
|||||||
return comments
|
return comments
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_comment(tenant_id: str, app_id: str, comment_id: str) -> WorkflowComment:
|
def get_comment(tenant_id: str, app_id: str, comment_id: str, session: Session = None) -> WorkflowComment:
|
||||||
"""Get a specific comment."""
|
"""Get a specific comment."""
|
||||||
with Session(db.engine) as session:
|
def _get_comment(session: Session) -> WorkflowComment:
|
||||||
stmt = (
|
stmt = (
|
||||||
select(WorkflowComment)
|
select(WorkflowComment)
|
||||||
.options(selectinload(WorkflowComment.replies), selectinload(WorkflowComment.mentions))
|
.options(selectinload(WorkflowComment.replies), selectinload(WorkflowComment.mentions))
|
||||||
@ -45,10 +46,16 @@ class WorkflowCommentService:
|
|||||||
)
|
)
|
||||||
comment = session.scalar(stmt)
|
comment = session.scalar(stmt)
|
||||||
|
|
||||||
if not comment:
|
if not comment:
|
||||||
raise NotFound("Comment not found")
|
raise NotFound("Comment not found")
|
||||||
|
|
||||||
return comment
|
return comment
|
||||||
|
|
||||||
|
if session is not None:
|
||||||
|
return _get_comment(session)
|
||||||
|
else:
|
||||||
|
with Session(db.engine, expire_on_commit=False) as session:
|
||||||
|
return _get_comment(session)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create_comment(
|
def create_comment(
|
||||||
@ -182,31 +189,16 @@ class WorkflowCommentService:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def resolve_comment(tenant_id: str, app_id: str, comment_id: str, user_id: str) -> WorkflowComment:
|
def resolve_comment(tenant_id: str, app_id: str, comment_id: str, user_id: str) -> WorkflowComment:
|
||||||
"""Resolve a workflow comment."""
|
"""Resolve a workflow comment."""
|
||||||
comment = WorkflowCommentService.get_comment(tenant_id, app_id, comment_id)
|
with Session(db.engine, expire_on_commit=False) as session:
|
||||||
|
comment = WorkflowCommentService.get_comment(tenant_id, app_id, comment_id, session)
|
||||||
|
if comment.resolved:
|
||||||
|
return comment
|
||||||
|
|
||||||
if comment.resolved:
|
comment.resolved = True
|
||||||
return comment
|
comment.resolved_at = naive_utc_now()
|
||||||
|
comment.resolved_by = user_id
|
||||||
comment.resolved = True
|
session.commit()
|
||||||
comment.resolved_at = db.func.current_timestamp()
|
|
||||||
comment.resolved_by = user_id
|
|
||||||
|
|
||||||
db.session.commit()
|
|
||||||
return comment
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def reopen_comment(tenant_id: str, app_id: str, comment_id: str, user_id: str) -> WorkflowComment:
|
|
||||||
"""Reopen a resolved workflow comment."""
|
|
||||||
comment = WorkflowCommentService.get_comment(tenant_id, app_id, comment_id)
|
|
||||||
|
|
||||||
if not comment.resolved:
|
|
||||||
return comment
|
|
||||||
|
|
||||||
comment.resolved = False
|
|
||||||
comment.resolved_at = None
|
|
||||||
comment.resolved_by = None
|
|
||||||
|
|
||||||
db.session.commit()
|
|
||||||
return comment
|
return comment
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user