Files
Davide Silvestri 42803f23ca feat: record and show the identity kind in history and pickers (#6620)
* feat: record and show the identity kind in history and pickers

- Snapshot the user type of the actor on row history, workflow history
  and audit log entries, and return it from their APIs.
- Show the identity icon in row and workflow history, list identities in
  their own section of the audit log actor filter and count them per role
  in inherited access.
- Load every identity in the team and access pickers through the
  paginated subjects endpoint, which now returns the workspace role.
- Give identities premium features from the workspace or instance
  licence instead of a seat.

* feat: record identity management in the audit log

Creating, updating and deleting an identity go through registered
actions, so the audit log shows who did it, with the identity's name and
role before and after an update. The actions are not undoable.

* fix: export an identity by its name in created by and last modified by

* fix: record the values an identity update replaced from the locked row

* fix: check the owner of an imported personal view without a query

* fix: show an identity with the avatar and icon of its subject type

* fix: audit an identity update by what it changed

* feat: include the actor's user type in the audit log export and tool

* test: cover a row history actor of an unregistered type

* test: name the history migration test after what it checks
2026-11-18 14:39:43 +01:00

145 lines
4.0 KiB
JavaScript

import { TestApp } from '@baserow/test/helpers/testApp'
import RowHistoryEntry from '@baserow/modules/database/components/row/RowHistoryEntry'
import { UserSubjectType } from '@baserow/modules/core/subjectTypes'
describe('RowHistoryEntry', () => {
let testApp = null
beforeEach(() => {
testApp = new TestApp()
testApp.store.state.workspace.items = [
{ users: [{ user_id: 1, name: 'Colliding user' }] },
]
})
afterEach(async () => {
vi.restoreAllMocks()
await testApp.afterEach()
})
test('renders a deleted Identity from its recorded identity metadata', async () => {
const wrapper = await testApp.mount(RowHistoryEntry, {
propsData: {
workspaceId: 1,
fields: [],
entry: {
action_type: 'update_row',
action_command_type: 'DO',
timestamp: '2026-08-05T12:00:00Z',
user: { id: 1, name: 'Current user' },
actor: {
id: 42,
type: 'auth.User',
user_type: 'identity',
name: 'Row writer',
},
before: {},
after: {},
fields_metadata: {},
},
},
})
expect(wrapper.html()).toMatchSnapshot()
})
test('shows an identity actor with the identity avatar of its subject type', async () => {
vi.spyOn(
UserSubjectType.prototype,
'identityIconClass',
'get'
).mockReturnValue('iconoir-identity-test')
const wrapper = await testApp.mount(RowHistoryEntry, {
propsData: {
workspaceId: 1,
fields: [],
entry: {
action_type: 'update_row',
action_command_type: 'DO',
timestamp: '2026-08-05T12:00:00Z',
user: { id: 42, name: 'Row writer' },
actor: {
id: 42,
type: 'auth.User',
user_type: 'identity',
name: 'Row writer',
},
before: {},
after: {},
fields_metadata: {},
},
},
})
expect(
wrapper.find('.identity-avatar .iconoir-identity-test').exists()
).toBe(true)
})
test('shows the stored name of an actor whose type is not registered', async () => {
const wrapper = await testApp.mount(RowHistoryEntry, {
propsData: {
workspaceId: 1,
fields: [],
entry: {
action_type: 'update_row',
action_command_type: 'DO',
timestamp: '2026-08-05T12:00:00Z',
user: { id: 1, name: 'Import token' },
actor: { id: 1, type: 'core.Token', name: 'Import token' },
before: {},
after: {},
fields_metadata: {},
},
},
})
expect(wrapper.find('.row-history-entry__name').text()).toContain(
'Import token'
)
expect(wrapper.find('.row-history-entry__initials').text()).toBe('I')
})
test('translates an Anonymous User actor when rendering', async () => {
const wrapper = await testApp.mount(RowHistoryEntry, {
propsData: {
workspaceId: 1,
fields: [],
entry: {
action_type: 'submit_form',
action_command_type: 'DO',
timestamp: '2026-08-05T12:00:00Z',
user: { id: null, name: 'Anonymous User' },
actor: { id: null, type: 'anonymous', name: 'Anonymous User' },
before: {},
after: {},
fields_metadata: {},
},
},
})
expect(wrapper.html()).toMatchSnapshot()
})
test('resolves a User actor through its registered subject type', async () => {
const wrapper = await testApp.mount(RowHistoryEntry, {
propsData: {
workspaceId: 1,
fields: [],
entry: {
action_type: 'update_row',
action_command_type: 'DO',
timestamp: '2026-08-05T12:00:00Z',
user: { id: 1, name: 'Stored user name' },
actor: { id: 1, type: 'auth.User', name: 'Stored user name' },
before: {},
after: {},
fields_metadata: {},
},
},
})
expect(wrapper.html()).toMatchSnapshot()
})
})