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 beccf2c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 17 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
41 changes: 25 additions & 16 deletions packages/web-pkg/src/composables/piniaStores/extensionRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Action } from '../actions'
import { SearchProvider } from '../../components/Search'
import { defineStore } from 'pinia'
import { Ref, unref } from 'vue'
import { useConfigurationManager } from '../configuration'

export type BaseExtension = {
id: string
Expand All @@ -20,20 +21,28 @@ 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 = () => {
const { options } = 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(unref(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
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 beccf2c

Please sign in to comment.