mirror of
https://github.com/baserow/baserow.git
synced 2026-12-05 00:38:35 +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>
376 lines
10 KiB
JavaScript
376 lines
10 KiB
JavaScript
import { defineComponent, h, nextTick } from 'vue'
|
|
import { mountSuspended } from '@nuxt/test-utils/runtime'
|
|
import { vi } from 'vitest'
|
|
|
|
import CoreSMTPEmailServiceForm from '@baserow/modules/integrations/core/components/services/CoreSMTPEmailServiceForm'
|
|
import { flushPromises } from '@vue/test-utils'
|
|
|
|
const FormGroupStub = defineComponent({
|
|
name: 'FormGroup',
|
|
inheritAttrs: false,
|
|
template: '<div v-bind="$attrs"><slot /></div>',
|
|
})
|
|
|
|
const InjectedFormulaInputStub = defineComponent({
|
|
name: 'InjectedFormulaInput',
|
|
props: {
|
|
modelValue: {
|
|
type: [Object, String],
|
|
required: false,
|
|
default: undefined,
|
|
},
|
|
placeholder: {
|
|
type: String,
|
|
required: false,
|
|
default: '',
|
|
},
|
|
enabledModes: {
|
|
type: Array,
|
|
required: false,
|
|
default: () => [],
|
|
},
|
|
textarea: {
|
|
type: Boolean,
|
|
required: false,
|
|
default: false,
|
|
},
|
|
},
|
|
template: `
|
|
<div
|
|
:modelvalue="modelValue"
|
|
:placeholder="placeholder"
|
|
:enabled-modes="enabledModes.length ? enabledModes.join(',') : undefined"
|
|
:textarea="textarea ? '' : undefined"
|
|
/>
|
|
`,
|
|
})
|
|
|
|
const IntegrationDropdownStub = defineComponent({
|
|
name: 'IntegrationDropdown',
|
|
emits: ['update:modelValue'],
|
|
props: {
|
|
modelValue: {
|
|
type: Number,
|
|
required: false,
|
|
default: null,
|
|
},
|
|
application: {
|
|
type: Object,
|
|
required: true,
|
|
},
|
|
integrations: {
|
|
type: Array,
|
|
required: true,
|
|
},
|
|
integrationType: {
|
|
type: Object,
|
|
required: true,
|
|
},
|
|
allowEditing: {
|
|
type: Boolean,
|
|
required: false,
|
|
default: false,
|
|
},
|
|
},
|
|
render() {
|
|
return h(
|
|
'div',
|
|
{
|
|
modelvalue: this.modelValue,
|
|
application: this.application,
|
|
integrations: this.integrations,
|
|
'integration-type': this.integrationType,
|
|
},
|
|
this.integrations.length
|
|
? this.integrations.map((integration) =>
|
|
h(
|
|
'button',
|
|
{
|
|
onClick: () => this.$emit('update:modelValue', integration.id),
|
|
},
|
|
String(integration.id)
|
|
)
|
|
)
|
|
: undefined
|
|
)
|
|
},
|
|
})
|
|
|
|
const DropdownStub = defineComponent({
|
|
name: 'Dropdown',
|
|
props: {
|
|
modelValue: {
|
|
type: String,
|
|
required: false,
|
|
default: '',
|
|
},
|
|
},
|
|
template: '<div :modelvalue="modelValue"><slot /></div>',
|
|
})
|
|
|
|
const DropdownItemStub = defineComponent({
|
|
name: 'DropdownItem',
|
|
props: {
|
|
name: {
|
|
type: String,
|
|
required: true,
|
|
},
|
|
value: {
|
|
type: String,
|
|
required: true,
|
|
},
|
|
},
|
|
template: '<div :name="name" :value="value" />',
|
|
})
|
|
|
|
const defaultService = {
|
|
instance_smtp_settings_enabled: true,
|
|
}
|
|
|
|
async function mountComponent({
|
|
service = defaultService,
|
|
defaultValues = service,
|
|
integrations = [],
|
|
application = { id: 1 },
|
|
props = {},
|
|
} = {}) {
|
|
return await mountSuspended(CoreSMTPEmailServiceForm, {
|
|
props: {
|
|
application,
|
|
service,
|
|
defaultValues,
|
|
...props,
|
|
},
|
|
global: {
|
|
stubs: {
|
|
FormGroup: FormGroupStub,
|
|
InjectedFormulaInput: InjectedFormulaInputStub,
|
|
IntegrationDropdown: IntegrationDropdownStub,
|
|
Dropdown: DropdownStub,
|
|
DropdownItem: DropdownItemStub,
|
|
},
|
|
mocks: {
|
|
$t: (key) => key,
|
|
$store: {
|
|
getters: {
|
|
'integration/getUsableIntegrations': () => integrations,
|
|
},
|
|
},
|
|
$registry: {
|
|
get: vi.fn(() => ({ type: 'smtp' })),
|
|
},
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
describe('Core SMTP email service form', () => {
|
|
test('defaults to instance SMTP settings when available without an existing custom SMTP configuration', async () => {
|
|
const wrapper = await mountComponent()
|
|
|
|
expect(wrapper.element).toMatchSnapshot()
|
|
})
|
|
|
|
test('defaults to instance SMTP settings when available even if custom SMTP fields already exist', async () => {
|
|
const wrapper = await mountComponent({
|
|
service: {
|
|
...defaultService,
|
|
from_email: {
|
|
formula: "'from@example.com'",
|
|
},
|
|
},
|
|
defaultValues: {
|
|
...defaultService,
|
|
from_email: {
|
|
formula: "'from@example.com'",
|
|
},
|
|
},
|
|
})
|
|
|
|
expect(wrapper.element).toMatchSnapshot()
|
|
})
|
|
|
|
test('defaults to instance SMTP settings when available even if an SMTP integration is already selected', async () => {
|
|
const wrapper = await mountComponent({
|
|
service: {
|
|
...defaultService,
|
|
integration_id: 123,
|
|
},
|
|
defaultValues: {
|
|
...defaultService,
|
|
integration_id: 123,
|
|
},
|
|
})
|
|
|
|
expect(wrapper.element).toMatchSnapshot()
|
|
})
|
|
|
|
test('does not default to instance SMTP settings when custom SMTP mode was explicitly selected', async () => {
|
|
const wrapper = await mountComponent({
|
|
service: {
|
|
...defaultService,
|
|
use_instance_smtp_settings: false,
|
|
integration_id: 123,
|
|
from_email: {
|
|
formula: "'from@example.com'",
|
|
},
|
|
},
|
|
defaultValues: {
|
|
...defaultService,
|
|
use_instance_smtp_settings: false,
|
|
integration_id: 123,
|
|
from_email: {
|
|
formula: "'from@example.com'",
|
|
},
|
|
},
|
|
})
|
|
|
|
expect(wrapper.element).toMatchSnapshot()
|
|
})
|
|
|
|
test('shows custom SMTP fields when instance SMTP is unchecked', async () => {
|
|
const wrapper = await mountComponent()
|
|
|
|
await wrapper.find('input[type="checkbox"]').trigger('click')
|
|
await nextTick()
|
|
|
|
expect(wrapper.element).toMatchSnapshot()
|
|
})
|
|
|
|
test('only passes SMTP integrations to the integration dropdown', async () => {
|
|
const smtpIntegration = { id: 1, type: 'smtp' }
|
|
const wrapper = await mountComponent({
|
|
service: {
|
|
instance_smtp_settings_enabled: false,
|
|
},
|
|
defaultValues: {
|
|
instance_smtp_settings_enabled: false,
|
|
},
|
|
integrations: [smtpIntegration, { id: 2, type: 'slack' }],
|
|
})
|
|
|
|
expect(
|
|
wrapper.findComponent(IntegrationDropdownStub).props('integrations')
|
|
).toEqual([smtpIntegration])
|
|
})
|
|
|
|
test('an explicit instance flag wins over the service', async () => {
|
|
// A button action being added has no saved service to carry the flag.
|
|
const wrapper = await mountComponent({
|
|
service: { instance_smtp_settings_enabled: true },
|
|
props: { instanceSmtpAvailable: false },
|
|
})
|
|
|
|
expect(wrapper.find('input[type="checkbox"]').exists()).toBe(false)
|
|
expect(wrapper.findComponent(IntegrationDropdownStub).exists()).toBe(true)
|
|
})
|
|
|
|
test('with the instance available, the choice is offered', async () => {
|
|
const wrapper = await mountComponent({
|
|
service: {},
|
|
defaultValues: { use_instance_smtp_settings: true },
|
|
props: { instanceSmtpAvailable: true },
|
|
})
|
|
|
|
expect(wrapper.find('input[type="checkbox"]').exists()).toBe(true)
|
|
expect(wrapper.findComponent(IntegrationDropdownStub).exists()).toBe(false)
|
|
})
|
|
|
|
test('a stale instance choice offers the integration without changing it', async () => {
|
|
// Opening the form must not be an edit: the choice changes only when the
|
|
// user picks an integration, so a save of anything else keeps it.
|
|
const stale = { use_instance_smtp_settings: true }
|
|
const wrapper = await mountComponent({
|
|
service: stale,
|
|
defaultValues: stale,
|
|
props: { instanceSmtpAvailable: false },
|
|
})
|
|
await nextTick()
|
|
|
|
expect(wrapper.find('input[type="checkbox"]').exists()).toBe(false)
|
|
expect(wrapper.findComponent(IntegrationDropdownStub).exists()).toBe(true)
|
|
expect(
|
|
wrapper
|
|
.find('[placeholder="smtpEmailForm.fromEmailPlaceholder"]')
|
|
.exists()
|
|
).toBe(true)
|
|
expect(wrapper.vm.getFormValues().use_instance_smtp_settings).toBe(true)
|
|
const changed = (wrapper.emitted('values-changed') || []).filter(
|
|
([values]) => values.use_instance_smtp_settings !== true
|
|
)
|
|
expect(changed).toHaveLength(0)
|
|
})
|
|
|
|
test('an unavailable saved instance choice shows custom configuration without rewriting it', async () => {
|
|
const stale = {
|
|
use_instance_smtp_settings: true,
|
|
instance_smtp_settings_enabled: false,
|
|
}
|
|
const wrapper = await mountComponent({
|
|
service: stale,
|
|
defaultValues: stale,
|
|
})
|
|
|
|
expect(wrapper.find('input[type="checkbox"]').exists()).toBe(false)
|
|
expect(
|
|
wrapper
|
|
.find('[placeholder="smtpEmailForm.fromEmailPlaceholder"]')
|
|
.exists()
|
|
).toBe(true)
|
|
expect(
|
|
(wrapper.emitted('values-changed') || []).some(
|
|
([values]) => values.use_instance_smtp_settings === false
|
|
)
|
|
).toBe(false)
|
|
})
|
|
|
|
test('selecting an integration repairs a stale instance choice', async () => {
|
|
const service = {
|
|
use_instance_smtp_settings: true,
|
|
instance_smtp_settings_enabled: false,
|
|
}
|
|
const wrapper = await mountComponent({
|
|
service,
|
|
integrations: [{ id: 7, type: 'smtp' }],
|
|
})
|
|
await wrapper.get('button').trigger('click')
|
|
await flushPromises()
|
|
expect(wrapper.emitted('values-changed').at(-1)[0]).toMatchObject({
|
|
integration_id: 7,
|
|
use_instance_smtp_settings: false,
|
|
})
|
|
})
|
|
|
|
test('a host can offer inline integration editing without an integrations page', async () => {
|
|
const wrapper = await mountComponent({
|
|
service: { instance_smtp_settings_enabled: false },
|
|
application: { id: 1, type: 'agent' },
|
|
props: { allowIntegrationEditing: true },
|
|
})
|
|
expect(
|
|
wrapper.findComponent(IntegrationDropdownStub).props('allowEditing')
|
|
).toBe(true)
|
|
})
|
|
|
|
test('an integration can be edited from a database but not a builder', async () => {
|
|
// A database has no integrations page, so the dropdown is the only place
|
|
// to edit one. The builder and automations keep their own pages.
|
|
const service = { instance_smtp_settings_enabled: false }
|
|
const inDatabase = await mountComponent({
|
|
service,
|
|
application: { id: 1, type: 'database' },
|
|
})
|
|
const inBuilder = await mountComponent({
|
|
service,
|
|
application: { id: 2, type: 'builder' },
|
|
})
|
|
|
|
expect(
|
|
inDatabase.findComponent(IntegrationDropdownStub).props('allowEditing')
|
|
).toBe(true)
|
|
expect(
|
|
inBuilder.findComponent(IntegrationDropdownStub).props('allowEditing')
|
|
).toBe(false)
|
|
})
|
|
})
|