mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 16:28:31 +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>
430 lines
12 KiB
JavaScript
430 lines
12 KiB
JavaScript
import { StoreItemLookupError } from '@baserow/modules/core/errors'
|
|
import ApplicationService from '@baserow/modules/core/services/application'
|
|
import { clone } from '@baserow/modules/core/utils/object'
|
|
import { CORE_ACTION_SCOPES } from '@baserow/modules/core/utils/undoRedoConstants'
|
|
import { generateHash } from '@baserow/modules/core/utils/hashing'
|
|
import {
|
|
markRealtimeMetadata,
|
|
realtimeMetadata,
|
|
} from '@baserow/modules/core/utils/realtime'
|
|
import { SharedApplicationType } from '@baserow/modules/core/applicationTypes'
|
|
|
|
/**
|
|
* Whether the application is the hidden one that owns the workspace integrations of
|
|
* its workspace. It's in the store, so it can be found by id, but it isn't one of
|
|
* the user's applications.
|
|
*/
|
|
export function isSharedApplication(application) {
|
|
return application.type === SharedApplicationType.getType()
|
|
}
|
|
|
|
export function populateApplication(application, registry) {
|
|
const type = registry.get('application', application.type)
|
|
|
|
const app = {
|
|
...application,
|
|
_: {
|
|
type: type.serialize(),
|
|
loading: false,
|
|
selected: false,
|
|
...realtimeMetadata(),
|
|
},
|
|
}
|
|
return type.populate(app)
|
|
}
|
|
|
|
export const state = () => ({
|
|
loading: false,
|
|
loaded: false,
|
|
items: [],
|
|
selected: null,
|
|
expandedSidebarApplications: {},
|
|
})
|
|
|
|
export const mutations = {
|
|
SET_SIDEBAR_EXPANDED(state, { id, workspaceId, expanded }) {
|
|
if (expanded) {
|
|
state.expandedSidebarApplications[id] = workspaceId
|
|
} else {
|
|
delete state.expandedSidebarApplications[id]
|
|
}
|
|
},
|
|
SET_ITEMS(state, applications) {
|
|
state.items = applications
|
|
},
|
|
SET_LOADING(state, value) {
|
|
state.loading = value
|
|
},
|
|
SET_LOADED(state, value) {
|
|
state.loaded = value
|
|
},
|
|
SET_ITEM_LOADING(state, { application, value }) {
|
|
if (application?._) {
|
|
application._.loading = value
|
|
}
|
|
},
|
|
ADD_ITEM(state, item) {
|
|
state.items.push(item)
|
|
},
|
|
APPEND_ITEMS(state, items) {
|
|
state.items = state.items.concat(items)
|
|
},
|
|
UPDATE_ITEM(state, { id, values, viaRealtime = false }) {
|
|
const index = state.items.findIndex((item) => item.id === id)
|
|
if (index !== -1) {
|
|
Object.assign(state.items[index], state.items[index], values)
|
|
markRealtimeMetadata(state.items[index], viaRealtime)
|
|
}
|
|
},
|
|
ORDER_ITEMS(state, { workspace, order, isHashed = false }) {
|
|
state.items
|
|
.filter((item) => item.workspace.id === workspace.id)
|
|
.forEach((item) => {
|
|
const itemId = isHashed ? generateHash(item.id) : item.id
|
|
const index = order.findIndex((value) => value === itemId)
|
|
item.order = index === -1 ? undefined : index + 1
|
|
})
|
|
},
|
|
DELETE_ITEM(state, id) {
|
|
const index = state.items.findIndex((item) => item.id === id)
|
|
if (index !== -1) {
|
|
state.items.splice(index, 1)
|
|
}
|
|
},
|
|
DELETE_ITEMS_FOR_WORKSPACE(state, workspaceId) {
|
|
state.items = state.items.filter((app) => app.workspace.id !== workspaceId)
|
|
},
|
|
SET_SELECTED(state, application) {
|
|
Object.values(state.items).forEach((item) => {
|
|
item._.selected = false
|
|
})
|
|
application._.selected = true
|
|
state.selected = application
|
|
},
|
|
UNSELECT(state) {
|
|
Object.values(state.items).forEach((item) => {
|
|
item._.selected = false
|
|
})
|
|
state.selected = {}
|
|
},
|
|
}
|
|
|
|
export const actions = {
|
|
/**
|
|
* Changes the loading state of a specific item.
|
|
*/
|
|
setItemLoading({ commit }, { application, value }) {
|
|
commit('SET_ITEM_LOADING', { application, value })
|
|
},
|
|
/**
|
|
* Force creates a list of applications.
|
|
*/
|
|
forceCreateAll({ dispatch }, applications) {
|
|
applications.forEach((app) => {
|
|
dispatch('forceCreate', app)
|
|
})
|
|
},
|
|
/**
|
|
* Fetches all the applications for the authenticated user.
|
|
*/
|
|
async fetchAll({ commit, dispatch }) {
|
|
commit('SET_LOADING', true)
|
|
const { $client } = this
|
|
|
|
try {
|
|
const { data } = await ApplicationService($client).fetchAll()
|
|
await dispatch('forceSetAll', { applications: data })
|
|
} catch (error) {
|
|
commit('SET_ITEMS', [])
|
|
commit('SET_LOADING', false)
|
|
|
|
throw error
|
|
}
|
|
},
|
|
forceSetAll({ commit }, { applications }) {
|
|
const { $registry } = this
|
|
const apps = applications.map((application) =>
|
|
populateApplication(application, $registry)
|
|
)
|
|
commit('SET_ITEMS', apps)
|
|
commit('SET_LOADING', false)
|
|
commit('SET_LOADED', true)
|
|
return { applications: apps }
|
|
},
|
|
/**
|
|
* Clears all the currently selected applications, this could be called when
|
|
* the workspace is deleted of when the user logs off.
|
|
*/
|
|
clearAll({ commit }, workspace) {
|
|
commit('DELETE_ITEMS_FOR_WORKSPACE', workspace)
|
|
commit('UNSELECT')
|
|
commit('SET_LOADED', false)
|
|
},
|
|
|
|
/**
|
|
* Creates a new application with the given type and values for the currently
|
|
* selected workspace.
|
|
*/
|
|
async create({ dispatch }, { type, workspace, values, initWithData = true }) {
|
|
const { $registry, $client } = this
|
|
|
|
if (Object.prototype.hasOwnProperty.call(values, 'type')) {
|
|
throw new Error(
|
|
'The key "type" is a reserved, but is already set on the ' +
|
|
'values when creating a new application.'
|
|
)
|
|
}
|
|
|
|
if (!$registry.exists('application', type)) {
|
|
throw new StoreItemLookupError(
|
|
`An application type with type "${type}" doesn't exist.`
|
|
)
|
|
}
|
|
|
|
const postData = clone(values)
|
|
postData.type = type
|
|
postData.init_with_data = initWithData
|
|
|
|
const { data } = await ApplicationService($client).create(
|
|
workspace.id,
|
|
postData
|
|
)
|
|
return dispatch('forceCreate', data)
|
|
},
|
|
/**
|
|
* Forcefully create an item in the store without making a call to the server.
|
|
*/
|
|
forceCreate({ commit, state, getters }, data) {
|
|
const { $registry, $client } = this
|
|
|
|
const app = populateApplication(data, $registry)
|
|
const index = state.items.findIndex((item) => item.id === app.id)
|
|
if (index === -1) {
|
|
commit('ADD_ITEM', app)
|
|
} else {
|
|
commit('UPDATE_ITEM', { id: app.id, values: app })
|
|
}
|
|
return getters.get(app.id)
|
|
},
|
|
/**
|
|
* Returns the shared application of the workspace. When the store doesn't have
|
|
* it, for example because the workspace was created after the applications were
|
|
* loaded, the applications of the workspace are fetched and only the shared one
|
|
* is added.
|
|
*/
|
|
async fetchSharedApplication({ dispatch, getters }, workspace) {
|
|
const sharedApplication = getters.getSharedApplication(workspace)
|
|
if (sharedApplication) {
|
|
return sharedApplication
|
|
}
|
|
|
|
const { data } = await ApplicationService(this.$client).fetchAll(
|
|
workspace.id
|
|
)
|
|
const fetched = data.find(isSharedApplication)
|
|
return fetched ? dispatch('forceCreate', fetched) : undefined
|
|
},
|
|
async refreshPermissions(
|
|
{ dispatch, getters, rootGetters },
|
|
applicationOrId
|
|
) {
|
|
const application =
|
|
typeof applicationOrId === 'object'
|
|
? applicationOrId
|
|
: getters.get(applicationOrId)
|
|
|
|
if (
|
|
application?.workspace &&
|
|
rootGetters['workspace/haveWorkspacePermissionsBeenLoaded'](
|
|
application.workspace.id
|
|
)
|
|
) {
|
|
await dispatch('workspace/forceFetchPermissions', application.workspace, {
|
|
root: true,
|
|
})
|
|
}
|
|
},
|
|
/**
|
|
* Updates the values of an existing application.
|
|
*/
|
|
async update({ dispatch }, { application, values }) {
|
|
const { $registry, $client } = this
|
|
|
|
const { data } = await ApplicationService($client).update(
|
|
application.id,
|
|
values
|
|
)
|
|
|
|
// Create a dict with only the values we want to update.
|
|
const update = Object.keys(values).reduce((result, key) => {
|
|
result[key] = data[key]
|
|
return result
|
|
}, {})
|
|
|
|
dispatch('forceUpdate', { application, data: update })
|
|
},
|
|
/**
|
|
* Forcefully update an item in the store without making a call to the server.
|
|
*/
|
|
forceUpdate({ commit }, { application, data, viaRealtime = false }) {
|
|
const { $registry, $client } = this
|
|
|
|
const type = $registry.get('application', application.type)
|
|
data = type.prepareForStoreUpdate(application, data)
|
|
|
|
commit('UPDATE_ITEM', { id: application.id, values: data, viaRealtime })
|
|
},
|
|
/**
|
|
* Updates the order of all the applications in a workspace.
|
|
*/
|
|
async order(
|
|
{ commit, getters },
|
|
{ workspace, order, oldOrder, isHashed = false }
|
|
) {
|
|
const { $registry, $client } = this
|
|
|
|
commit('ORDER_ITEMS', { workspace, order, isHashed })
|
|
|
|
try {
|
|
await ApplicationService($client).order(workspace.id, order)
|
|
} catch (error) {
|
|
commit('ORDER_ITEMS', { workspace, order: oldOrder, isHashed })
|
|
throw error
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Deletes an existing application.
|
|
*/
|
|
async delete({ commit, dispatch, getters }, application) {
|
|
const { $registry, $client } = this
|
|
|
|
try {
|
|
await ApplicationService($client).delete(application.id)
|
|
dispatch('forceDelete', application)
|
|
} catch (error) {
|
|
if (error.response && error.response.status === 404) {
|
|
dispatch('forceDelete', application)
|
|
} else {
|
|
throw error
|
|
}
|
|
}
|
|
},
|
|
/**
|
|
* Forcefully delete an item in the store without making a call to the server.
|
|
*/
|
|
forceDelete({ commit, dispatch }, application) {
|
|
const { $registry, $client } = this
|
|
|
|
const type = $registry.get('application', application.type)
|
|
dispatch('job/deleteForApplication', application, { root: true })
|
|
type.delete(application, this)
|
|
commit('DELETE_ITEM', application.id)
|
|
},
|
|
/**
|
|
* Select an application.
|
|
*/
|
|
select({ commit, dispatch }, application) {
|
|
commit('SET_SELECTED', application)
|
|
dispatch(
|
|
'undoRedo/updateCurrentScopeSet',
|
|
CORE_ACTION_SCOPES.application(application.id),
|
|
{
|
|
root: true,
|
|
}
|
|
)
|
|
return application
|
|
},
|
|
/**
|
|
* Select an application by a given application id.
|
|
*/
|
|
selectById({ dispatch, getters }, id) {
|
|
const application = getters.get(id)
|
|
if (application === undefined) {
|
|
throw new StoreItemLookupError(`Application with id ${id} is not found.`)
|
|
}
|
|
return dispatch('select', application)
|
|
},
|
|
/**
|
|
* Unselect the application
|
|
*/
|
|
unselect({ commit, dispatch }) {
|
|
commit('UNSELECT', {})
|
|
dispatch(
|
|
'undoRedo/updateCurrentScopeSet',
|
|
CORE_ACTION_SCOPES.application(null),
|
|
{
|
|
root: true,
|
|
}
|
|
)
|
|
},
|
|
}
|
|
|
|
export const getters = {
|
|
isLoading(state) {
|
|
return state.loading
|
|
},
|
|
isLoaded(state) {
|
|
return state.loaded
|
|
},
|
|
isSelected: (state) => (application) => {
|
|
return state.selected?.id === application.id
|
|
},
|
|
get: (state) => (id) => {
|
|
return state.items.find((item) => item.id === id)
|
|
},
|
|
selectedId(state) {
|
|
if (!Object.prototype.hasOwnProperty.call(state.selected, 'id')) {
|
|
throw new Error('There is no selected application.')
|
|
}
|
|
|
|
return state.selected.id
|
|
},
|
|
getSelected(state, getters) {
|
|
if (state.selected?.id) {
|
|
return getters.get(getters.selectedId)
|
|
} else {
|
|
return null
|
|
}
|
|
},
|
|
/**
|
|
* The applications of all the workspaces, without the shared applications, which
|
|
* `get` and `getSharedApplication` return.
|
|
*/
|
|
getAll(state) {
|
|
return state.items.filter(
|
|
(application) => !isSharedApplication(application)
|
|
)
|
|
},
|
|
/**
|
|
* The applications of the workspace, without its shared application.
|
|
*/
|
|
getAllOfWorkspace: (state) => (workspace) => {
|
|
return state.items.filter(
|
|
(application) =>
|
|
application.workspace.id === workspace.id &&
|
|
!isSharedApplication(application)
|
|
)
|
|
},
|
|
/**
|
|
* The hidden application that owns the workspace integrations of the workspace,
|
|
* or undefined when the store doesn't have it, like before the applications are
|
|
* loaded.
|
|
*/
|
|
getSharedApplication: (state) => (workspace) => {
|
|
return state.items.find(
|
|
(application) =>
|
|
application.workspace.id === workspace.id &&
|
|
isSharedApplication(application)
|
|
)
|
|
},
|
|
}
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state,
|
|
getters,
|
|
actions,
|
|
mutations,
|
|
}
|