Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(admin): guard guest email actions and validate user directory inputs

Tin28c23dc1becc
diff --git a/apps/api/src/admin/controllers/list-users.ts b/apps/api/src/admin/controllers/list-users.ts
index ca1d9ca89..8d8b73711 100644
--- a/apps/api/src/admin/controllers/list-users.ts
+++ b/apps/api/src/admin/controllers/list-users.ts
@@ -3,6 +3,7 @@ import db from "../../database";
import { userTable } from "../../database/schema";
import { escapeLikePattern } from "../../search/like-pattern";
import { instanceAdminRoleSql } from "../../utils/instance-admin-role";
+import { notBannedCondition } from "../../utils/user-ban";
import { adminUserColumns, toAdminUser } from "../users/admin-user-columns";
type ListUsersInput = {
@@ -17,7 +18,7 @@ type ListUsersInput = {
function filters({ search, status, role, emailVerified }: ListUsersInput) {
const term = search?.trim() ?? "";
const pattern = `%${escapeLikePattern(term)}%`;
- const deactivated = sql`coalesce(${userTable.banned}, false)`;
+ const active = notBannedCondition();
const isAdmin = sql`coalesce(${instanceAdminRoleSql(userTable.role)}, false)`;
return and(
term
@@ -26,8 +27,8 @@ function filters({ search, status, role, emailVerified }: ListUsersInput) {
status === undefined
? undefined
: status === "deactivated"
- ? deactivated
- : sql`NOT ${deactivated}`,
+ ? sql`NOT (${active})`
+ : active,
role === undefined
? undefined
: role === "admin"
diff --git a/apps/api/src/admin/controllers/mark-email-verified.ts b/apps/api/src/admin/controllers/mark-email-verified.ts
index d6891b816..a8ea46e00 100644
--- a/apps/api/src/admin/controllers/mark-email-verified.ts
+++ b/apps/api/src/admin/controllers/mark-email-verified.ts
@@ -1,6 +1,7 @@
import { and, eq } from "drizzle-orm";
import db from "../../database";
import { userTable } from "../../database/schema";
+import { ApiError } from "../../errors/api-error";
import type { AdminAuditRequest } from "../audit/admin-audit-request";
import { recordAdminAction } from "../audit/record-admin-action";
import { findAdminTargetUser } from "../users/find-admin-target-user";
@@ -8,7 +9,13 @@ import { findAdminTargetUser } from "../users/find-admin-target-user";
/** Mark a user's email verified. Already verified addresses are left alone. */
async function markEmailVerified(userId: string, audit: AdminAuditRequest) {
await db.transaction(async (tx) => {
- await findAdminTargetUser(userId, tx);
+ const user = await findAdminTargetUser(userId, tx);
+ if (user.isAnonymous) {
+ throw new ApiError(409, {
+ code: "GUEST_ACCOUNT",
+ message: "Guest accounts have no email address to verify.",
+ });
+ }
const [updated] = await tx
.update(userTable)
.set({ emailVerified: true })
diff --git a/apps/api/src/admin/response.ts b/apps/api/src/admin/response.ts
index aed93baa1..4ce02fa80 100644
--- a/apps/api/src/admin/response.ts
+++ b/apps/api/src/admin/response.ts
@@ -8,6 +8,7 @@ export const adminUserSchema = z
name: z.string(),
email: z.string(),
emailVerified: z.boolean(),
+ isAnonymous: z.boolean(),
image: z.string().nullable(),
createdAt: isoTimestamp,
updatedAt: isoTimestamp,
diff --git a/apps/api/src/admin/user-routes.ts b/apps/api/src/admin/user-routes.ts
index 84f4acd50..0ea8077c1 100644
--- a/apps/api/src/admin/user-routes.ts
+++ b/apps/api/src/admin/user-routes.ts
@@ -103,13 +103,14 @@ const markEmailVerifiedRoute = createRoute({
tags: ["Admin"],
summary: "Mark an email as verified",
description:
- "Mark the user's email address as verified without asking them, for example so a single sign-on identity with the same address can link to the account.",
+ "Mark a non-guest user's email address as verified without asking them, for example so a single sign-on identity with the same address can link to the account.",
middleware: [requireUserSession, requireInstanceAdmin] as const,
request: { params: adminUserParam },
responses: {
200: jsonResponse("The email is verified", adminEmailVerifiedSchema),
403: forbidden,
404: notFound,
+ 409: errorResponse("Guest accounts have no email address to verify"),
},
});
diff --git a/apps/api/src/admin/users/admin-user-columns.ts b/apps/api/src/admin/users/admin-user-columns.ts
index 8e285b496..8ac450e48 100644
--- a/apps/api/src/admin/users/admin-user-columns.ts
+++ b/apps/api/src/admin/users/admin-user-columns.ts
@@ -13,6 +13,7 @@ export const adminUserColumns = {
name: userTable.name,
email: userTable.email,
emailVerified: userTable.emailVerified,
+ isAnonymous: userTable.isAnonymous,
image: userTable.image,
createdAt: userTable.createdAt,
updatedAt: userTable.updatedAt,
@@ -47,6 +48,7 @@ export function toAdminUser(row: AdminUserRow) {
createdAt: iso(row.createdAt),
updatedAt: iso(row.updatedAt),
banned: row.banned ?? false,
+ isAnonymous: row.isAnonymous ?? false,
banExpires: row.banExpires ? iso(row.banExpires) : null,
lastActiveAt: row.lastActiveAt ? iso(row.lastActiveAt) : null,
signInMethods: [...row.signInMethods].sort(),
diff --git a/apps/docs/core/operations/administration.mdx b/apps/docs/core/operations/administration.mdx
index 6ed3e6e94..857fd2bb7 100644
--- a/apps/docs/core/operations/administration.mdx
+++ b/apps/docs/core/operations/administration.mdx
@@ -19,6 +19,8 @@ From a user's menu you can:
- **Mark email as verified.** Confirms the address without asking them. Only do this when you know the address is theirs: single sign-on identities with the same verified email can link to the account.
- **Deactivate, reactivate, or delete** the account.
+Guest accounts have generated addresses, so password reset, verification email, and mark-verified actions are unavailable for them.
+
Emails need [SMTP](/core/installation/environment-variables#smtp-configuration) to be configured. Without it, Kaneo tells you nothing was sent.
If [the identity provider manages profile pictures](/core/social-providers/custom-oauth#managed-profile-fields), you can't replace a user's picture, and you can only remove one they uploaded in Kaneo.
diff --git a/apps/docs/openapi.json b/apps/docs/openapi.json
index c0e4856d8..68326549b 100644
--- a/apps/docs/openapi.json
+++ b/apps/docs/openapi.json
@@ -5356,6 +5356,9 @@
"emailVerified": {
"type": "boolean"
},
+ "isAnonymous": {
+ "type": "boolean"
+ },
"image": {
"type": [
"string",
@@ -5413,6 +5416,7 @@
"name",
"email",
"emailVerified",
+ "isAnonymous",
"image",
"createdAt",
"updatedAt",
@@ -25373,7 +25377,7 @@
"Admin"
],
"summary": "Mark an email as verified",
- "description": "Mark the user's email address as verified without asking them, for example so a single sign-on identity with the same address can link to the account.",
+ "description": "Mark a non-guest user's email address as verified without asking them, for example so a single sign-on identity with the same address can link to the account.",
"parameters": [
{
"schema": {
@@ -25426,6 +25430,16 @@
}
}
},
+ "409": {
+ "description": "Guest accounts have no email address to verify",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ApiError"
+ }
+ }
+ }
+ },
"429": {
"$ref": "#/components/responses/ApiKeyRateLimited"
}
diff --git a/apps/web/src/components/admin/user-management/create-user-dialog.tsx b/apps/web/src/components/admin/user-management/create-user-dialog.tsx
index 9823d06bf..2a69c8bbc 100644
--- a/apps/web/src/components/admin/user-management/create-user-dialog.tsx
+++ b/apps/web/src/components/admin/user-management/create-user-dialog.tsx
@@ -13,7 +13,7 @@ import {
DialogPopup,
DialogTitle,
} from "@/components/ui/dialog";
-import { Field, FieldLabel } from "@/components/ui/field";
+import { Field, FieldError, FieldLabel } from "@/components/ui/field";
import { Input } from "@/components/ui/input";
import useCreateAdminUser from "@/hooks/mutations/admin/use-create-admin-user";
import useGetConfig from "@/hooks/queries/config/use-get-config";
@@ -44,16 +44,21 @@ export function CreateUserDialog({
const [values, setValues] = useState(EMPTY_CREATE_USER_VALUES);
const { mutateAsync: createUser, isPending } = useCreateAdminUser();
const mode = getAccountSetupMode(config);
+ const [nameError, setNameError] = useState(false);
const close = () => {
onOpenChange(false);
setValues(EMPTY_CREATE_USER_VALUES);
+ setNameError(false);
};
const handleSubmit = async (event: FormEvent<HTMLFormElement>) => {
event.preventDefault();
const request = buildCreateUserRequest(values);
- if (!request) return;
+ if (!request) {
+ setNameError(!values.name.trim());
+ return;
+ }
try {
await createUser(request);
close();
@@ -80,7 +85,7 @@ export function CreateUserDialog({
</DialogHeader>
<DialogPanel>
<div className="flex flex-col gap-4">
- <Field>
+ <Field invalid={nameError}>
<FieldLabel htmlFor="admin-create-user-name">
{t("settings:adminUsers.edit.name")}
</FieldLabel>
@@ -92,13 +97,19 @@ export function CreateUserDialog({
required
maxLength={200}
value={values.name}
- onChange={(event) =>
+ onChange={(event) => {
setValues((current) => ({
...current,
name: event.target.value,
- }))
- }
+ }));
+ setNameError(false);
+ }}
/>
+ {nameError ? (
+ <FieldError match>
+ {t("settings:adminUsers.create.nameRequired")}
+ </FieldError>
+ ) : null}
</Field>
<Field>
<FieldLabel htmlFor="admin-create-user-email">
diff --git a/apps/web/src/components/admin/user-management/get-user-action-types.test.ts b/apps/web/src/components/admin/user-management/get-user-action-types.test.ts
index fc3dcf644..507963747 100644
--- a/apps/web/src/components/admin/user-management/get-user-action-types.test.ts
+++ b/apps/web/src/components/admin/user-management/get-user-action-types.test.ts
@@ -6,10 +6,16 @@ const options = { isSelf: false, canSendPasswordReset: true };
describe("getUserActionTypes", () => {
it("offers verification actions only for unverified addresses", () => {
expect(
- getUserActionTypes({ emailVerified: true, banned: false }, options),
+ getUserActionTypes(
+ { isAnonymous: false, emailVerified: true, banned: false },
+ options,
+ ),
).toEqual(["sendPasswordReset", "deactivate", "delete"]);
expect(
- getUserActionTypes({ emailVerified: false, banned: true }, options),
+ getUserActionTypes(
+ { isAnonymous: false, emailVerified: false, banned: true },
+ options,
+ ),
).toEqual([
"sendPasswordReset",
"sendVerification",
@@ -19,10 +25,19 @@ describe("getUserActionTypes", () => {
]);
});
+ it("omits every email action for guests", () => {
+ expect(
+ getUserActionTypes(
+ { isAnonymous: true, emailVerified: false, banned: false },
+ options,
+ ),
+ ).toEqual(["deactivate", "delete"]);
+ });
+
it("never offers deactivating or deleting yourself", () => {
expect(
getUserActionTypes(
- { emailVerified: true, banned: false },
+ { isAnonymous: false, emailVerified: true, banned: false },
{ ...options, isSelf: true },
),
).toEqual(["sendPasswordReset"]);
@@ -31,7 +46,7 @@ describe("getUserActionTypes", () => {
it("hides reset links when password sign-in is off", () => {
expect(
getUserActionTypes(
- { emailVerified: true, banned: false },
+ { isAnonymous: false, emailVerified: true, banned: false },
{ ...options, canSendPasswordReset: false },
),
).toEqual(["deactivate", "delete"]);
diff --git a/apps/web/src/components/admin/user-management/get-user-action-types.ts b/apps/web/src/components/admin/user-management/get-user-action-types.ts
index a0c8f74d6..7ea4f801a 100644
--- a/apps/web/src/components/admin/user-management/get-user-action-types.ts
+++ b/apps/web/src/components/admin/user-management/get-user-action-types.ts
@@ -9,12 +9,15 @@ type Options = {
/** The confirmable actions a directory row offers, in menu order. */
export function getUserActionTypes(
- user: Pick<AdminUser, "emailVerified" | "banned">,
+ user: Pick<AdminUser, "emailVerified" | "banned" | "isAnonymous">,
{ isSelf, canSendPasswordReset }: Options,
): UserActionType[] {
const types: UserActionType[] = [];
- if (canSendPasswordReset) types.push("sendPasswordReset");
- if (!user.emailVerified) types.push("sendVerification", "markEmailVerified");
+ if (!user.isAnonymous) {
+ if (canSendPasswordReset) types.push("sendPasswordReset");
+ if (!user.emailVerified)
+ types.push("sendVerification", "markEmailVerified");
+ }
if (!isSelf) {
types.push(user.banned ? "reactivate" : "deactivate", "delete");
}
diff --git a/apps/web/src/components/admin/user-management/user-management-panel.test.tsx b/apps/web/src/components/admin/user-management/user-management-panel.test.tsx
index 5fc8c4ff1..18a6ee1fe 100644
--- a/apps/web/src/components/admin/user-management/user-management-panel.test.tsx
+++ b/apps/web/src/components/admin/user-management/user-management-panel.test.tsx
@@ -105,6 +105,7 @@ function user(overrides: Partial<AdminUser> = {}): AdminUser {
name: "Ada Lovelace",
emailVerified: true,
+ isAnonymous: false,
image: null,
createdAt: "2026-01-01T00:00:00.000Z",
updatedAt: "2026-01-01T00:00:00.000Z",
@@ -615,6 +616,52 @@ describe("UserManagementPanel", () => {
);
});
+ it("shows an inline error for a whitespace-only name and clears it on correction", async () => {
+ vi.useRealTimers();
+ useAdminUsersMock.mockReturnValue(success(1));
+ render(<UserManagementPanel />);
+ fireEvent.click(
+ screen.getByRole("button", { name: "settings:adminUsers.create.open" }),
+ );
+ const dialog = await screen.findByRole("dialog");
+ const name = within(dialog).getByLabelText("settings:adminUsers.edit.name");
+ fireEvent.change(name, { target: { value: " " } });
+ fireEvent.change(
+ within(dialog).getByLabelText("settings:adminUsers.edit.email"),
+ {
+ target: { value: "[email protected]" },
+ },
+ );
+ fireEvent.click(
+ within(dialog).getByRole("button", {
+ name: "settings:adminUsers.create.submit",
+ }),
+ );
+ expect(
+ await within(dialog).findByText(
+ "settings:adminUsers.create.nameRequired",
+ ),
+ ).toBeTruthy();
+ expect(name.getAttribute("aria-invalid")).toBe("true");
+ expect(credentialMocks.createUser).not.toHaveBeenCalled();
+ fireEvent.change(name, { target: { value: "Nora New" } });
+ expect(
+ within(dialog).queryByText("settings:adminUsers.create.nameRequired"),
+ ).toBeNull();
+ fireEvent.click(
+ within(dialog).getByRole("button", {
+ name: "settings:adminUsers.create.submit",
+ }),
+ );
+ await waitFor(() =>
+ expect(credentialMocks.createUser).toHaveBeenCalledWith({
+ name: "Nora New",
+ email: "[email protected]",
+ role: "user",
+ }),
+ );
+ });
+
it("explains single sign-on accounts when password registration is off", async () => {
vi.useRealTimers();
configMock.data = { hasSmtp: true, disablePasswordRegistration: true };
diff --git a/i18n/az-AZ.json b/i18n/az-AZ.json
index 388ac28cd..b0a453b36 100644
--- a/i18n/az-AZ.json
+++ b/i18n/az-AZ.json
@@ -1707,7 +1707,8 @@
"hintSso": "Password sign-in is turned off here, so no email is sent. They sign in with single sign-on using this email address.",
"open": "Create user",
"submit": "Create user",
- "title": "Create user"
+ "title": "Create user",
+ "nameRequired": "Enter a name"
},
"details": {
"avatarHint": "PNG, JPEG, or WebP. Cropped to a square.",
diff --git a/i18n/de-DE.json b/i18n/de-DE.json
index 7ddef03be..edcfa147b 100644
--- a/i18n/de-DE.json
+++ b/i18n/de-DE.json
@@ -687,7 +687,8 @@
"hintSso": "Password sign-in is turned off here, so no email is sent. They sign in with single sign-on using this email address.",
"open": "Create user",
"submit": "Create user",
- "title": "Create user"
+ "title": "Create user",
+ "nameRequired": "Enter a name"
},
"details": {
"avatarHint": "PNG, JPEG, or WebP. Cropped to a square.",
diff --git a/i18n/el-GR.json b/i18n/el-GR.json
index 2d0da08c2..b98878672 100644
--- a/i18n/el-GR.json
+++ b/i18n/el-GR.json
@@ -1707,7 +1707,8 @@
"hintSso": "Password sign-in is turned off here, so no email is sent. They sign in with single sign-on using this email address.",
"open": "Create user",
"submit": "Create user",
- "title": "Create user"
+ "title": "Create user",
+ "nameRequired": "Enter a name"
},
"details": {
"avatarHint": "PNG, JPEG, or WebP. Cropped to a square.",
diff --git a/i18n/en-US.json b/i18n/en-US.json
index f2a0c32d8..fe56d92e1 100644
--- a/i18n/en-US.json
+++ b/i18n/en-US.json
@@ -763,6 +763,7 @@
"create": {
"open": "Create user",
"title": "Create user",
+ "nameRequired": "Enter a name",
"description": "Add an account for someone. You never choose or see their password.",
"hintEmail": "They'll get an email with a link to set their own password. The link expires in 2 days.",
"hintNoEmail": "Email isn't configured on this instance, so no password link can be sent. Once SMTP is set up, use “Send password reset link”.",
diff --git a/i18n/es-ES.json b/i18n/es-ES.json
index ea0cc4562..7319bfe15 100644
--- a/i18n/es-ES.json
+++ b/i18n/es-ES.json
@@ -1717,7 +1717,8 @@
"hintSso": "Password sign-in is turned off here, so no email is sent. They sign in with single sign-on using this email address.",
"open": "Create user",
"submit": "Create user",
- "title": "Create user"
+ "title": "Create user",
+ "nameRequired": "Enter a name"
},
"details": {
"avatarHint": "PNG, JPEG, or WebP. Cropped to a square.",
diff --git a/i18n/fr-FR.json b/i18n/fr-FR.json
index 74fd73ef6..413aa1788 100644
--- a/i18n/fr-FR.json
+++ b/i18n/fr-FR.json
@@ -1717,7 +1717,8 @@
"hintSso": "Password sign-in is turned off here, so no email is sent. They sign in with single sign-on using this email address.",
"open": "Create user",
"submit": "Create user",
- "title": "Create user"
+ "title": "Create user",
+ "nameRequired": "Enter a name"
},
"details": {
"avatarHint": "PNG, JPEG, or WebP. Cropped to a square.",
diff --git a/i18n/hi-IN.json b/i18n/hi-IN.json
index a7652824f..1d0f2408d 100644
--- a/i18n/hi-IN.json
+++ b/i18n/hi-IN.json
@@ -1707,7 +1707,8 @@
"hintSso": "Password sign-in is turned off here, so no email is sent. They sign in with single sign-on using this email address.",
"open": "Create user",
"submit": "Create user",
- "title": "Create user"
+ "title": "Create user",
+ "nameRequired": "Enter a name"
},
"details": {
"avatarHint": "PNG, JPEG, or WebP. Cropped to a square.",
diff --git a/i18n/id-ID.json b/i18n/id-ID.json
index db049b925..3a0ad6def 100644
--- a/i18n/id-ID.json
+++ b/i18n/id-ID.json
@@ -1697,7 +1697,8 @@
"hintSso": "Password sign-in is turned off here, so no email is sent. They sign in with single sign-on using this email address.",
"open": "Create user",
"submit": "Create user",
- "title": "Create user"
+ "title": "Create user",
+ "nameRequired": "Enter a name"
},
"details": {
"avatarHint": "PNG, JPEG, or WebP. Cropped to a square.",
diff --git a/i18n/it-IT.json b/i18n/it-IT.json
index 023ee39c6..cd4b43fe9 100644
--- a/i18n/it-IT.json
+++ b/i18n/it-IT.json
@@ -1717,7 +1717,8 @@
"hintSso": "Password sign-in is turned off here, so no email is sent. They sign in with single sign-on using this email address.",
"open": "Create user",
"submit": "Create user",
- "title": "Create user"
+ "title": "Create user",
+ "nameRequired": "Enter a name"
},
"details": {
"avatarHint": "PNG, JPEG, or WebP. Cropped to a square.",
diff --git a/i18n/ja-JP.json b/i18n/ja-JP.json
index 528afa1ec..4306b48ce 100644
--- a/i18n/ja-JP.json
+++ b/i18n/ja-JP.json
@@ -1697,7 +1697,8 @@
"hintSso": "Password sign-in is turned off here, so no email is sent. They sign in with single sign-on using this email address.",
"open": "Create user",
"submit": "Create user",
- "title": "Create user"
+ "title": "Create user",
+ "nameRequired": "Enter a name"
},
"details": {
"avatarHint": "PNG, JPEG, or WebP. Cropped to a square.",
diff --git a/i18n/ko-KR.json b/i18n/ko-KR.json
index b8866abf2..96133cf60 100644
--- a/i18n/ko-KR.json
+++ b/i18n/ko-KR.json
@@ -1697,7 +1697,8 @@
"hintSso": "Password sign-in is turned off here, so no email is sent. They sign in with single sign-on using this email address.",
"open": "Create user",
"submit": "Create user",
- "title": "Create user"
+ "title": "Create user",
+ "nameRequired": "Enter a name"
},
"details": {
"avatarHint": "PNG, JPEG, or WebP. Cropped to a square.",
diff --git a/i18n/mk-MK.json b/i18n/mk-MK.json
index e7ea97cf1..e5e5de57a 100644
--- a/i18n/mk-MK.json
+++ b/i18n/mk-MK.json
@@ -1707,7 +1707,8 @@
"hintSso": "Password sign-in is turned off here, so no email is sent. They sign in with single sign-on using this email address.",
"open": "Create user",
"submit": "Create user",
- "title": "Create user"
+ "title": "Create user",
+ "nameRequired": "Enter a name"
},
"details": {
"avatarHint": "PNG, JPEG, or WebP. Cropped to a square.",
diff --git a/i18n/nl-NL.json b/i18n/nl-NL.json
index d0b8b53e9..9050bf7c2 100644
--- a/i18n/nl-NL.json
+++ b/i18n/nl-NL.json
@@ -1707,7 +1707,8 @@
"hintSso": "Password sign-in is turned off here, so no email is sent. They sign in with single sign-on using this email address.",
"open": "Create user",
"submit": "Create user",
- "title": "Create user"
+ "title": "Create user",
+ "nameRequired": "Enter a name"
},
"details": {
"avatarHint": "PNG, JPEG, or WebP. Cropped to a square.",
diff --git a/i18n/pl-PL.json b/i18n/pl-PL.json
index 67bfd45b8..6123b7ced 100644
--- a/i18n/pl-PL.json
+++ b/i18n/pl-PL.json
@@ -2412,7 +2412,8 @@
"hintSso": "Password sign-in is turned off here, so no email is sent. They sign in with single sign-on using this email address.",
"open": "Create user",
"submit": "Create user",
- "title": "Create user"
+ "title": "Create user",
+ "nameRequired": "Enter a name"
},
"details": {
"avatarHint": "PNG, JPEG, or WebP. Cropped to a square.",
diff --git a/i18n/pt-BR.json b/i18n/pt-BR.json
index d22e06397..cb5f72b24 100644
--- a/i18n/pt-BR.json
+++ b/i18n/pt-BR.json
@@ -1717,7 +1717,8 @@
"hintSso": "Password sign-in is turned off here, so no email is sent. They sign in with single sign-on using this email address.",
"open": "Create user",
"submit": "Create user",
- "title": "Create user"
+ "title": "Create user",
+ "nameRequired": "Enter a name"
},
"details": {
"avatarHint": "PNG, JPEG, or WebP. Cropped to a square.",
diff --git a/i18n/ru-RU.json b/i18n/ru-RU.json
index dde90027b..f3b2e3da3 100644
--- a/i18n/ru-RU.json
+++ b/i18n/ru-RU.json
@@ -1735,7 +1735,8 @@
"hintSso": "Password sign-in is turned off here, so no email is sent. They sign in with single sign-on using this email address.",
"open": "Create user",
"submit": "Create user",
- "title": "Create user"
+ "title": "Create user",
+ "nameRequired": "Enter a name"
},
"details": {
"avatarHint": "PNG, JPEG, or WebP. Cropped to a square.",
diff --git a/i18n/tr-TR.json b/i18n/tr-TR.json
index 6e30b93d7..2b359f350 100644
--- a/i18n/tr-TR.json
+++ b/i18n/tr-TR.json
@@ -1707,7 +1707,8 @@
"hintSso": "Password sign-in is turned off here, so no email is sent. They sign in with single sign-on using this email address.",
"open": "Create user",
"submit": "Create user",
- "title": "Create user"
+ "title": "Create user",
+ "nameRequired": "Enter a name"
},
"details": {
"avatarHint": "PNG, JPEG, or WebP. Cropped to a square.",
diff --git a/i18n/uk-UA.json b/i18n/uk-UA.json
index 5bdc43c34..b9a3e0c4a 100644
--- a/i18n/uk-UA.json
+++ b/i18n/uk-UA.json
@@ -1727,7 +1727,8 @@
"hintSso": "Password sign-in is turned off here, so no email is sent. They sign in with single sign-on using this email address.",
"open": "Create user",
"submit": "Create user",
- "title": "Create user"
+ "title": "Create user",
+ "nameRequired": "Enter a name"
},
"details": {
"avatarHint": "PNG, JPEG, or WebP. Cropped to a square.",
diff --git a/i18n/vi-VN.json b/i18n/vi-VN.json
index 86613c27d..fa5faafb9 100644
--- a/i18n/vi-VN.json
+++ b/i18n/vi-VN.json
@@ -1697,7 +1697,8 @@
"hintSso": "Password sign-in is turned off here, so no email is sent. They sign in with single sign-on using this email address.",
"open": "Create user",
"submit": "Create user",
- "title": "Create user"
+ "title": "Create user",
+ "nameRequired": "Enter a name"
},
"details": {
"avatarHint": "PNG, JPEG, or WebP. Cropped to a square.",
diff --git a/i18n/zh-CN.json b/i18n/zh-CN.json
index 8e4b7a64e..8b44da7d4 100644
--- a/i18n/zh-CN.json
+++ b/i18n/zh-CN.json
@@ -1697,7 +1697,8 @@
"hintSso": "Password sign-in is turned off here, so no email is sent. They sign in with single sign-on using this email address.",
"open": "Create user",
"submit": "Create user",
- "title": "Create user"
+ "title": "Create user",
+ "nameRequired": "Enter a name"
},
"details": {
"avatarHint": "PNG, JPEG, or WebP. Cropped to a square.",
diff --git a/i18n/zh-TW.json b/i18n/zh-TW.json
index 8646d76d8..3fb4663fa 100644
--- a/i18n/zh-TW.json
+++ b/i18n/zh-TW.json
@@ -1696,7 +1696,8 @@
"hintSso": "Password sign-in is turned off here, so no email is sent. They sign in with single sign-on using this email address.",
"open": "Create user",
"submit": "Create user",
- "title": "Create user"
+ "title": "Create user",
+ "nameRequired": "Enter a name"
},
"details": {
"avatarHint": "PNG, JPEG, or WebP. Cropped to a square.",
diff --git a/tests/api-integration/admin-user-creation.test.ts b/tests/api-integration/admin-user-creation.test.ts
index eb0569882..dc3e4402e 100644
--- a/tests/api-integration/admin-user-creation.test.ts
+++ b/tests/api-integration/admin-user-creation.test.ts
@@ -98,8 +98,14 @@ describe("POST /api/admin/users", () => {
expect(JSON.stringify(audit)).not.toContain(token);
// The emailed link goes through the regular reset flow.
- const callback = await setup.app.request(`${link.pathname}${link.search}`);
+ const callback = await setup.app.request(data.passwordLink);
expect(callback.status).toBe(302);
+ const redirect = new URL(callback.headers.get("location") as string);
+ expect(`${redirect.origin}${redirect.pathname}`).toBe(
+ "http://localhost:5173/auth/reset-password",
+ );
+ expect(redirect.searchParams.get("token")).toBe(token);
+ expect(redirect.searchParams.has("error")).toBe(false);
const post = (path: string, body: unknown) =>
setup.app.request(`/api/auth${path}`, {
method: "POST",
diff --git a/tests/api-integration/admin-user-credentials.test.ts b/tests/api-integration/admin-user-credentials.test.ts
index 8fb02b6e2..cd825c87a 100644
--- a/tests/api-integration/admin-user-credentials.test.ts
+++ b/tests/api-integration/admin-user-credentials.test.ts
@@ -56,7 +56,8 @@ describe("POST /api/admin/users/{userId}/password-reset-email", () => {
expect(to).toBe("[email protected]");
expect(subject).toBe("Choose a new Kaneo password");
expect(data.purpose).toBe("reset");
- const token = new URL(data.passwordLink).pathname.split("/").at(-1);
+ const link = new URL(data.passwordLink);
+ const token = link.pathname.split("/").at(-1);
expect(text).not.toContain(token);
const [verification] = await db.select().from(schema.verificationTable);
@@ -74,6 +75,24 @@ describe("POST /api/admin/users/{userId}/password-reset-email", () => {
metadata: null,
});
expect(JSON.stringify(rows)).not.toContain(token);
+
+ const visit = await setup.app.request(data.passwordLink);
+ expect(visit.status).toBe(302);
+ const redirect = new URL(visit.headers.get("location") as string);
+ expect(`${redirect.origin}${redirect.pathname}`).toBe(
+ "http://localhost:5173/auth/reset-password",
+ );
+ expect(redirect.searchParams.get("token")).toBe(token);
+ expect(redirect.searchParams.has("error")).toBe(false);
+ const reset = await setup.app.request("/api/auth/reset-password", {
+ method: "POST",
+ headers: { "content-type": "application/json" },
+ body: JSON.stringify({
+ token,
+ newPassword: "a fresh reset password 123",
+ }),
+ });
+ expect(reset.status).toBe(200);
});
it("explains why nothing was sent and records nothing", async () => {
@@ -129,7 +148,7 @@ describe("POST /api/admin/users/{userId}/verification-email", () => {
expect(await auditRows("user.verification_sent")).toHaveLength(1);
expect(await readAuditLog()).toHaveLength(1);
- const visit = await setup.app.request(`${link.pathname}${link.search}`);
+ const visit = await setup.app.request(data.verificationLink);
expect(visit.status).toBe(302);
expect(visit.headers.get("location")).toBe(
"http://localhost:5173/auth/sign-in",
@@ -157,6 +176,38 @@ describe("POST /api/admin/users/{userId}/verification-email", () => {
});
describe("PUT /api/admin/users/{userId}/email-verified", () => {
+ it("rejects all guest email actions without changing or auditing the account", async () => {
+ await db
+ .update(schema.userTable)
+ .set({ isAnonymous: true })
+ .where(eq(schema.userTable.id, setup.target.userId));
+
+ for (const [path, method] of [
+ ["/password-reset-email", "POST"],
+ ["/verification-email", "POST"],
+ ["/email-verified", "PUT"],
+ ]) {
+ const response = await post(path, method);
+ expect(response.status, path).toBe(409);
+ expect((await readErrorBody(response)).code).toBe("GUEST_ACCOUNT");
+ }
+ expect(await targetVerified()).toBe(false);
+ expect(email.sendAccountPasswordEmail).not.toHaveBeenCalled();
+ expect(email.sendEmailVerificationEmail).not.toHaveBeenCalled();
+ expect(await readAuditLog()).toEqual([]);
+
+ const response = await setup.asAdmin("");
+ const body = (await response.json()) as {
+ users: { id: string; isAnonymous: boolean }[];
+ };
+ expect(
+ body.users.find((user) => user.id === setup.target.userId)?.isAnonymous,
+ ).toBe(true);
+ expect(
+ body.users.find((user) => user.id === setup.admin.userId)?.isAnonymous,
+ ).toBe(false);
+ });
+
it("marks the email verified once", async () => {
expect(await targetVerified()).toBe(false);
const first = await post("/email-verified", "PUT");
diff --git a/tests/api-integration/admin-user-listing.test.ts b/tests/api-integration/admin-user-listing.test.ts
index 56de82b18..78a53b1b1 100644
--- a/tests/api-integration/admin-user-listing.test.ts
+++ b/tests/api-integration/admin-user-listing.test.ts
@@ -231,6 +231,40 @@ describe("API integration: admin user listing", () => {
expect((await listUsers(app, { emailVerified: "yes" })).status).toBe(400);
});
+ it("treats expired timed bans as active in filtered results and totals", async () => {
+ const admin = await createUser({
+ name: "Admin",
+ email: "[email protected]",
+ role: "admin",
+ });
+ const expired = await createUser({
+ name: "Expired",
+ email: "[email protected]",
+ banned: true,
+ banExpires: new Date(Date.now() - 60_000),
+ });
+ const future = await createUser({
+ name: "Future",
+ email: "[email protected]",
+ banned: true,
+ banExpires: new Date(Date.now() + 60_000),
+ });
+ mockAuthenticatedSession(admin);
+ const { app } = createApp();
+ const active = (await (
+ await listUsers(app, { status: "active" })
+ ).json()) as AdminUserList;
+ expect(active.total).toBe(2);
+ expect(active.users.map((user) => user.id).sort()).toEqual(
+ [admin.id, expired.id].sort(),
+ );
+ const deactivated = (await (
+ await listUsers(app, { status: "deactivated" })
+ ).json()) as AdminUserList;
+ expect(deactivated.total).toBe(1);
+ expect(deactivated.users.map((user) => user.id)).toEqual([future.id]);
+ });
+
it("reports last session activity and linked sign-in methods", async () => {
const admin = await createUser({
name: "Instance Admin",