From 91e70d2f0cc4d5a045d319ec76edc37dde3a7fa2 Mon Sep 17 00:00:00 2001 From: arc53-machine <232052973+arc53-machine@users.noreply.github.com> Date: Tue, 29 Sep 2026 16:37:58 +0100 Subject: [PATCH] Answer 404 when a wiki settings change finds no row to update --- docsgpt/api/user/sources/routes.py | 11 +++++++---- tests/api/user/sources/test_wiki_routes.py | 12 ++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/docsgpt/api/user/sources/routes.py b/docsgpt/api/user/sources/routes.py index e66db1a6..423d621e 100644 --- a/docsgpt/api/user/sources/routes.py +++ b/docsgpt/api/user/sources/routes.py @@ -1091,8 +1091,8 @@ class WikiSettings(Resource): @api.doc( description="Change a wiki's settings (owner only, manage_settings). " - "Body: {\"allow_outside_edits\": bool}: whether runs from the agent's " - "API key, widget or public link may edit the wiki." + "Body: {\"allow_outside_edits\": bool}: whether runs from an agent's " + "API key or widget may edit the wiki." ) def put(self, source_id): decoded_token = request.decoded_token @@ -1118,9 +1118,12 @@ class WikiSettings(Resource): return make_response( jsonify({"success": False, "message": "Source is not a wiki"}), 400 ) - SourcesRepository(conn).set_wiki_outside_edits( + if not SourcesRepository(conn).set_wiki_outside_edits( str(doc["id"]), ra.owner_id, allowed - ) + ): + return make_response( + jsonify({"success": False, "message": "Source not found"}), 404 + ) record_event( conn, "source.wiki_settings_updated", diff --git a/tests/api/user/sources/test_wiki_routes.py b/tests/api/user/sources/test_wiki_routes.py index 62ec960e..3acd8660 100644 --- a/tests/api/user/sources/test_wiki_routes.py +++ b/tests/api/user/sources/test_wiki_routes.py @@ -705,3 +705,15 @@ class TestWikiSettings: ) assert response.status_code == 400 assert self._stored(pg_conn, sid) is False + + def test_no_row_updated_is_404(self, app, pg_conn): + sid = self._wiki(pg_conn, "alice-ws-gone") + with patch( + "docsgpt.storage.db.repositories.sources.SourcesRepository.set_wiki_outside_edits", + return_value=False, + ): + response = _settings_call( + app, pg_conn, sid, "alice-ws-gone", "PUT", {"allow_outside_edits": True} + ) + assert response.status_code == 404 + assert response.json["success"] is False