Skip to content
This repository was archived by the owner on Mar 26, 2025. It is now read-only.

Commit c11d4c9

Browse files
authored
Merge pull request #633 from openchatai/fix/copilots
Delete flow permissions
2 parents bfc16f9 + 16bd2a8 commit c11d4c9

File tree

4 files changed

+55
-6
lines changed

4 files changed

+55
-6
lines changed

llm-server/models/repository/flow_repo.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,20 @@ def add_or_update_variable_in_flow(
157157
session.add(variable)
158158
session.commit()
159159
return variable
160+
161+
162+
def delete_flow(flow_id: str) -> bool:
163+
"""
164+
Deletes a flow record from the database.
165+
Args:
166+
flow_id: The ID of the flow to delete.
167+
Returns:
168+
True if the flow was deleted, False otherwise.
169+
"""
170+
with Session() as session:
171+
flow = session.query(Flow).filter(Flow.id == flow_id).first()
172+
if flow:
173+
session.delete(flow)
174+
session.commit()
175+
return True
176+
return False

llm-server/routes/copilot/copilot_controller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def delete_bot(copilot_id):
9090
# Find the bot
9191
bot = find_or_fail_by_bot_id(copilot_id)
9292

93-
# Delete the bot using the session
93+
# This should be soft delete but for now, we are doing hard delete
9494
session.delete(bot)
9595
session.commit()
9696
return jsonify({"success": "chatbot_deleted"}), 200

llm-server/routes/flow/flow_controller.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
get_variables_for_flow,
1212
add_or_update_variable_in_flow,
1313
update_flow,
14+
delete_flow as delete_flow_from_db,
1415
)
1516
from presenters.flow_presenters import flow_to_dict, flow_variable_to_dict
1617
from routes.flow import flow_vector_service
1718
from routes.flow.utils.dynamic_flow_builder import build_dynamic_flow
1819
from utils.get_logger import CustomLogger
20+
from routes.flow.flow_vector_service import delete_flow as delete_flow_from_vector_store
1921

2022
logger = CustomLogger("flow")
2123
flow = Blueprint("flow", __name__)
@@ -249,3 +251,31 @@ def add_variables_to_flow_api(flow_id: str):
249251
),
250252
500,
251253
)
254+
255+
256+
@flow.route("/<flow_id>", methods=["DELETE"])
257+
def delete_flow_api(flow_id: str):
258+
try:
259+
# Attempt to delete the flow from the database
260+
if delete_flow_from_db(flow_id):
261+
# Attempt to delete the flow from the vector store
262+
point_id = flow_vector_service.get_flow_point_id_by_flow_id(flow_id)
263+
if point_id:
264+
delete_flow_from_vector_store(point_id)
265+
return (
266+
jsonify({"success": True, "message": "Flow deleted successfully."}),
267+
200,
268+
)
269+
else:
270+
return (
271+
jsonify({"success": False, "message": "Flow vector not found."}),
272+
404,
273+
)
274+
else:
275+
return (
276+
jsonify({"success": False, "message": "Flow not found in database."}),
277+
404,
278+
)
279+
except Exception as e:
280+
logger.error("Failed to delete flow", payload=e)
281+
return jsonify({"error": "Failed to delete flow."}), 500

llm-server/routes/flow/flow_vector_service.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,13 @@ def create_flow(flow: FlowDTO):
4747
documents: List[Document] = []
4848

4949
document = Document(page_content=flow.description + " " + flow.name)
50-
document.metadata.update({
51-
"bot_id": str(flow.bot_id),
52-
"flow_id": str(flow.id),
53-
"operation_id": flow.operation_id
54-
})
50+
document.metadata.update(
51+
{
52+
"bot_id": str(flow.bot_id),
53+
"flow_id": str(flow.id),
54+
"operation_id": flow.operation_id,
55+
}
56+
)
5557

5658
documents.append(document)
5759

0 commit comments

Comments
 (0)