Skip to content

Commit

Permalink
feat: introduce extension disabling via config
Browse files Browse the repository at this point in the history
Adds a config option `disabledExtensions` which enables disabling specific extensions via their id.
  • Loading branch information
JammingBen committed Oct 13, 2023
1 parent e86b313 commit 34576d9
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 22 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/enhancement-disabling-extensions
Original file line number Diff line number Diff line change
@@ -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
48 changes: 31 additions & 17 deletions packages/web-pkg/src/composables/piniaStores/extensionRegistry.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -20,20 +22,32 @@ export interface SearchExtension extends BaseExtension {

export type Extension = ActionExtension | SearchExtension

export const useExtensionRegistry = defineStore('extensionRegistry', {
state: () => ({ extensions: [] as Ref<Extension[]>[] }),
actions: {
registerExtensions(extensions: Ref<Extension[]>) {
this.extensions.push(extensions)
}
},
getters: {
requestExtensions:
(state) =>
<ExtensionType extends Extension>(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<Extension[]>[] }),
actions: {
registerExtensions(extensions: Ref<Extension[]>) {
this.extensions.push(extensions)
}
},
getters: {
requestExtensions:
(state) =>
<ExtensionType extends Extension>(type: string) => {
return state.extensions
.map((e) =>
unref(e).filter((e) => e.type === type && !options.disabledExtensions.includes(e.id))
)
.flat() as ExtensionType[]
}
}
})()
}
1 change: 1 addition & 0 deletions packages/web-pkg/src/configuration/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions packages/web-pkg/src/configuration/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface OptionsConfiguration {
openAppsInTab?: boolean
openLinksWithDefaultApp?: boolean
tokenStorageLocal?: boolean
disabledExtensions?: string[]
}

export interface OAuth2Configuration {
Expand Down
8 changes: 5 additions & 3 deletions packages/web-runtime/src/container/application/classic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -84,7 +84,8 @@ export const convertClassicApplication = async ({
store,
router,
gettext,
supportedLanguages
supportedLanguages,
configurationManager
}: {
app: App
applicationScript: ClassicApplicationScript
Expand All @@ -93,6 +94,7 @@ export const convertClassicApplication = async ({
router: Router
gettext: Language
supportedLanguages: { [key: string]: string }
configurationManager: ConfigurationManager
}): Promise<NextApplication> => {
if (applicationScript.setup) {
applicationScript = app.runWithContext(() => {
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion packages/web-runtime/src/container/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ export const buildApplication = async ({
store,
router,
gettext,
supportedLanguages
supportedLanguages,
configurationManager
}).catch()
}
} catch (err) {
Expand Down
3 changes: 2 additions & 1 deletion packages/web-runtime/src/store/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ const state = {
loginUrl: '',
privacyUrl: '',
imprintUrl: '',
accessDeniedHelpUrl: ''
accessDeniedHelpUrl: '',
disabledExtensions: []
}
}

Expand Down

0 comments on commit 34576d9

Please sign in to comment.