mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 16:28:31 +00:00
* fix: keep every button action card in place after a save A retyped action can keep its id, and an action created by an earlier save still carries its client id, so the refetched list must keep the client id of every buffered action rather than only the created ones. * feat(jobs): let a job type choose its Celery queue * test: assert the job enqueue through apply_async * refactor(database): expose the button click pre-checks on the service * refactor(database): share the button click payload and outcome mapping * feat(database): run a button click with external actions as a job * fix(database): map click races on the job and assert the audit entry * feat(database): answer a click with external actions with a job The request returns 202 and the job runs the sequence, so a slow endpoint holds a Celery worker instead of a WSGI one. * fix(database): give a capped click its slots back and cover the denied job * refactor(database): raise a plain exception for a denied click job * chore: consume the button_dispatch queue on the default worker * chore: add the button_dispatch queue to the Zed worker launch config * feat(database): wait on the job of an accepted button click * fix(database): stop waiting on a button click job after a deadline * test(e2e): a slow endpoint no longer blocks the grid during a click * test(e2e): name the second-button test for what a single worker can prove * test: assert the airtable import job enqueue through apply_async * chore: changelog for the button dispatch job * fix(database): keep the clicker's IP and session on a button click job The audit log and analytics read both from the user, which the job only restores through these mixins. * fix(database): fail a button click job whose field or table was trashed * fix(database): serialize the busy check of a click with its job creation Two racing requests could both see the cell free and each start a job, so a single worker sent every request twice. Also drops the budget bookkeeping from the inline path, which no longer reaches outside Baserow. * test: assert a refused dispatch check records no audit entry * docs: say a button click job shares the default worker with realtime updates Also adds the automation_workflow and button_dispatch queues to the example supervisor config. * fix(database): check a button click job once more at the deadline The job store stops polling before the deadline, so a job that finished unseen was reported as still running. * test: cover an accepted click in the row modal and on a card * refactor(database): ask the service whether a cell has a click in flight The view queried the job table itself; the check belongs beside the other dispatch rules in the service. * fix(database): run only the action list a click was accepted with The request checks and charges one list; the job re-read the field's current one, so an action added while the job waited ran unchecked and an added external one sent without a rate-limit slot. * fix(database): keep queued button clicks sane across crashes, retypes and trash A dead worker's job no longer blocks its cell until cleanup, a retype no longer deletes a queued job, and a trashed database refuses the click. Core permission refusals use the API's wording. The cell lock is shared and the unused refund plumbing is gone. * fix(database): stop a queued button click from sending twice or unchecked A late or replica-blind click no longer repeats its requests, a retype to external is caught, and a quota refusal answers in the request. Slots come back when no job row was written, and the stored answer is safe for jsonb. * fix: keep polling a button click job after one failed poll A click waits on the job store, which stopped for good after a single failed poll. A settled click's job is dropped so the store stops polling it. * fix(database): stop a cancelled button click between actions The owner can cancel a running job, and later actions still ran. The last job check at the deadline is bounded too, so a hung request cannot keep the button spinning. * test: cover a job's answer reaching Open URL and a click edited while queued * fix(database): let a click job finish when its button is retyped mid-run The worker's save wrote the old field id back and failed. Timeouts and unmapped failures no longer name the job type, and a job that is already final leaves the store. * fix(database): run button click jobs on the export queue Review feedback: the celery queue is for fast tasks, and a new queue needs every self-hosted worker changed. Also strips lone surrogates from the stored answer, moves the enqueue rules into the service and drops the unused websocket id. * fix(database): drop a waiting button click on logout or table switch A job can end minutes after the click, when its toast or Open URL no longer belongs to the page. * chore: drop the changelog entry for #6134 The button field has not shipped yet, so there is no fix to announce. * fix(database): point a click job at the base field A retype deletes the button row, so a job pointing at it had to be nulled first, and a click landing meanwhile failed the retype. * fix(database): keep a button spinning for its job after a reload The spinner only knew about clicks made in this page, so a reload dropped it while the job ran and a second click got the 409 toast. * fix(database): ignore a late job_started for a settled button click On a single worker the broadcast reaches the clicking tab after the job ended, and its started copy spun the button again until the next poll. * docs(database): correct the dispatch signal and e2e comments The signal's first send for a job click happens before the enqueue lock.
172 lines
5.3 KiB
JavaScript
172 lines
5.3 KiB
JavaScript
import { vi } from 'vitest'
|
|
import flushPromises from 'flush-promises'
|
|
import { TestApp } from '@baserow/test/helpers/testApp'
|
|
import RowCardFieldButtonField from '@baserow/modules/database/components/card/RowCardFieldButtonField'
|
|
|
|
describe('RowCardFieldButtonField', () => {
|
|
let testApp = null
|
|
let openUrlType = null
|
|
|
|
beforeEach(() => {
|
|
testApp = new TestApp()
|
|
openUrlType = testApp._app.$registry.get(
|
|
'databaseWorkflowActionType',
|
|
'open_url'
|
|
)
|
|
})
|
|
|
|
afterEach(async () => {
|
|
await testApp.afterEach()
|
|
vi.restoreAllMocks()
|
|
})
|
|
|
|
const field = {
|
|
id: 2,
|
|
type: 'button',
|
|
label: 'Open',
|
|
has_workflow_actions: true,
|
|
}
|
|
|
|
const mountCell = async (props = {}, responseData = {}, options = {}) => {
|
|
const wrapper = await testApp.mount(RowCardFieldButtonField, {
|
|
propsData: {
|
|
field,
|
|
value: null,
|
|
row: { id: 1, field_1: 'ada' },
|
|
...props,
|
|
},
|
|
...options,
|
|
})
|
|
wrapper.vm.$client.post = vi.fn().mockResolvedValue({
|
|
data: { results: [], client_actions: [], ...responseData },
|
|
})
|
|
return wrapper
|
|
}
|
|
|
|
test('a field without actions renders a disabled button and no link', async () => {
|
|
const wrapper = await mountCell({
|
|
field: { ...field, has_workflow_actions: false },
|
|
})
|
|
|
|
expect(wrapper.find('a').exists()).toBe(false)
|
|
const button = wrapper.find('button')
|
|
expect(button.attributes('disabled')).toBeDefined()
|
|
expect(button.text()).toBe('Open')
|
|
// Nothing to say, so the card keeps the pointer.
|
|
expect(button.element.parentElement.classList).not.toContain(
|
|
'forced-pointer-events-auto'
|
|
)
|
|
})
|
|
|
|
test('a user who may not click gets a disabled button that says so', async () => {
|
|
const hasPermission = vi.fn().mockReturnValue(false)
|
|
const wrapper = await mountCell(
|
|
{ workspaceId: 9 },
|
|
{},
|
|
{ global: { mocks: { $hasPermission: hasPermission } } }
|
|
)
|
|
|
|
const button = wrapper.find('button')
|
|
expect(button.attributes('disabled')).toBeDefined()
|
|
expect(hasPermission).toHaveBeenCalledWith(
|
|
'database.table.field.workflow_action.dispatch',
|
|
field,
|
|
9
|
|
)
|
|
// A card takes the pointer away from everything inside it, so the wrapper
|
|
// asks for it back to show the tooltip.
|
|
const wrapperElement = button.element.parentElement
|
|
expect(wrapperElement.classList).toContain('forced-pointer-events-auto')
|
|
expect(wrapperElement.tooltipOptions.value).toBe('buttonField.noPermission')
|
|
|
|
await button.trigger('click')
|
|
|
|
expect(wrapper.vm.$client.post).not.toHaveBeenCalled()
|
|
})
|
|
|
|
test('a field that needs reconfiguring renders a disabled button with a warning', async () => {
|
|
const wrapper = await mountCell({
|
|
field: { ...field, requires_reconfiguration: true },
|
|
})
|
|
|
|
const button = wrapper.find('button')
|
|
expect(button.attributes('disabled')).toBeDefined()
|
|
expect(wrapper.find('.iconoir-warning-triangle').exists()).toBe(true)
|
|
|
|
await button.trigger('click')
|
|
|
|
expect(wrapper.vm.$client.post).not.toHaveBeenCalled()
|
|
})
|
|
|
|
test('dispatches on click and runs the returned client actions', async () => {
|
|
const execute = vi.spyOn(openUrlType, 'execute').mockResolvedValue()
|
|
const action = {
|
|
id: 1,
|
|
type: 'open_url',
|
|
url: { formula: "'https://example.com'", mode: 'simple', version: 1 },
|
|
target: 'blank',
|
|
}
|
|
const wrapper = await mountCell({}, { client_actions: [action] })
|
|
|
|
await wrapper.find('button').trigger('click')
|
|
await wrapper.vm.$nextTick()
|
|
|
|
expect(wrapper.vm.$client.post).toHaveBeenCalledWith(
|
|
`database/field/${field.id}/workflow_actions/dispatch/`,
|
|
{ row_id: 1 },
|
|
{ omitWebSocketId: true }
|
|
)
|
|
expect(execute).toHaveBeenCalledTimes(1)
|
|
expect(execute.mock.calls[0][0].workflowAction).toEqual(action)
|
|
})
|
|
|
|
test('an accepted click waits on its job and then runs the client actions', async () => {
|
|
const execute = vi.spyOn(openUrlType, 'execute').mockResolvedValue()
|
|
const job = {
|
|
id: 7,
|
|
type: 'button_field_dispatch',
|
|
state: 'pending',
|
|
progress_percentage: 0,
|
|
human_readable_error: '',
|
|
results: null,
|
|
client_actions: null,
|
|
}
|
|
const action = {
|
|
id: 1,
|
|
type: 'open_url',
|
|
url: { formula: "'https://example.com'", mode: 'simple', version: 1 },
|
|
target: 'self',
|
|
}
|
|
const wrapper = await mountCell()
|
|
wrapper.vm.$client.post = vi
|
|
.fn()
|
|
.mockResolvedValue({ status: 202, data: job })
|
|
const store = wrapper.vm.$store
|
|
|
|
await wrapper.find('button').trigger('click')
|
|
await flushPromises()
|
|
|
|
// Still waiting: the spinner stays and nothing has run.
|
|
expect(wrapper.vm.dispatching).toBe(true)
|
|
expect(wrapper.find('button').classes()).toContain('button--loading')
|
|
expect(execute).not.toHaveBeenCalled()
|
|
expect(store.getters['job/get'](job.id)).toBeTruthy()
|
|
|
|
await store.dispatch('job/forceUpdate', {
|
|
job: store.getters['job/get'](job.id),
|
|
data: {
|
|
...job,
|
|
state: 'finished',
|
|
results: [],
|
|
client_actions: [action],
|
|
},
|
|
})
|
|
await flushPromises()
|
|
|
|
expect(wrapper.vm.dispatching).toBe(false)
|
|
expect(wrapper.find('button').classes()).not.toContain('button--loading')
|
|
expect(execute).toHaveBeenCalledTimes(1)
|
|
expect(execute.mock.calls[0][0].workflowAction).toEqual(action)
|
|
})
|
|
})
|