fix: Scope incorrectly translated on API key creation (#10134)

This commit is contained in:
Tom Moor authored and GitHub committed 2025-09-08 21:58:52 -04:00
1 parent 75df8fc18b
commit 866d30638e
2 files changed
+14 -2

No files matched your search

+9 -1
View File
@@ -47,7 +47,13 @@ describe("#apiKeys.create", () => {
body: {
token: user.getJwtToken(),
name: "My API Key",
scope: ["/api/documents.list", "*.info", "users.*"],
scope: [
"/api/documents.list",
"/revisions.list",
"*.info",
"users.*",
"collections:read",
],
},
});
const body = await res.json();
@@ -56,8 +62,10 @@ describe("#apiKeys.create", () => {
expect(body.data.name).toEqual("My API Key");
expect(body.data.scope).toEqual([
"/api/documents.list",
"/api/revisions.list",
"/api/*.info",
"/api/users.*",
"collections:read",
]);
});
+5 -1
View File
@@ -31,7 +31,11 @@ router.post(
name,
userId: user.id,
expiresAt,
scope: scope?.map((s) => (s.startsWith("/api/") ? s : `/api/${s}`)),
scope: scope?.map((s) =>
s.startsWith("/api/") || s.includes(":")
? s
: `/api/${s.replace(/^\//, "")}`
),
});
apiKey.user = user;