Skip to content

Commit 345aa16

Browse files
committed
refactor: use ox option instead of capability
1 parent 6f90d76 commit 345aa16

14 files changed

Lines changed: 46 additions & 76 deletions

File tree

packages/web-app-files/src/composables/openXchange/useOpenXchangeContacts.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import { useCapabilityStore, useClientService } from '@opencloud-eu/web-pkg'
1+
import { useClientService, useConfigStore } from '@opencloud-eu/web-pkg'
22
import { CollaboratorAutoCompleteItem, ShareTypes } from '@opencloud-eu/web-client'
33

44
/**
55
* Searches the Open-Xchange addressbook for contacts and maps them to share
6-
* recipients of type "contact". Only active when the `open_xchange.enabled`
6+
* recipients of type "contact". Only active when the `config.options.oxAppSuite.enabled`
77
* capability is set.
88
*/
99
export const useOpenXchangeContacts = () => {
1010
const clientService = useClientService()
11-
const capabilityStore = useCapabilityStore()
11+
const configStore = useConfigStore()
1212

1313
const searchContacts = async (
1414
query: string,
1515
signal?: AbortSignal
1616
): Promise<CollaboratorAutoCompleteItem[]> => {
17-
if (!capabilityStore.openXchangeEnabled) {
17+
if (!configStore.options.oxAppSuite?.enabled) {
1818
return []
1919
}
2020

packages/web-app-files/tests/unit/components/SideBar/Shares/Collaborators/InviteCollaborator/InviteCollaboratorForm.spec.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,7 @@ function getWrapper({
301301
mocks.$clientService.ox.autocompleteContacts.mockResolvedValue(openXchangeContacts)
302302

303303
const capabilities = {
304-
files_sharing: { federation: { incoming: true, outgoing: true } },
305-
open_xchange: { enabled: openXchange, api_url: openXchange ? 'https://ox.example.com/api' : '' }
304+
files_sharing: { federation: { incoming: true, outgoing: true } }
306305
}
307306

308307
return {
@@ -314,7 +313,15 @@ function getWrapper({
314313
piniaOptions: {
315314
userState: { user },
316315
capabilityState: { capabilities },
317-
configState: { options: { concurrentRequests: { shares: { create: 1 } } } },
316+
configState: {
317+
options: {
318+
concurrentRequests: { shares: { create: 1 } },
319+
oxAppSuite: {
320+
enabled: openXchange,
321+
apiUrl: openXchange ? 'https://ox.example.com/api' : ''
322+
}
323+
}
324+
},
318325
sharesState: {
319326
collaboratorShares: existingCollaborators
320327
}

packages/web-app-files/tests/unit/composables/openXchange/useOpenXchangeContacts.spec.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { Contact } from '@opencloud-eu/web-client/ox'
22
import { ShareTypes } from '@opencloud-eu/web-client'
33
import { defaultComponentMocks, getComposableWrapper } from '@opencloud-eu/web-test-helpers'
4-
import { useCapabilityStore } from '@opencloud-eu/web-pkg'
54
import { useOpenXchangeContacts } from '../../../../src/composables/openXchange/useOpenXchangeContacts'
65

76
describe('useOpenXchangeContacts', () => {
8-
it('returns an empty list and does not call the api when the capability is disabled', async () => {
7+
it('returns an empty list and does not call the api when the config option is disabled', async () => {
98
const { instance, mocks } = getWrapper({ enabled: false })
109
const result = await instance.searchContacts('jane')
1110
expect(result).toEqual([])
@@ -63,11 +62,15 @@ function getWrapper({
6362
let instance: ReturnType<typeof useOpenXchangeContacts>
6463
const wrapper = getComposableWrapper(
6564
() => {
66-
const capabilityStore = useCapabilityStore()
67-
vi.mocked(capabilityStore).openXchangeEnabled = enabled
6865
instance = useOpenXchangeContacts()
6966
},
70-
{ mocks, provide: mocks }
67+
{
68+
mocks,
69+
provide: mocks,
70+
pluginOptions: {
71+
piniaOptions: { configState: { options: { oxAppSuite: { enabled } } } }
72+
}
73+
}
7174
)
7275

7376
return { wrapper, instance, mocks }

packages/web-client/src/ocs/capabilities.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,6 @@ export interface Capabilities {
178178
groupware?: {
179179
enabled?: boolean
180180
}
181-
open_xchange?: {
182-
enabled?: boolean
183-
api_url?: string
184-
}
185181
}
186182
version: {
187183
edition?: string

packages/web-client/src/ox/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export interface OX {
3333
* Client for the Open-Xchange middleware HTTP API.
3434
*
3535
* The base url is resolved lazily through `getApiUrl` because it originates from
36-
* a server capability that is only available after the app has bootstrapped.
36+
* a config option that is only available after the app has bootstrapped.
3737
*/
3838
export const ox = (axiosClient: AxiosInstance, getApiUrl: () => string | undefined): OX => {
3939
return {

packages/web-pkg/src/composables/piniaStores/capabilities.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ const defaultValues = {
6060
enabled: false,
6161
max_quota: 0,
6262
projects: false
63-
},
64-
open_xchange: {
65-
enabled: false,
66-
api_url: ''
6763
}
6864
} satisfies Partial<Capabilities['capabilities']>
6965

@@ -142,9 +138,6 @@ export const useCapabilityStore = defineStore('capabilities', () => {
142138
const searchMediaType = computed(() => unref(capabilities).search.property?.mediatype)
143139
const searchContent = computed(() => unref(capabilities).search.property?.content)
144140

145-
const openXchangeEnabled = computed(() => unref(capabilities).open_xchange.enabled)
146-
const openXchangeApiUrl = computed(() => unref(capabilities).open_xchange.api_url)
147-
148141
return {
149142
isInitialized,
150143
capabilities,
@@ -188,9 +181,7 @@ export const useCapabilityStore = defineStore('capabilities', () => {
188181
passwordPolicy,
189182
searchLastMofifiedDate,
190183
searchMediaType,
191-
searchContent,
192-
openXchangeEnabled,
193-
openXchangeApiUrl
184+
searchContent
194185
}
195186
})
196187

packages/web-pkg/src/composables/piniaStores/config/config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ const defaultOptions = {
3131
},
3232
tokenStorageLocal: true,
3333
userListRequiresFilter: false,
34-
hideLogo: false
34+
hideLogo: false,
35+
oxAppSuite: {
36+
enabled: false,
37+
apiUrl: ''
38+
}
3539
} satisfies Partial<OptionsConfig>
3640

3741
export const useConfigStore = defineStore('config', () => {

packages/web-pkg/src/composables/piniaStores/config/types.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,13 @@ const OptionsConfigSchema = z.object({
104104
})
105105
.optional(),
106106
userListRequiresFilter: z.boolean().optional(),
107-
hideLogo: z.boolean().optional()
107+
hideLogo: z.boolean().optional(),
108+
oxAppSuite: z
109+
.object({
110+
enabled: z.boolean().optional(),
111+
apiUrl: z.string().optional()
112+
})
113+
.optional()
108114
})
109115

110116
export type OptionsConfig = z.infer<typeof OptionsConfigSchema>

packages/web-pkg/src/services/client/client.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { WebDAV } from '@opencloud-eu/web-client/webdav'
1010
import { Language } from 'vue3-gettext'
1111
import { FetchEventSourceInit } from '@microsoft/fetch-event-source'
1212
import { sse } from '@opencloud-eu/web-client/sse'
13-
import { AuthStore, CapabilityStore, ConfigStore } from '../../composables'
13+
import { AuthStore, ConfigStore } from '../../composables'
1414
import { createVaultWebDav } from './vaultWebDav'
1515

1616
const createFetchOptions = (authParams: AuthParameters, language: string): FetchEventSourceInit => {
@@ -28,14 +28,12 @@ export interface ClientServiceOptions {
2828
configStore: ConfigStore
2929
language: Language
3030
authStore: AuthStore
31-
capabilityStore: CapabilityStore
3231
}
3332

3433
export class ClientService {
3534
private configStore: ConfigStore
3635
private language: Language
3736
private authStore: AuthStore
38-
private capabilityStore: CapabilityStore
3937

4038
private httpAuthenticatedClient: HttpClient
4139
private httpUnAuthenticatedClient: HttpClient
@@ -56,7 +54,6 @@ export class ClientService {
5654
this.configStore = options.configStore
5755
this.language = options.language
5856
this.authStore = options.authStore
59-
this.capabilityStore = options.capabilityStore
6057

6158
this.initGraphClient()
6259
this.initOcsClient()
@@ -145,7 +142,7 @@ export class ClientService {
145142
Object.assign(config.headers, this.getDynamicHeaders())
146143
return config
147144
})
148-
this.oxClient = ox(axiosClient, () => this.capabilityStore.openXchangeApiUrl)
145+
this.oxClient = ox(axiosClient, () => this.configStore.options.oxAppSuite?.apiUrl)
149146
}
150147

151148
private initWebDavClient() {

packages/web-pkg/tests/unit/composables/piniaStores/capabilities.spec.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -42,32 +42,6 @@ describe('useCapabilityStore', () => {
4242
})
4343
})
4444
})
45-
46-
describe('open-xchange getters', () => {
47-
it('default to disabled with an empty api url', () => {
48-
getWrapper({
49-
setup: (instance) => {
50-
expect(instance.openXchangeEnabled).toBe(false)
51-
expect(instance.openXchangeApiUrl).toBe('')
52-
}
53-
})
54-
})
55-
it('reflect the values set via "setCapabilities"', () => {
56-
getWrapper({
57-
setup: (instance) => {
58-
const data = {
59-
capabilities: {
60-
open_xchange: { enabled: true, api_url: 'https://ox.example.com/api' }
61-
}
62-
} as Capabilities
63-
instance.setCapabilities(data)
64-
65-
expect(instance.openXchangeEnabled).toBe(true)
66-
expect(instance.openXchangeApiUrl).toBe('https://ox.example.com/api')
67-
}
68-
})
69-
})
70-
})
7145
})
7246

7347
function getWrapper({

0 commit comments

Comments
 (0)