From 34576d9b1a08c8cb0f361f0f8acd47e1092e68ac Mon Sep 17 00:00:00 2001 From: Jannik Stehle Date: Fri, 13 Oct 2023 09:10:37 +0200 Subject: [PATCH] feat: introduce extension disabling via config Adds a config option `disabledExtensions` which enables disabling specific extensions via their id. --- .../enhancement-disabling-extensions | 6 +++ .../piniaStores/extensionRegistry.ts | 48 ++++++++++++------- packages/web-pkg/src/configuration/manager.ts | 1 + packages/web-pkg/src/configuration/types.ts | 1 + .../src/container/application/classic.ts | 8 ++-- .../src/container/application/index.ts | 3 +- packages/web-runtime/src/store/config.ts | 3 +- 7 files changed, 48 insertions(+), 22 deletions(-) create mode 100644 changelog/unreleased/enhancement-disabling-extensions diff --git a/changelog/unreleased/enhancement-disabling-extensions b/changelog/unreleased/enhancement-disabling-extensions new file mode 100644 index 00000000000..0132bb08b51 --- /dev/null +++ b/changelog/unreleased/enhancement-disabling-extensions @@ -0,0 +1,6 @@ +Enhancement: Disabling extensions + +A new configuration `disabledExtensions` has been added which enables disabling specific extensions via their id. + +https://github.com/owncloud/web/pull/9441 +https://github.com/owncloud/web/issues/8524 diff --git a/packages/web-pkg/src/composables/piniaStores/extensionRegistry.ts b/packages/web-pkg/src/composables/piniaStores/extensionRegistry.ts index 6574c122763..5150b663ce6 100644 --- a/packages/web-pkg/src/composables/piniaStores/extensionRegistry.ts +++ b/packages/web-pkg/src/composables/piniaStores/extensionRegistry.ts @@ -1,7 +1,9 @@ import { Action } from '../actions' import { SearchProvider } from '../../components/Search' import { defineStore } from 'pinia' -import { Ref, unref } from 'vue' +import { Ref, hasInjectionContext, unref } from 'vue' +import { useConfigurationManager } from '../configuration' +import { ConfigurationManager } from '../../configuration' export type BaseExtension = { id: string @@ -20,20 +22,32 @@ export interface SearchExtension extends BaseExtension { export type Extension = ActionExtension | SearchExtension -export const useExtensionRegistry = defineStore('extensionRegistry', { - state: () => ({ extensions: [] as Ref[] }), - actions: { - registerExtensions(extensions: Ref) { - this.extensions.push(extensions) - } - }, - getters: { - requestExtensions: - (state) => - (type: string) => { - return state.extensions - .map((e) => unref(e).filter((e) => e.type === type)) - .flat() as ExtensionType[] - } +export const useExtensionRegistry = ({ + configurationManager +}: { configurationManager?: ConfigurationManager } = {}) => { + if (!hasInjectionContext() && !configurationManager) { + throw new Error('no injection context, you need to pass configuration manager via options') } -}) + + const { options } = configurationManager || useConfigurationManager() + + return defineStore('extensionRegistry', { + state: () => ({ extensions: [] as Ref[] }), + actions: { + registerExtensions(extensions: Ref) { + this.extensions.push(extensions) + } + }, + getters: { + requestExtensions: + (state) => + (type: string) => { + return state.extensions + .map((e) => + unref(e).filter((e) => e.type === type && !options.disabledExtensions.includes(e.id)) + ) + .flat() as ExtensionType[] + } + } + })() +} diff --git a/packages/web-pkg/src/configuration/manager.ts b/packages/web-pkg/src/configuration/manager.ts index 632cc96801f..1f08c38fcf5 100644 --- a/packages/web-pkg/src/configuration/manager.ts +++ b/packages/web-pkg/src/configuration/manager.ts @@ -104,6 +104,7 @@ export class ConfigurationManager { set(this.optionsConfiguration, 'upload.companionUrl', get(options, 'upload.companionUrl', '')) set(this.optionsConfiguration, 'tokenStorageLocal', get(options, 'tokenStorageLocal', true)) set(this.optionsConfiguration, 'loginUrl', get(options, 'loginUrl', '')) + set(this.optionsConfiguration, 'disabledExtensions', get(options, 'disabledExtensions', [])) } get options(): OptionsConfiguration { diff --git a/packages/web-pkg/src/configuration/types.ts b/packages/web-pkg/src/configuration/types.ts index 3d015ec18fb..95e574601fb 100644 --- a/packages/web-pkg/src/configuration/types.ts +++ b/packages/web-pkg/src/configuration/types.ts @@ -25,6 +25,7 @@ export interface OptionsConfiguration { openAppsInTab?: boolean openLinksWithDefaultApp?: boolean tokenStorageLocal?: boolean + disabledExtensions?: string[] } export interface OAuth2Configuration { diff --git a/packages/web-runtime/src/container/application/classic.ts b/packages/web-runtime/src/container/application/classic.ts index b0738b24357..1574d96a789 100644 --- a/packages/web-runtime/src/container/application/classic.ts +++ b/packages/web-runtime/src/container/application/classic.ts @@ -5,7 +5,7 @@ import { isFunction, isObject } from 'lodash-es' import { NextApplication } from './next' import { Store } from 'vuex' import { Router } from 'vue-router' -import { RuntimeError } from '@ownclouders/web-pkg' +import { ConfigurationManager, RuntimeError } from '@ownclouders/web-pkg' import { AppConfigObject, AppReadyHookArgs, ClassicApplicationScript } from '@ownclouders/web-pkg' import { useExtensionRegistry } from '@ownclouders/web-pkg' import type { Language } from 'vue3-gettext' @@ -84,7 +84,8 @@ export const convertClassicApplication = async ({ store, router, gettext, - supportedLanguages + supportedLanguages, + configurationManager }: { app: App applicationScript: ClassicApplicationScript @@ -93,6 +94,7 @@ export const convertClassicApplication = async ({ router: Router gettext: Language supportedLanguages: { [key: string]: string } + configurationManager: ConfigurationManager }): Promise => { if (applicationScript.setup) { applicationScript = app.runWithContext(() => { @@ -130,7 +132,7 @@ export const convertClassicApplication = async ({ await store.dispatch('registerApp', applicationScript.appInfo) if (applicationScript.extensions) { - useExtensionRegistry().registerExtensions(applicationScript.extensions) + useExtensionRegistry({ configurationManager }).registerExtensions(applicationScript.extensions) } return new ClassicApplication(runtimeApi, applicationScript, app) diff --git a/packages/web-runtime/src/container/application/index.ts b/packages/web-runtime/src/container/application/index.ts index b0313dd103e..77d3e43fafc 100644 --- a/packages/web-runtime/src/container/application/index.ts +++ b/packages/web-runtime/src/container/application/index.ts @@ -130,7 +130,8 @@ export const buildApplication = async ({ store, router, gettext, - supportedLanguages + supportedLanguages, + configurationManager }).catch() } } catch (err) { diff --git a/packages/web-runtime/src/store/config.ts b/packages/web-runtime/src/store/config.ts index 6ffd198a866..34e5cf14afb 100644 --- a/packages/web-runtime/src/store/config.ts +++ b/packages/web-runtime/src/store/config.ts @@ -72,7 +72,8 @@ const state = { loginUrl: '', privacyUrl: '', imprintUrl: '', - accessDeniedHelpUrl: '' + accessDeniedHelpUrl: '', + disabledExtensions: [] } }