Files
baserow/web-frontend/test/fixtures/user.js
alamin-br 4ded9a7d37 Allow instance admins to manage users' 2FA state (#5517)
* feat: add password-free TwoFactorAuthHandler.disable_for_user

* feat: add UserAdminHandler.disable_user_two_factor_auth

* feat: add AdminDisableTwoFactorAuthActionType for audit logging

* feat: expose two_factor_auth status in admin users list

* feat: add admin endpoint to remove a user's two-factor authentication

* feat: show 2FA status column in admin users table

* feat: allow admins to remove a user's 2FA from the edit user modal

* chore: add changelog entry for admin 2FA management

* style: add styling for the remove 2FA link in the edit user modal

* fix: correct admin users 2FA column width and edit-modal layout

Give the new 2FA column an explicit width so it no longer sizes to its
content and pushes the row past the container, which had clipped the
rightmost "Highest Role" badge.

Wrap the edit modal's 2FA badge and remove link in a centered flex row
with a gap, and tighten the link so it aligns with the badge instead of
out-weighing the primary Save action.

* fix(review): register AdminDisableTwoFactorAuthActionType in apps.py

The new admin 2FA-removal action type was not registered in the action
type registry like every sibling user action. Audit log entries were
still created (the action_done signal carries the type directly), but the
action was absent from the enterprise audit-log export filter choices
(action_type_registry.get_types()) and unresolvable via the registry.
Register it alongside the other user action types and add a regression
test asserting it is registered.

* fix: show admin users active state as an icon only to free column space

Drop the "Active"/"Deactivated" text label from each row and keep just
the status icon (with a tooltip), so the table reclaims horizontal space
and the enterprise "Highest Role" billable badge is no longer clipped.
Both states keep an icon. Also drop the 2FA column width override, which
over-reserved space without helping.

* test: parametrize admin user password and name validation tests

Collapse the three password-validation tests and the two name-length
tests into test.each cases. Same coverage, less duplication, and a new
validation case only needs another data row.

* fix(review): annotate 2FA serializer schema and document 403

- Add @extend_schema_field(TwoFactorAuthSerializer) to get_two_factor_auth
  so the OpenAPI spec reflects the {type, is_enabled} shape instead of a
  bare object.
- Make the empty-provider case an explicit {} return rather than relying on
  TwoFactorAuthSerializer(None).data, which only yields {} because both
  fields are read_only.
- Document the 403 response on the admin two-factor-auth DELETE endpoint
  (IsAdminUser returns 403 for authenticated non-staff users).

* test: cover admin 2FA self-removal and modal error path

Add a backend test asserting an admin can remove their own 2FA (the
handler intentionally allows self-removal since it can't lock anyone
out), locking in that behavior against a future self-modification guard.

Add a frontend test for the DisableTwoFactorAuthModal failure path: on a
non-204 response the error surfaces in the modal and the optimistic row
clear is not applied, so the 2FA badge stays as-is.

* fix(review): drop misleading 2FA required marker and document empty schema

- Remove required attribute from the read-only 2FA FormGroup in UserForm
  (it wraps a display badge, not an input, so the indicator misled admins).
- Annotate get_two_factor_auth with a raw OpenAPI object schema that omits
  required, so the empty {} (no provider) case is valid while still
  documenting the {type, is_enabled} shape. Response data is unchanged.

* fix(review): null 2FA state, register 2FA actions, trim raises doc

- Return null (not {}) from get_two_factor_auth when no provider is
  configured; document the field as a nullable typed object. Propagated to
  admin/enterprise tests, EditUserModal optimistic update, and the user
  fixture. Make TwoFactorAuthField null-safe so the cell tolerates null.
- Register the pre-existing ConfigureTwoFactorAuthActionType and
  DisableTwoFactorAuthActionType so they appear in the audit-log dropdown.
- Drop the TwoFactorAuthNotConfigured :raises from disable(); it is raised by
  disable_for_user, which already documents it.
2026-06-22 15:34:37 +02:00

63 lines
1.3 KiB
JavaScript

export function aUser({
id = 1,
username = 'user@baserow.io',
name = 'user_name',
workspaces = [
{
id: 1,
name: 'some_workspace',
permissions: 'ADMIN',
},
],
lastLogin = '2021-04-26T07:50:45.643059Z',
dateJoined = '2021-04-21T12:04:27.379781Z',
isActive = true,
isStaff = true,
twoFactorAuth = null,
}) {
return {
id,
username,
name,
workspaces,
last_login: lastLogin,
date_joined: dateJoined,
is_active: isActive,
is_staff: isStaff,
two_factor_auth: twoFactorAuth,
}
}
export function createUsersForAdmin(
mock,
users,
page,
{ count = null, search = null, sorts = null }
) {
const params = { page }
if (search !== null) {
params.search = search
}
if (sorts !== null) {
params.sorts = sorts
}
mock.onGet(`/admin/users/`, { params }).reply(200, {
count: count === null ? users.length : count,
results: users,
})
}
export function expectUserDeleted(mock, userId) {
mock.onDelete(`/admin/users/${userId}/`).reply(200)
}
export function expectUserUpdated(mock, user, changes) {
mock
.onPatch(new RegExp(`/admin/users/${user.id}/`))
.reply(200, Object.assign({}, user, changes))
}
export function expectUserUpdatedRespondsWithError(mock, user, error) {
mock.onPatch(`/admin/users/${user.id}/`).reply(500, error)
}