mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 00:08:25 +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>
567 lines
15 KiB
JavaScript
567 lines
15 KiB
JavaScript
import { defineComponent, nextTick } from 'vue'
|
|
import { mountSuspended } from '@nuxt/test-utils/runtime'
|
|
import { flushPromises } from '@vue/test-utils'
|
|
import { DataProviderType } from '@baserow/modules/core/dataProviderTypes'
|
|
|
|
import DataSourceForm from '@baserow/modules/builder/components/dataSource/DataSourceForm'
|
|
import { CoreHTTPDataSourceServiceType } from '@baserow/modules/integrations/core/serviceTypes'
|
|
|
|
const FormGroupStub = defineComponent({
|
|
name: 'FormGroup',
|
|
template: '<div><slot /></div>',
|
|
})
|
|
|
|
const FormInputStub = defineComponent({
|
|
name: 'FormInput',
|
|
props: {
|
|
modelValue: {
|
|
type: String,
|
|
required: false,
|
|
default: '',
|
|
},
|
|
},
|
|
emits: ['update:modelValue', 'blur'],
|
|
template: '<input :value="modelValue" />',
|
|
})
|
|
|
|
const GroupedDropdownStub = defineComponent({
|
|
name: 'GroupedDropdown',
|
|
props: {
|
|
modelValue: {
|
|
type: String,
|
|
required: false,
|
|
default: null,
|
|
},
|
|
items: {
|
|
type: Array,
|
|
required: true,
|
|
},
|
|
placeholder: {
|
|
type: String,
|
|
required: false,
|
|
default: '',
|
|
},
|
|
searchPlaceholder: {
|
|
type: String,
|
|
required: false,
|
|
default: '',
|
|
},
|
|
emptyText: {
|
|
type: String,
|
|
required: false,
|
|
default: '',
|
|
},
|
|
panelHeight: {
|
|
type: String,
|
|
required: false,
|
|
default: null,
|
|
},
|
|
},
|
|
emits: ['update:modelValue'],
|
|
template: '<div class="grouped-dropdown-stub" />',
|
|
})
|
|
|
|
const IntegrationDropdownStub = defineComponent({
|
|
name: 'IntegrationDropdown',
|
|
props: {
|
|
modelValue: {
|
|
type: Number,
|
|
required: false,
|
|
default: null,
|
|
},
|
|
application: {
|
|
type: Object,
|
|
required: true,
|
|
},
|
|
integrations: {
|
|
type: Array,
|
|
required: true,
|
|
},
|
|
integrationType: {
|
|
type: Object,
|
|
required: false,
|
|
default: null,
|
|
},
|
|
disabled: {
|
|
type: Boolean,
|
|
required: false,
|
|
default: false,
|
|
},
|
|
placeholder: {
|
|
type: String,
|
|
required: false,
|
|
default: '',
|
|
},
|
|
},
|
|
emits: ['update:modelValue'],
|
|
template: '<div class="integration-dropdown-stub" />',
|
|
})
|
|
|
|
const localBaserowIntegrationType = {
|
|
name: 'Local Baserow',
|
|
image: '/local-baserow.svg',
|
|
iconClass: 'iconoir-database',
|
|
iconColor: 'darker-blue',
|
|
getType: () => 'local_baserow',
|
|
}
|
|
|
|
const otherIntegrationType = {
|
|
name: 'Other',
|
|
image: '/other.svg',
|
|
getType: () => 'other',
|
|
}
|
|
|
|
const serviceType = {
|
|
name: 'Get row',
|
|
icon: 'iconoir-pin',
|
|
iconColor: 'darker-blue',
|
|
description: 'Reads a row from a Baserow table.',
|
|
integrationType: localBaserowIntegrationType,
|
|
isDataSource: true,
|
|
formComponent: null,
|
|
getType: () => 'local_baserow_get_row',
|
|
isDeactivatedReason: () => null,
|
|
}
|
|
|
|
const httpGroup = {
|
|
id: 'http',
|
|
label: 'HTTP',
|
|
icon: 'iconoir-globe',
|
|
iconColor: 'muted-cyan',
|
|
}
|
|
|
|
const ServiceFormStub = defineComponent({
|
|
name: 'ServiceForm',
|
|
template: '<div class="service-form-stub" />',
|
|
})
|
|
|
|
const httpServiceType = {
|
|
name: 'HTTP request',
|
|
icon: 'iconoir-globe',
|
|
iconColor: 'muted-cyan',
|
|
description: 'Fetches data from a URL.',
|
|
integrationType: null,
|
|
group: httpGroup,
|
|
isDataSource: true,
|
|
canBeTested: true,
|
|
formComponent: ServiceFormStub,
|
|
getType: () => 'http_get',
|
|
isDeactivatedReason: () => null,
|
|
}
|
|
|
|
const hiddenServiceType = {
|
|
name: 'Read a CSV file',
|
|
icon: 'iconoir-page',
|
|
iconColor: 'muted-yellow',
|
|
description: 'Reads rows from a CSV file.',
|
|
integrationType: null,
|
|
group: { id: 'files', label: 'Files' },
|
|
isDataSource: true,
|
|
hiddenInDataSourcePicker: true,
|
|
formComponent: null,
|
|
getType: () => 'csv_file_reader',
|
|
isDeactivatedReason: () => null,
|
|
}
|
|
|
|
const BUILDER_ID = 1
|
|
// The shared application owning the workspace integrations.
|
|
const SHARED_APPLICATION_ID = 99
|
|
|
|
async function mountComponent({
|
|
serviceTypes = [serviceType],
|
|
create = true,
|
|
dataSource = {},
|
|
defaultValues = {},
|
|
storeDispatch = () => Promise.resolve(),
|
|
integrations = [
|
|
{ id: 1, type: 'local_baserow', application_id: BUILDER_ID },
|
|
{ id: 2, type: 'other', application_id: BUILDER_ID },
|
|
],
|
|
} = {}) {
|
|
const registry = {
|
|
getOrderedList(namespace) {
|
|
return namespace === 'service'
|
|
? serviceTypes
|
|
: [localBaserowIntegrationType, otherIntegrationType]
|
|
},
|
|
get(namespace, type) {
|
|
if (namespace === 'service') {
|
|
return serviceTypes.find((s) => s.getType() === type) || null
|
|
}
|
|
return null
|
|
},
|
|
}
|
|
|
|
return await mountSuspended(DataSourceForm, {
|
|
props: {
|
|
builder: { id: BUILDER_ID, workspace: { id: 1 } },
|
|
page: { id: 1 },
|
|
integrations,
|
|
create,
|
|
dataSource,
|
|
defaultValues,
|
|
},
|
|
global: {
|
|
provide: {
|
|
applicationContext: {},
|
|
},
|
|
stubs: {
|
|
FormGroup: FormGroupStub,
|
|
FormInput: FormInputStub,
|
|
IntegrationDropdown: IntegrationDropdownStub,
|
|
GroupedDropdown: GroupedDropdownStub,
|
|
DataSourceTestForm: {
|
|
name: 'DataSourceTestForm',
|
|
inject: ['dataSourceTest'],
|
|
template:
|
|
'<div class="data-source-test-form-stub" @click="dataSourceTest.test()" />',
|
|
},
|
|
},
|
|
mocks: {
|
|
$registry: registry,
|
|
$store: {
|
|
getters: {
|
|
'dataSource/getPageDataSources': () => [],
|
|
},
|
|
dispatch: storeDispatch,
|
|
},
|
|
$t: (key) => key,
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
describe('DataSourceForm', () => {
|
|
test('groups service types under their integration type', async () => {
|
|
const wrapper = await mountComponent()
|
|
const actionDropdown = wrapper.findComponent(GroupedDropdownStub)
|
|
|
|
expect(actionDropdown.props('panelHeight')).toBe('240px')
|
|
expect(actionDropdown.props('items')).toEqual([
|
|
{
|
|
id: 'integration-local_baserow',
|
|
label: 'Local Baserow',
|
|
image: '/local-baserow.svg',
|
|
icon: 'iconoir-database',
|
|
iconColor: 'darker-blue',
|
|
children: [
|
|
{
|
|
id: 'service-local_baserow_get_row',
|
|
label: 'Get row',
|
|
value: 'local_baserow_get_row',
|
|
icon: 'iconoir-pin',
|
|
iconColor: 'darker-blue',
|
|
description: 'Reads a row from a Baserow table.',
|
|
disabled: false,
|
|
disabledReason: null,
|
|
},
|
|
],
|
|
order: 0,
|
|
},
|
|
])
|
|
})
|
|
|
|
test('filters and auto-selects connections for the selected action', async () => {
|
|
const wrapper = await mountComponent()
|
|
|
|
wrapper
|
|
.findComponent(GroupedDropdownStub)
|
|
.vm.$emit('update:modelValue', serviceType.getType())
|
|
await nextTick()
|
|
|
|
const connectionDropdown = wrapper.findComponent(IntegrationDropdownStub)
|
|
expect(connectionDropdown.props('integrations')).toEqual([
|
|
{ id: 1, type: 'local_baserow', application_id: BUILDER_ID },
|
|
])
|
|
expect(connectionDropdown.props('modelValue')).toBe(1)
|
|
})
|
|
|
|
async function selectServiceType(wrapper) {
|
|
wrapper
|
|
.findComponent(GroupedDropdownStub)
|
|
.vm.$emit('update:modelValue', serviceType.getType())
|
|
await nextTick()
|
|
return wrapper.findComponent(IntegrationDropdownStub).props('modelValue')
|
|
}
|
|
|
|
const own = (id) => ({
|
|
id,
|
|
type: 'local_baserow',
|
|
application_id: BUILDER_ID,
|
|
})
|
|
const ofWorkspace = (id) => ({
|
|
id,
|
|
type: 'local_baserow',
|
|
application_id: SHARED_APPLICATION_ID,
|
|
})
|
|
|
|
test.each([
|
|
['own integration', [ofWorkspace(3), own(1)], 1],
|
|
['only workspace integration', [ofWorkspace(3)], 3],
|
|
[
|
|
'ambiguous workspace integrations',
|
|
[ofWorkspace(3), ofWorkspace(4)],
|
|
null,
|
|
],
|
|
])(
|
|
'handles a late integration response: %s',
|
|
async (_, integrations, expected) => {
|
|
const wrapper = await mountComponent({ integrations: [] })
|
|
expect(await selectServiceType(wrapper)).toBe(null)
|
|
|
|
await wrapper.setProps({ integrations })
|
|
|
|
expect(
|
|
wrapper.findComponent(IntegrationDropdownStub).props('modelValue')
|
|
).toBe(expected)
|
|
}
|
|
)
|
|
|
|
test('keeps a manual choice when the integration list refreshes', async () => {
|
|
const wrapper = await mountComponent({
|
|
integrations: [ofWorkspace(3), ofWorkspace(4)],
|
|
})
|
|
await selectServiceType(wrapper)
|
|
wrapper
|
|
.findComponent(IntegrationDropdownStub)
|
|
.vm.$emit('update:modelValue', 4)
|
|
await nextTick()
|
|
|
|
await wrapper.setProps({
|
|
integrations: [own(1), ofWorkspace(3), ofWorkspace(4)],
|
|
})
|
|
|
|
expect(
|
|
wrapper.findComponent(IntegrationDropdownStub).props('modelValue')
|
|
).toBe(4)
|
|
})
|
|
|
|
test('does not silently repair an existing source when integrations finish loading', async () => {
|
|
const wrapper = await mountComponent({
|
|
create: false,
|
|
integrations: [],
|
|
defaultValues: { type: serviceType.getType(), integration_id: null },
|
|
})
|
|
|
|
await wrapper.setProps({ integrations: [own(1)] })
|
|
|
|
expect(
|
|
wrapper.findComponent(IntegrationDropdownStub).props('modelValue')
|
|
).toBe(null)
|
|
})
|
|
|
|
test('auto-selects the builder connection before a workspace one', async () => {
|
|
const wrapper = await mountComponent({
|
|
integrations: [ofWorkspace(3), own(1)],
|
|
})
|
|
|
|
expect(await selectServiceType(wrapper)).toBe(1)
|
|
})
|
|
|
|
test('auto-selects the only workspace connection when the builder has none', async () => {
|
|
const wrapper = await mountComponent({
|
|
integrations: [ofWorkspace(3), { ...own(2), type: 'other' }],
|
|
})
|
|
|
|
expect(await selectServiceType(wrapper)).toBe(3)
|
|
})
|
|
|
|
test.each([
|
|
['of the builder', [own(1), own(2), ofWorkspace(3)]],
|
|
['of the workspace', [ofWorkspace(3), ofWorkspace(4)]],
|
|
])(
|
|
'auto-selects nothing when several connections %s fit',
|
|
async (_, integrations) => {
|
|
const wrapper = await mountComponent({ integrations })
|
|
|
|
expect(await selectServiceType(wrapper)).toBe(null)
|
|
}
|
|
)
|
|
|
|
test('keeps a selected workspace connection that fits the new action', async () => {
|
|
const wrapper = await mountComponent({
|
|
integrations: [own(1), ofWorkspace(3)],
|
|
defaultValues: { integration_id: 3 },
|
|
})
|
|
|
|
expect(await selectServiceType(wrapper)).toBe(3)
|
|
})
|
|
|
|
test('groups service types without an integration under their own group', async () => {
|
|
const wrapper = await mountComponent({
|
|
serviceTypes: [serviceType, httpServiceType, hiddenServiceType],
|
|
})
|
|
const items = wrapper.findComponent(GroupedDropdownStub).props('items')
|
|
|
|
// The menu sorts groups by order before label, so Local Baserow stays
|
|
// above HTTP.
|
|
expect(items.map(({ id, order }) => [id, order])).toEqual([
|
|
['integration-local_baserow', 0],
|
|
['http', 1],
|
|
])
|
|
expect(items[1]).toEqual({
|
|
id: 'http',
|
|
label: 'HTTP',
|
|
image: undefined,
|
|
icon: 'iconoir-globe',
|
|
iconColor: 'muted-cyan',
|
|
children: [
|
|
{
|
|
id: 'service-http_get',
|
|
label: 'HTTP request',
|
|
value: 'http_get',
|
|
icon: 'iconoir-globe',
|
|
iconColor: 'muted-cyan',
|
|
description: 'Fetches data from a URL.',
|
|
disabled: false,
|
|
disabledReason: null,
|
|
},
|
|
],
|
|
order: 1,
|
|
})
|
|
})
|
|
|
|
test('hides the connection dropdown for a service without an integration', async () => {
|
|
const wrapper = await mountComponent({
|
|
serviceTypes: [serviceType, httpServiceType],
|
|
})
|
|
expect(wrapper.findComponent(IntegrationDropdownStub).exists()).toBe(true)
|
|
|
|
wrapper
|
|
.findComponent(GroupedDropdownStub)
|
|
.vm.$emit('update:modelValue', httpServiceType.getType())
|
|
await nextTick()
|
|
|
|
expect(wrapper.findComponent(IntegrationDropdownStub).exists()).toBe(false)
|
|
})
|
|
|
|
test('shows the service and test forms of a data source without an integration', async () => {
|
|
const dataSource = {
|
|
id: 3,
|
|
name: 'Products',
|
|
type: 'http_get',
|
|
integration_id: null,
|
|
}
|
|
const wrapper = await mountComponent({
|
|
serviceTypes: [serviceType, httpServiceType],
|
|
create: false,
|
|
dataSource,
|
|
defaultValues: dataSource,
|
|
})
|
|
await nextTick()
|
|
|
|
expect(wrapper.find('.service-form-stub').exists()).toBe(true)
|
|
expect(wrapper.find('.data-source-test-form-stub').exists()).toBe(true)
|
|
})
|
|
|
|
describe('with the HTTP request type', () => {
|
|
const app = {
|
|
$i18n: { t: (key) => key },
|
|
$registry: { get: () => ({}) },
|
|
}
|
|
const httpTypes = () => [new CoreHTTPDataSourceServiceType({ app })]
|
|
|
|
test('the picker shows the HTTP request entry', async () => {
|
|
const wrapper = await mountComponent({ serviceTypes: httpTypes() })
|
|
const items = wrapper.findComponent(GroupedDropdownStub).props('items')
|
|
|
|
expect(items).toHaveLength(1)
|
|
expect(items[0].id).toBe('http')
|
|
expect(items[0].children.map(({ value }) => value)).toEqual(['http_get'])
|
|
})
|
|
|
|
test('a list data source is shown as the HTTP request entry', async () => {
|
|
const dataSource = {
|
|
id: 3,
|
|
name: 'Products',
|
|
type: 'http_get',
|
|
returns_list: true,
|
|
integration_id: null,
|
|
}
|
|
const wrapper = await mountComponent({
|
|
serviceTypes: httpTypes(),
|
|
create: false,
|
|
dataSource,
|
|
defaultValues: dataSource,
|
|
})
|
|
await nextTick()
|
|
|
|
expect(
|
|
wrapper.findComponent(GroupedDropdownStub).props('modelValue')
|
|
).toBe('http_get')
|
|
expect(wrapper.find('.data-source-test-form-stub').exists()).toBe(true)
|
|
})
|
|
})
|
|
|
|
test('saves unsaved changes before testing', async () => {
|
|
const EditableServiceFormStub = defineComponent({
|
|
name: 'EditableServiceForm',
|
|
data: () => ({ values: { url: { formula: '', mode: 'simple' } } }),
|
|
methods: {
|
|
getFormValues() {
|
|
return { ...this.values }
|
|
},
|
|
isFormValid() {
|
|
return true
|
|
},
|
|
},
|
|
template: '<div class="editable-service-form-stub" />',
|
|
})
|
|
const dataSource = {
|
|
id: 3,
|
|
name: 'Products',
|
|
type: 'http_get',
|
|
integration_id: null,
|
|
url: { formula: '', mode: 'simple' },
|
|
}
|
|
// The form saves through its own store, the test dispatches through the
|
|
// app's.
|
|
const dispatch = vi.fn().mockResolvedValue({})
|
|
const simulateDispatch = vi
|
|
.spyOn(useNuxtApp().$store, 'dispatch')
|
|
.mockResolvedValue({})
|
|
vi.spyOn(
|
|
DataProviderType,
|
|
'getAllDataSourceDispatchContext'
|
|
).mockReturnValue({})
|
|
|
|
const wrapper = await mountComponent({
|
|
serviceTypes: [
|
|
{ ...httpServiceType, formComponent: EditableServiceFormStub },
|
|
],
|
|
create: false,
|
|
dataSource,
|
|
defaultValues: dataSource,
|
|
storeDispatch: dispatch,
|
|
})
|
|
await nextTick()
|
|
|
|
// Nothing changed, so nothing is saved before the test.
|
|
await wrapper.find('.data-source-test-form-stub').trigger('click')
|
|
await flushPromises()
|
|
expect(dispatch).not.toHaveBeenCalled()
|
|
expect(simulateDispatch).toHaveBeenCalledTimes(1)
|
|
expect(wrapper.emitted('saved')).toBeUndefined()
|
|
|
|
wrapper.findComponent(EditableServiceFormStub).vm.values.url = {
|
|
formula: 'https://httpbin.org/get',
|
|
mode: 'simple',
|
|
}
|
|
await wrapper.find('.data-source-test-form-stub').trigger('click')
|
|
await flushPromises()
|
|
|
|
expect(dispatch).toHaveBeenCalledWith('dataSource/update', {
|
|
page: { id: 1 },
|
|
dataSourceId: 3,
|
|
values: { url: { formula: 'https://httpbin.org/get', mode: 'simple' } },
|
|
})
|
|
// So that the elements using the data source show what it now returns.
|
|
expect(wrapper.emitted('saved')).toHaveLength(1)
|
|
expect(simulateDispatch).toHaveBeenLastCalledWith(
|
|
'dataSource/simulateDispatch',
|
|
{ page: { id: 1 }, dataSourceId: 3, dispatchContext: {} }
|
|
)
|
|
vi.restoreAllMocks()
|
|
})
|
|
})
|