mirror of
https://github.com/baserow/baserow.git
synced 2026-12-05 16:58:36 +00:00
* Add ADR-013 for workspace level integrations * Add implementation * Improve context section and remove technical points * Move bulk replacement point to v2 * Remove workspace-level ownership on import since manual promotion should handle this. * Add a glossary section * Do Lazy creation + Celery migration * Remove demotion * Tighten the Options considered section * Add Decision describing where the integrations are managed * Update implementation plan after changes to ADR * Sync plan and adr * Rename adr and implementation * Add the shared application that owns workspace integrations * Create the shared application of every workspace * Let only workspace admins manage workspace integrations * Let applications use the integrations of their workspace. * Trash workspace integrations in their workspace. * Copy workspace integrations into exports and keep them in duplicates. * Workspace admins can share integrations with every application in the workspace. * Load the shared application of each workspace in the frontend and keep it out of application lists. * Manage workspace integrations from an Integrations page in workspace settings. * Offer workspace integrations in the integration dropdowns of every application. * Move promoted integrations to the workspace list in other open tabs. * Let admins make an app's integration available to the whole workspace from its integration settings. * Preselect a workspace integration for new nodes and data sources when the app has none of its own. * fix tests * Delete implementation file * More fixes after rebase * Fix tests * Let builders of an application see and use the workspace integrations from it. * Show the workspace integrations, read-only, in the integration settings of applications. * Keep a dashboard's integration out of promotion to the workspace. * Leave the shared applications out of the admin dashboard's application count. * Create the shared application of the workspaces made by the fill commands. * Say in the promotion modal that an integration nobody authorized will run as the promoting admin. * Say in the promotion modal that undoing it won't make the integration run as the previous person again. * Ignore integration ids in sample data when publishing copies the workspace integrations an app uses. * Let only undoing a promotion move an integration out of the workspace. * Let the shared application backfill stop itself after 5 minutes and skip workspaces another transaction has locked. * Say in the workspace integrations settings that published applications and workflows keep their own copy until they're published again. * Leave the shared application out of the assistant evals' application counts. * Refresh the workspace integrations when the Builder's data, events, users and integrations panels open. * Say that anything new using a promoted integration blocks undoing the promotion, even from its own application. * Warn when a database button sends through a workspace integration with no host or token. * Refuse roles and invitations on the shared application. * Fix tests * Show an application only the workspace integrations of types it can use. * Say in the promotion modal what builders of other applications can do as the integration. * Leave the shared application type out of the API docs for creating and updating applications. * Check who receives a workspace integration event in one permission call. * Say which workspaces have a shared application and who creates it. * Let a redone promotion record what uses the integration again. * Update docstrings * Stop template visitors from listing the integrations of the template's workspace. * Let database buttons find their own copy of a workspace integration after an import. * Say what holds the workspace row lock while a shared application is created. * Fix tests * Stop the workspace integration form component from being made reactive. * Make test runs use a new copy of the workflow after an integration it uses changes. * Hide the Members settings tab from members who can't list the workspace members. * Add changelog * Fix migration conflict * Fix migration conflict * Fix test * Update comments and ADR number * Link to the workspace integrations from the sidebar's Settings menu. * fix: refresh agent action errors when workspace integrations change * fix: move workspace integrations into workspace settings * fix: use share icon for workspace integration promotion * refactor: use explicit shared application relations * feat: centralize default integration selection * refactor: share integration change notifications * refactor: prepare integration mappings before import * refactor: collect integration references during export * refactor: prepare integration ownership changes without a new hook * test: restore registered service model after mocking * test: cover shared integration defaults in Builder * test: include Slack in Agent workspace integration choices * Fix migrations * Stop template visitors from listing the workspace integrations through an application of the template. * Only offer integrations of the user source's integration type when updating a user source. * Say the workspace integration copy means published Application Builder apps and automation workflows. * Use the same spacing under both integration settings sections and enlarge their headings. * Keep the shared application out of automatic snapshot schedules. * Fix test after rebase --------- Co-authored-by: Jeremie Pardou <571533+jrmi@users.noreply.github.com>
333 lines
9.5 KiB
JavaScript
333 lines
9.5 KiB
JavaScript
import { vi } from 'vitest'
|
|
import { reactive, nextTick } from 'vue'
|
|
import { TestApp } from '@baserow/test/helpers/testApp'
|
|
import { registerRealtimeEvents } from '@baserow/modules/builder/realtime'
|
|
import { mountSuspended } from '@nuxt/test-utils/runtime'
|
|
import WorkflowAction from '@baserow/modules/builder/components/event/WorkflowAction.vue'
|
|
|
|
describe('WorkflowAction', () => {
|
|
const mountComponent = ({ workflowActionType, workflowAction }) => {
|
|
const builder = { id: 1 }
|
|
const page = { id: 1 }
|
|
const workspace = { id: 1 }
|
|
const mode = 'editing'
|
|
const element = { id: 1 }
|
|
|
|
return mountSuspended(WorkflowAction, {
|
|
props: {
|
|
availableWorkflowActionTypes: [workflowActionType],
|
|
workflowAction,
|
|
element,
|
|
expanded: true,
|
|
},
|
|
global: {
|
|
provide: {
|
|
builder,
|
|
elementPage: page,
|
|
mode,
|
|
workspace,
|
|
applicationContext: { builder, page, mode, workspace },
|
|
},
|
|
stubs: {
|
|
SidebarExpandable: {
|
|
template: `
|
|
<section>
|
|
<slot name="title" />
|
|
<slot />
|
|
<slot name="footer" />
|
|
</section>
|
|
`,
|
|
},
|
|
SampleDataViewer: {
|
|
name: 'SampleDataViewer',
|
|
props: ['sampleData', 'isError', 'modalTitle', 'modalSubtitle'],
|
|
template: '<div class="sample-data-viewer" />',
|
|
},
|
|
ButtonText: {
|
|
template: '<button><slot /></button>',
|
|
},
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
test('shows list service sample data without throwing', async () => {
|
|
const workflowActionType = {
|
|
form: {
|
|
template: '<form />',
|
|
methods: {
|
|
isFormValid() {
|
|
return true
|
|
},
|
|
},
|
|
},
|
|
icon: 'iconoir-page',
|
|
label: 'Read xls file',
|
|
returnsList: () => true,
|
|
getType() {
|
|
return 'xls_file_reader'
|
|
},
|
|
getErrorMessage() {
|
|
return null
|
|
},
|
|
}
|
|
const results = [{ id: 1, name: 'First row' }]
|
|
|
|
const wrapper = await mountComponent({
|
|
workflowActionType,
|
|
workflowAction: {
|
|
id: 1,
|
|
type: 'xls_file_reader',
|
|
service: {
|
|
sample_data: {
|
|
data: {
|
|
results,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
})
|
|
|
|
expect(
|
|
wrapper.findComponent({ name: 'SampleDataViewer' }).props()
|
|
).toMatchObject({
|
|
sampleData: results,
|
|
isError: false,
|
|
})
|
|
})
|
|
|
|
// A form stub whose `reset()` re-reads the current `defaultValues` (like the real
|
|
// form mixin), and records that it was called. This lets us observe that the side
|
|
// panel calls `reset()` (rather than remounting) when a realtime change arrives.
|
|
const makeResetProbe = () => {
|
|
const resetSpy = vi.fn()
|
|
const workflowActionType = {
|
|
form: {
|
|
name: 'ActionFormStub',
|
|
props: ['defaultValues', 'workflowAction'],
|
|
data() {
|
|
return { snapshot: this.defaultValues?.value }
|
|
},
|
|
methods: {
|
|
isFormValid() {
|
|
return true
|
|
},
|
|
reset() {
|
|
resetSpy()
|
|
this.snapshot = this.defaultValues?.value
|
|
},
|
|
},
|
|
template: '<div class="form-value">{{ snapshot }}</div>',
|
|
},
|
|
getType() {
|
|
return 'probe'
|
|
},
|
|
getErrorMessage() {
|
|
return null
|
|
},
|
|
}
|
|
return { workflowActionType, resetSpy }
|
|
}
|
|
|
|
test('resets the form when the action changes via realtime (undo/redo)', async () => {
|
|
// Mirrors the real app: the realtime `forceUpdate` mutates the same store
|
|
// object in place (bumping `_.realtimeVersion`), rather than replacing it.
|
|
const { workflowActionType, resetSpy } = makeResetProbe()
|
|
const workflowAction = reactive({
|
|
id: 1,
|
|
type: 'probe',
|
|
value: 'a',
|
|
_: { viaRealtime: false, realtimeVersion: 0 },
|
|
})
|
|
const wrapper = await mountComponent({ workflowActionType, workflowAction })
|
|
expect(wrapper.find('.form-value').text()).toBe('a')
|
|
|
|
// Apply an undo/redo as the store mutation would: in place, same object.
|
|
workflowAction.value = 'b'
|
|
workflowAction._.viaRealtime = true
|
|
workflowAction._.realtimeVersion = 1
|
|
await wrapper.vm.$nextTick()
|
|
|
|
// The panel called reset(), so the form re-read the new default value.
|
|
expect(resetSpy).toHaveBeenCalled()
|
|
expect(wrapper.find('.form-value').text()).toBe('b')
|
|
})
|
|
|
|
test('does not reset the form on a local (non-realtime) update', async () => {
|
|
const { workflowActionType, resetSpy } = makeResetProbe()
|
|
const workflowAction = reactive({
|
|
id: 1,
|
|
type: 'probe',
|
|
value: 'a',
|
|
_: { viaRealtime: false, realtimeVersion: 0 },
|
|
})
|
|
const wrapper = await mountComponent({ workflowActionType, workflowAction })
|
|
expect(wrapper.find('.form-value').text()).toBe('a')
|
|
|
|
// A local edit does not change realtimeVersion, so the form is not reset.
|
|
workflowAction.value = 'b'
|
|
await wrapper.vm.$nextTick()
|
|
|
|
expect(resetSpy).not.toHaveBeenCalled()
|
|
expect(wrapper.find('.form-value').text()).toBe('a')
|
|
})
|
|
|
|
test('does not reset when viaRealtime is stale but the version has not advanced', async () => {
|
|
// Guards against relying on `viaRealtime` alone: it stays set until the next
|
|
// local edit, so a reset must only happen when the version actually advances.
|
|
const { workflowActionType, resetSpy } = makeResetProbe()
|
|
const workflowAction = reactive({
|
|
id: 1,
|
|
type: 'probe',
|
|
value: 'a',
|
|
_: { viaRealtime: true, realtimeVersion: 3 },
|
|
})
|
|
const wrapper = await mountComponent({ workflowActionType, workflowAction })
|
|
|
|
// `viaRealtime` flips to true again, but the version is unchanged.
|
|
workflowAction._.viaRealtime = true
|
|
await wrapper.vm.$nextTick()
|
|
|
|
expect(resetSpy).not.toHaveBeenCalled()
|
|
})
|
|
})
|
|
|
|
describe('WorkflowAction integration lifecycle', () => {
|
|
let testApp
|
|
beforeEach(() => {
|
|
testApp = new TestApp()
|
|
})
|
|
afterEach(async () => {
|
|
await testApp.afterEach()
|
|
})
|
|
|
|
test.each([false, true])(
|
|
'refreshes the warning for a shared=%s integration without reopening the action',
|
|
async (shared) => {
|
|
const store = testApp.store
|
|
const workspace = { id: 1 }
|
|
await store.dispatch('workspace/forceCreate', {
|
|
...workspace,
|
|
name: 'Acme',
|
|
})
|
|
await store.dispatch('application/forceCreate', {
|
|
id: 1,
|
|
type: 'builder',
|
|
name: 'App',
|
|
pages: [],
|
|
workspace,
|
|
order: 0,
|
|
})
|
|
await store.dispatch('application/forceCreate', {
|
|
id: 99,
|
|
type: 'shared',
|
|
name: '__shared__',
|
|
workspace,
|
|
order: 0,
|
|
})
|
|
const builder = store.getters['application/get'](1)
|
|
const owner = store.getters['application/get'](shared ? 99 : 1)
|
|
const integration = {
|
|
id: 5,
|
|
type: 'local_baserow',
|
|
application_id: owner.id,
|
|
name: 'Tables',
|
|
authorized_subject: { id: 1, type: 'auth.User' },
|
|
}
|
|
await store.dispatch('integration/forceCreate', {
|
|
application: owner,
|
|
integration,
|
|
})
|
|
const workflowActionType = testApp
|
|
.getRegistry()
|
|
.get('workflowAction', 'create_row')
|
|
const wrapper = await testApp.mount(WorkflowAction, {
|
|
props: {
|
|
availableWorkflowActionTypes: [workflowActionType],
|
|
workflowAction: {
|
|
id: 1,
|
|
type: 'create_row',
|
|
service: { integration_id: 5, table_id: 99 },
|
|
},
|
|
element: { id: 1 },
|
|
},
|
|
provide: {
|
|
builder,
|
|
workspace,
|
|
elementPage: { id: 1 },
|
|
mode: 'editing',
|
|
applicationContext: { builder, workspace, mode: 'editing' },
|
|
},
|
|
global: {
|
|
stubs: {
|
|
SidebarExpandable: {
|
|
template: '<section><slot name="title" /></section>',
|
|
},
|
|
Icon: { props: ['icon'], template: '<i :data-icon="icon" />' },
|
|
},
|
|
},
|
|
})
|
|
const warning = () =>
|
|
wrapper.find('[data-icon="iconoir-warning-circle"]').exists()
|
|
const handlers = {}
|
|
registerRealtimeEvents({
|
|
registerEvent: (name, callback) => {
|
|
handlers[name] = callback
|
|
},
|
|
})
|
|
expect(warning()).toBe(false)
|
|
|
|
handlers.integration_deleted(
|
|
{ store },
|
|
{ integration_id: 5, application_id: owner.id }
|
|
)
|
|
await nextTick()
|
|
expect(warning()).toBe(true)
|
|
|
|
handlers.integration_created({ store }, { integration })
|
|
await nextTick()
|
|
expect(warning()).toBe(false)
|
|
|
|
handlers.integration_updated(
|
|
{ store },
|
|
{ integration: { ...integration, authorized_subject: null } }
|
|
)
|
|
await nextTick()
|
|
expect(warning()).toBe(true)
|
|
|
|
handlers.integration_updated(
|
|
{ store },
|
|
{
|
|
integration: {
|
|
...integration,
|
|
authorized_subject: { id: 1, type: 'auth.User' },
|
|
},
|
|
}
|
|
)
|
|
await nextTick()
|
|
expect(warning()).toBe(false)
|
|
|
|
if (shared) {
|
|
// It now belongs to another app, so this builder must stop using it.
|
|
handlers.integration_updated(
|
|
{ store },
|
|
{
|
|
integration: { ...integration, application_id: 300 },
|
|
}
|
|
)
|
|
await nextTick()
|
|
expect(warning()).toBe(true)
|
|
|
|
handlers.integration_updated(
|
|
{ store },
|
|
{
|
|
integration: { ...integration, application_id: owner.id },
|
|
}
|
|
)
|
|
await nextTick()
|
|
expect(warning()).toBe(false)
|
|
}
|
|
}
|
|
)
|
|
})
|