Skip to content

Commit caf08df

Browse files
committed
Fix LoadAdditionalListener and bad nodes (Vue 3 migration)
1 parent b182c08 commit caf08df

File tree

5 files changed

+162
-210
lines changed

5 files changed

+162
-210
lines changed

lib/Listener/LoadAdditionalListener.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use OCA\Libresign\AppInfo\Application;
1313
use OCA\Libresign\Handler\CertificateEngine\CertificateEngineFactory;
1414
use OCP\App\IAppManager;
15+
use OCP\AppFramework\Services\IInitialState;
1516
use OCP\EventDispatcher\Event;
1617
use OCP\EventDispatcher\IEventListener;
1718
use OCP\Util;
@@ -23,6 +24,7 @@ class LoadAdditionalListener implements IEventListener {
2324
public function __construct(
2425
private IAppManager $appManager,
2526
private CertificateEngineFactory $certificateEngineFactory,
27+
private IInitialState $initialState,
2628
) {
2729
}
2830
#[\Override]
@@ -40,6 +42,7 @@ public function handle(Event $event): void {
4042
}
4143

4244
if (class_exists('\OCA\Files\App')) {
45+
$this->initialState->provideInitialState('certificate_ok', true);
4346
Util::addInitScript(Application::APP_ID, 'libresign-init');
4447
}
4548
}

src/actions/openInLibreSignAction.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const action = {
3232
displayName: () => t('libresign', 'Open in LibreSign'),
3333
iconSvgInline: () => SvgIcon,
3434

35-
enabled({ nodes }) {
35+
enabled(nodes) {
3636
const getNodeMime = (node) => node?.mime || node?.mimetype || ''
3737

3838
if (!loadState('libresign', 'certificate_ok', false)) {
@@ -62,9 +62,8 @@ export const action = {
6262
/**
6363
* Single file or folder: open in sidebar
6464
*/
65-
async exec({ nodes }) {
65+
async exec(node) {
6666
const sidebar = getSidebar()
67-
const node = nodes[0]
6867
await sidebar.open(node, 'libresign')
6968
sidebar.setActiveTab('libresign')
7069
return null
@@ -74,11 +73,11 @@ export const action = {
7473
* Multiple files: prepare envelope data and delegate to sidebar
7574
* Similar to exec, but passes multiple files to the sidebar for processing
7675
*/
77-
async execBatch({ nodes }) {
76+
async execBatch(nodes) {
7877
const getNodeFileId = (node) => node?.fileid ?? node?.id
7978

8079
if (nodes.length === 1) {
81-
await this.exec({ nodes })
80+
await this.exec(nodes[0])
8281
return [null]
8382
}
8483

src/actions/showStatusInlineAction.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const getNodeMime = (node) => node?.mime || node?.mimetype || ''
1515
const action = {
1616
id: 'show-status-inline',
1717
displayName: () => '',
18-
title: ({ nodes }) => {
18+
title: (nodes) => {
1919
const node = nodes?.[0]
2020
if (!node || !node.attributes) return ''
2121

@@ -28,15 +28,14 @@ const action = {
2828

2929
return t('libresign', 'original file')
3030
},
31-
exec: async ({ nodes }) => {
31+
exec: async (node) => {
3232
const sidebar = getSidebar()
33-
const node = nodes?.[0]
3433
if (!node) return null
3534
sidebar.open(node, 'libresign')
3635
sidebar.setActiveTab('libresign')
3736
return null
3837
},
39-
iconSvgInline: ({ nodes }) => {
38+
iconSvgInline: (nodes) => {
4039
const node = nodes?.[0]
4140
if (!node || !node.attributes) return ''
4241

@@ -50,7 +49,7 @@ const action = {
5049
return getStatusSvgInline(FILE_STATUS.DRAFT) || ''
5150
},
5251
inline: () => true,
53-
enabled: ({ nodes }) => {
52+
enabled: (nodes) => {
5453
const certificateOk = loadState('libresign', 'certificate_ok')
5554
const allHaveStatus = nodes?.every(node => node.attributes?.['libresign-signature-status'] !== undefined)
5655

src/tests/actions/openInLibreSignAction.spec.ts

Lines changed: 42 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ describe('openInLibreSignAction rules', () => {
9696
order: number
9797
displayName: unknown
9898
iconSvgInline: unknown
99-
enabled: (context: { nodes: unknown }) => boolean
100-
exec: (context: { nodes: unknown }) => Promise<unknown>
101-
execBatch: (context: { nodes: unknown }) => Promise<unknown>
99+
enabled: (nodes: unknown[]) => boolean
100+
exec: (node: unknown, view?: unknown, dir?: unknown) => Promise<unknown>
101+
execBatch: (nodes: unknown[], view?: unknown, dir?: unknown) => Promise<unknown[]>
102102
}
103103
let loadState: { mockReturnValue: (value: unknown) => unknown }
104104
let getCapabilities: { mockReturnValue: (value: unknown) => unknown }
@@ -146,19 +146,15 @@ describe('openInLibreSignAction rules', () => {
146146
it('disables action when certificate not configured', () => {
147147
loadState.mockReturnValue(false)
148148

149-
const enabled = action.enabled({
150-
nodes: [{ type: 'file', mime: 'application/pdf' }],
151-
})
149+
const enabled = action.enabled([{ type: 'file', mime: 'application/pdf' }])
152150

153151
expect(enabled).toBe(false)
154152
})
155153

156154
it('enables action when certificate configured', () => {
157155
loadState.mockReturnValue(true)
158156

159-
const enabled = action.enabled({
160-
nodes: [{ type: 'file', mime: 'application/pdf' }],
161-
})
157+
const enabled = action.enabled([{ type: 'file', mime: 'application/pdf' }])
162158

163159
expect(enabled).toBe(true)
164160
})
@@ -170,47 +166,37 @@ describe('openInLibreSignAction rules', () => {
170166
})
171167

172168
it('enables for single PDF file', () => {
173-
const enabled = action.enabled({
174-
nodes: [{ type: 'file', mime: 'application/pdf' }],
175-
})
169+
const enabled = action.enabled([{ type: 'file', mime: 'application/pdf' }])
176170

177171
expect(enabled).toBe(true)
178172
})
179173

180174
it('disables for single non-PDF file', () => {
181-
const enabled = action.enabled({
182-
nodes: [{ type: 'file', mime: 'image/png' }],
183-
})
175+
const enabled = action.enabled([{ type: 'file', mime: 'image/png' }])
184176

185177
expect(enabled).toBe(false)
186178
})
187179

188180
it('enables for single PDF when only mimetype is provided', () => {
189-
const enabled = action.enabled({
190-
nodes: [{ type: 'file', mimetype: 'application/pdf' }],
191-
})
181+
const enabled = action.enabled([{ type: 'file', mimetype: 'application/pdf' }])
192182

193183
expect(enabled).toBe(true)
194184
})
195185

196186
it('enables for folder with signature status', () => {
197-
const enabled = action.enabled({
198-
nodes: [{
199-
type: 'folder',
200-
attributes: { 'libresign-signature-status': 'signed' },
201-
}],
202-
})
187+
const enabled = action.enabled([{
188+
type: 'folder',
189+
attributes: { 'libresign-signature-status': 'signed' },
190+
}])
203191

204192
expect(enabled).toBe(true)
205193
})
206194

207195
it('disables for folder without signature status', () => {
208-
const enabled = action.enabled({
209-
nodes: [{
210-
type: 'folder',
211-
attributes: {},
212-
}],
213-
})
196+
const enabled = action.enabled([{
197+
type: 'folder',
198+
attributes: {},
199+
}])
214200

215201
expect(enabled).toBe(false)
216202
})
@@ -230,12 +216,10 @@ describe('openInLibreSignAction rules', () => {
230216
},
231217
})
232218

233-
const enabled = action.enabled({
234-
nodes: [
235-
{ type: 'file', mime: 'application/pdf' },
236-
{ type: 'file', mime: 'application/pdf' },
237-
],
238-
})
219+
const enabled = action.enabled([
220+
{ type: 'file', mime: 'application/pdf' },
221+
{ type: 'file', mime: 'application/pdf' },
222+
])
239223

240224
expect(enabled).toBe(true)
241225
})
@@ -249,12 +233,10 @@ describe('openInLibreSignAction rules', () => {
249233
},
250234
})
251235

252-
const enabled = action.enabled({
253-
nodes: [
254-
{ type: 'file', mime: 'application/pdf' },
255-
{ type: 'file', mime: 'application/pdf' },
256-
],
257-
})
236+
const enabled = action.enabled([
237+
{ type: 'file', mime: 'application/pdf' },
238+
{ type: 'file', mime: 'application/pdf' },
239+
])
258240

259241
expect(enabled).toBe(false)
260242
})
@@ -268,12 +250,10 @@ describe('openInLibreSignAction rules', () => {
268250
},
269251
})
270252

271-
const enabled = action.enabled({
272-
nodes: [
273-
{ type: 'file', mime: 'application/pdf' },
274-
{ type: 'file', mime: 'image/png' },
275-
],
276-
})
253+
const enabled = action.enabled([
254+
{ type: 'file', mime: 'application/pdf' },
255+
{ type: 'file', mime: 'image/png' },
256+
])
277257

278258
expect(enabled).toBe(false)
279259
})
@@ -286,7 +266,7 @@ describe('openInLibreSignAction rules', () => {
286266

287267
window.OCA = { Libresign: {} }
288268

289-
await action.execBatch({ nodes })
269+
await action.execBatch(nodes)
290270

291271
const pending = getPendingEnvelope()
292272
expect(pending.files[0].fileId).toBe(999)
@@ -300,17 +280,17 @@ describe('openInLibreSignAction rules', () => {
300280
})
301281

302282
it('disables when nodes array is empty', () => {
303-
const enabled = action.enabled({ nodes: [] })
283+
const enabled = action.enabled([])
304284
expect(enabled).toBe(false)
305285
})
306286

307287
it('disables when nodes is null', () => {
308-
const enabled = action.enabled({ nodes: null })
288+
const enabled = action.enabled(null as unknown as unknown[])
309289
expect(enabled).toBe(false)
310290
})
311291

312292
it('disables when nodes is undefined', () => {
313-
const enabled = action.enabled({ nodes: undefined })
293+
const enabled = action.enabled(undefined as unknown as unknown[])
314294
expect(enabled).toBe(false)
315295
})
316296
})
@@ -323,7 +303,7 @@ describe('openInLibreSignAction rules', () => {
323303
it('opens sidebar with file', async () => {
324304
const node = { type: 'file', mime: 'application/pdf', fileid: 123 }
325305

326-
await action.exec({ nodes: [node] })
306+
await action.exec(node)
327307

328308
expect(mockSidebar.open).toHaveBeenCalledWith(node, 'libresign')
329309
expect(mockSidebar.setActiveTab).toHaveBeenCalledWith('libresign')
@@ -336,14 +316,14 @@ describe('openInLibreSignAction rules', () => {
336316
fileid: 456,
337317
}
338318

339-
await action.exec({ nodes: [node] })
319+
await action.exec(node)
340320

341321
expect(mockSidebar.open).toHaveBeenCalledWith(node, 'libresign')
342322
})
343323

344324
it('returns null after execution', async () => {
345325
const node = { type: 'file', mime: 'application/pdf' }
346-
const result = await action.exec({ nodes: [node] })
326+
const result = await action.exec(node)
347327

348328
expect(result).toBeNull()
349329
})
@@ -392,7 +372,7 @@ let spawnDialog: typeof import('@nextcloud/vue/functions/dialog').spawnDialog
392372
{ type: 'file', mime: 'application/pdf', fileid: 2, dirname: '/Docs' },
393373
]
394374

395-
const result = await action.execBatch({ nodes })
375+
const result = await action.execBatch(nodes)
396376

397377
expect(result).toEqual([null, null])
398378
})
@@ -405,7 +385,7 @@ let spawnDialog: typeof import('@nextcloud/vue/functions/dialog').spawnDialog
405385

406386
window.OCA = { Libresign: {} }
407387

408-
await action.execBatch({ nodes })
388+
await action.execBatch(nodes)
409389

410390
expect(mockSidebar.open).toHaveBeenCalled()
411391
expect(mockSidebar.setActiveTab).toHaveBeenCalledWith('libresign')
@@ -419,7 +399,7 @@ let spawnDialog: typeof import('@nextcloud/vue/functions/dialog').spawnDialog
419399

420400
window.OCA = { Libresign: {} }
421401

422-
await action.execBatch({ nodes })
402+
await action.execBatch(nodes)
423403

424404
const pending = getPendingEnvelope()
425405
expect(pending.nodeType).toBe('envelope')
@@ -436,7 +416,7 @@ let spawnDialog: typeof import('@nextcloud/vue/functions/dialog').spawnDialog
436416

437417
window.OCA = { Libresign: {} }
438418

439-
await action.execBatch({ nodes })
419+
await action.execBatch(nodes)
440420

441421
const pending = getPendingEnvelope()
442422
expect(pending.settings.path).toBe('/Documents/Contracts/Test Envelope')
@@ -450,7 +430,7 @@ let spawnDialog: typeof import('@nextcloud/vue/functions/dialog').spawnDialog
450430

451431
window.OCA = { Libresign: {} }
452432

453-
await action.execBatch({ nodes })
433+
await action.execBatch(nodes)
454434

455435
const pending = getPendingEnvelope()
456436
expect(pending.settings.path).toBe('/Test Envelope')
@@ -464,7 +444,7 @@ let spawnDialog: typeof import('@nextcloud/vue/functions/dialog').spawnDialog
464444

465445
window.OCA = { Libresign: {} }
466446

467-
await action.execBatch({ nodes })
447+
await action.execBatch(nodes)
468448

469449
const pending = getPendingEnvelope()
470450
expect(pending.settings.path).toBe('/Docs/Test Envelope')
@@ -490,7 +470,7 @@ let spawnDialog: typeof import('@nextcloud/vue/functions/dialog').spawnDialog
490470

491471
window.OCA = { Libresign: {} }
492472

493-
await action.execBatch({ nodes })
473+
await action.execBatch(nodes)
494474

495475
const pending = getPendingEnvelope()
496476
expect(pending.files[0].fileId).toBe(123)

0 commit comments

Comments
 (0)