Files
baserow/web-frontend/modules/builder/components/userSource/UpdateUserSourceForm.vue
Tsering PaljorandJeremie Pardou 250748c8dc feat: Workspace level integrations (#6547)
* 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>
2026-11-27 15:49:32 +04:00

276 lines
8.0 KiB
Vue

<template>
<form @submit.prevent="submit">
<FormRow class="margin-bottom-2">
<FormGroup
:label="$t('updateUserSourceForm.nameFieldLabel')"
:error-message="getFirstErrorMessage('name')"
required
small-label
>
<FormInput
v-model="v$.values.name.$model"
size="large"
class="update-user-source-form__name-input"
:placeholder="$t('updateUserSourceForm.nameFieldPlaceholder')"
/>
</FormGroup>
<FormGroup
:label="$t('updateUserSourceForm.integrationFieldLabel')"
:error-message="getFirstErrorMessage('integration_id')"
required
small-label
>
<IntegrationDropdown
v-model="v$.values.integration_id.$model"
:application="builder"
:integrations="integrations"
:integration-type="userSourceType.integrationType"
size="large"
/>
</FormGroup>
</FormRow>
<component
:is="userSourceType.formComponent"
v-if="integration"
:default-values="defaultValues"
:application="builder"
:integration="integration"
@values-changed="emitChange"
/>
<div v-if="integration">
<FormGroup
:label="$t('updateUserSourceForm.authTitle')"
small-label
required
>
<div
v-for="appAuthType in appAuthProviderTypes"
:key="appAuthType.type"
class="update-user-source-form__auth-provider"
>
<div class="update-user-source-form__auth-provider-header">
<Checkbox
:checked="hasAtLeastOneOfThisType(appAuthType)"
@input="onSelect(appAuthType)"
>
{{ appAuthType.name }}
</Checkbox>
<ButtonText
v-if="
hasAtLeastOneOfThisType(appAuthType) &&
appAuthType.canCreateNew(appAuthProviderPerTypes)
"
icon="iconoir-plus"
type="secondary"
@click.prevent="addNew(appAuthType)"
>
{{ $t('updateUserSourceForm.addProvider') }}
</ButtonText>
</div>
<div
v-for="appAuthProvider in appAuthProviderPerTypes[appAuthType.type]"
:key="appAuthProvider.id"
class="update-user-source-form__auth-provider-form"
>
<component
:is="appAuthType.formComponent"
v-if="hasAtLeastOneOfThisType(appAuthType) && fullValues?.type"
:ref="`authProviderForm`"
excluded-form
:application="builder"
:integration="integration"
:user-source="fullValues"
:auth-providers="appAuthProviderPerTypes"
:auth-provider="appAuthProvider"
:default-values="appAuthProvider"
:auth-provider-type="appAuthType"
@values-changed="updateAuthProvider(appAuthProvider, $event)"
@delete="remove(appAuthProvider)"
/>
</div>
</div>
</FormGroup>
<input type="submit" hidden />
</div>
</form>
</template>
<script>
import { useVuelidate } from '@vuelidate/core'
import form from '@baserow/modules/core/mixins/form'
import IntegrationDropdown from '@baserow/modules/core/components/integrations/IntegrationDropdown'
import { required, maxLength, helpers } from '@vuelidate/validators'
import _ from 'lodash'
export default {
components: { IntegrationDropdown },
mixins: [form],
props: {
builder: {
type: Object,
required: true,
},
userSourceType: {
type: Object,
required: false,
default: null,
},
},
emits: ['values-changed'],
setup() {
return { v$: useVuelidate({ $lazy: true }) }
},
data() {
return {
values: {
integration_id: null,
name: '',
auth_providers: [],
},
fullValues: null,
}
},
computed: {
integrations() {
return this.$store.getters['integration/getUsableIntegrations'](
this.builder
).filter(
(integration) =>
integration.type === this.userSourceType?.integrationType?.getType()
)
},
integration() {
if (!this.values.integration_id) {
return null
}
return this.integrations.find(
({ id }) => id === this.values.integration_id
)
},
appAuthProviderTypes() {
return this.$registry
.getOrderedList('appAuthProvider')
.filter((type) => !type.isDeactivated(this.builder.workspace.id))
},
appAuthProviderPerTypes() {
return Object.fromEntries(
this.appAuthProviderTypes.map((authType) => {
return [
authType.type,
this.values.auth_providers.filter(
({ type }) => type === authType.type
),
]
})
)
},
},
mounted() {
// Initialize fullValues after component is mounted and registeredChildForms is ready
this.fullValues = this.getFormValues()
},
methods: {
// Override the default getChildFormValues to exclude the provider forms from
// final values as they are handled directly by this component
// The problem is that the child provider forms are not handled as a sub array
// so they override the userSource configuration
// Note: excluded forms don't receive the :parent-form prop, so they won't be
// in registeredChildForms
getChildFormsValues() {
return Object.assign(
{},
...this.getChildForms(
(child) => 'getChildFormsValues' in child && !child.excludedForm
).map((child) => {
return child.getFormValues()
})
)
},
hasAtLeastOneOfThisType(appAuthProviderType) {
return this.appAuthProviderPerTypes[appAuthProviderType.type]?.length > 0
},
/** Return an integer bigger than any of the current auth_provider id to
* keep the right order when we want to map the error coming back from the server.
*/
nextID() {
return (
Math.max(1, ...this.values.auth_providers.map(({ id }) => id)) + 100
)
},
onSelect(appAuthProviderType) {
if (this.hasAtLeastOneOfThisType(appAuthProviderType)) {
this.values.auth_providers = this.values.auth_providers.filter(
({ type }) => type !== appAuthProviderType.type
)
} else {
this.values.auth_providers.push({
type: appAuthProviderType.type,
id: this.nextID(),
})
}
},
addNew(appAuthProviderType) {
this.values.auth_providers.push({
type: appAuthProviderType.type,
id: this.nextID(),
})
},
remove(appAuthProvider) {
this.values.auth_providers = this.values.auth_providers.filter(
({ id }) => id !== appAuthProvider.id
)
},
updateAuthProvider(authProviderToChange, values) {
this.values.auth_providers = this.values.auth_providers.map(
(authProvider) => {
if (authProvider.id === authProviderToChange.id) {
return { ...authProvider, ...values }
}
return authProvider
}
)
},
emitChange() {
this.fullValues = this.getFormValues()
this.$emit('values-changed', this.fullValues)
},
handleServerError(error) {
if (
this.$refs.authProviderForm
.map((form) => form.handleServerError(error))
.some((result) => result)
) {
return true
}
return false
},
},
validations() {
return {
values: {
integration_id: {
required: helpers.withMessage(
this.$t('error.requiredField'),
required
),
},
name: {
required: helpers.withMessage(
this.$t('error.requiredField'),
required
),
maxLength: helpers.withMessage(
this.$t('error.maxLength', { max: 255 }),
maxLength(255)
),
},
},
}
},
}
</script>