Skip to content

Commit

Permalink
Fix frontend_base_url / platform_base_url clash
Browse files Browse the repository at this point in the history
  • Loading branch information
majdyz committed Oct 25, 2024
1 parent 2734d83 commit 19b38fb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
31 changes: 14 additions & 17 deletions autogpt_platform/backend/backend/data/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,30 +470,27 @@ async def get_graph(


async def set_graph_active_version(graph_id: str, version: int, user_id: str) -> None:
# Check if the graph belongs to the user
graph = await AgentGraph.prisma().find_first(
# Activate the requested version if it exists and is owned by the user.
updated_count = await AgentGraph.prisma().update_many(
data={"isActive": True},
where={
"id": graph_id,
"version": version,
"userId": user_id,
}
)
if not graph:
raise Exception(f"Graph #{graph_id} v{version} not found or not owned by user")

updated_graph = await AgentGraph.prisma().update(
data={"isActive": True},
where={
"graphVersionId": {"id": graph_id, "version": version},
},
)
if not updated_graph:
raise Exception(f"Graph #{graph_id} v{version} not found")
if updated_count == 0:
raise Exception(f"Graph #{graph_id} v{version} not found or not owned by user")

# Deactivate all other versions
# Deactivate all other versions.
await AgentGraph.prisma().update_many(
data={"isActive": False},
where={"id": graph_id, "version": {"not": version}, "userId": user_id},
where={
"id": graph_id,
"version": {"not": version},
"userId": user_id,
"isActive": True,
},
)


Expand Down Expand Up @@ -580,9 +577,9 @@ async def __create_graph(tx, graph: Graph, user_id: str):
# ------------------------ UTILITIES ------------------------ #


def graph_from_creatable(creatable_graph: Graph, user_id: str) -> GraphModel:
def make_graph_model(creatable_graph: Graph, user_id: str) -> GraphModel:
"""
Convert a CreatableGraph to a Graph, setting graph_id and graph_version on all nodes.
Convert a Graph to a GraphModel, setting graph_id and graph_version on all nodes.
Args:
creatable_graph (Graph): The creatable graph to convert.
Expand Down
4 changes: 2 additions & 2 deletions autogpt_platform/backend/backend/server/rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ async def create_graph(
user_id: str,
) -> graph_db.GraphModel:
if create_graph.graph:
graph = graph_db.graph_from_creatable(create_graph.graph, user_id)
graph = graph_db.make_graph_model(create_graph.graph, user_id)
elif create_graph.template_id:
# Create a new graph from a template
graph = await graph_db.get_graph(
Expand Down Expand Up @@ -500,7 +500,7 @@ async def update_graph(
400, detail="Changing is_template on an existing graph is forbidden"
)
graph.is_active = not graph.is_template
graph = graph_db.graph_from_creatable(graph, user_id)
graph = graph_db.make_graph_model(graph, user_id)
graph.reassign_ids()

new_graph_version = await graph_db.create_graph(graph, user_id=user_id)
Expand Down
2 changes: 1 addition & 1 deletion autogpt_platform/backend/backend/util/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class Config(UpdateTrackingModel["Config"], BaseSettings):
)

frontend_base_url: str = Field(
default="http://localhost:3000",
default="",
description="Can be used to explicitly set the base URL for the frontend. "
"This value is then used to generate redirect URLs for OAuth flows.",
)
Expand Down

0 comments on commit 19b38fb

Please sign in to comment.