Local API: Return 404 for unknown group library

This commit is contained in:
Dan Stillman 2024-06-19 00:28:59 -04:00
parent ecfc217ce9
commit fad3e25278
2 changed files with 25 additions and 4 deletions

View file

@ -112,10 +112,18 @@ class LocalAPIEndpoint {
}
return this.makeResponse(400, 'text/plain', 'Only data for the logged-in user is available locally -- use userID 0' + suffix);
}
requestData.libraryID = requestData.pathParams.groupID
? Zotero.Groups.getLibraryIDFromGroupID(parseInt(requestData.pathParams.groupID))
: Zotero.Libraries.userLibraryID;
if (requestData.pathParams.groupID) {
let groupID = requestData.pathParams.groupID;
let libraryID = Zotero.Groups.getLibraryIDFromGroupID(parseInt(groupID));
if (!libraryID) {
return this.makeResponse(404, 'text/plain', 'Not found');
}
requestData.libraryID = libraryID;
}
else {
requestData.libraryID = Zotero.Libraries.userLibraryID;
}
let library = Zotero.Libraries.get(requestData.libraryID);
if (!library.getDataLoaded('item')) {

View file

@ -281,4 +281,17 @@ describe("Local API Server", function () {
assert.equal(response[0].meta.numItems, 1);
});
});
describe("/groups/<groupID>", function () {
it("should return 404 for unknown group", async function () {
let { response } = await apiGet(
'/groups/99999999999',
{
successCodes: [404],
responseType: 'text'
}
);
assert.equal(response, "Not found");
});
});
});