Skip to content

Commit e98ea40

Browse files
authored
fix(files): check for sharing permission on pasting files only [WPB-18723] (#19258)
* fix(files): check for sharing permission on pasting files only [WPB-18723] * adjust tests
1 parent 9888a3f commit e98ea40

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

src/script/components/InputBar/useFileHandling/useFilePaste/useFilePaste.test.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ describe('useFilePaste', () => {
6767
const calledWithFile = mockOnFilePasted.mock.calls[0][0];
6868
expect(calledWithFile instanceof File).toBe(true);
6969
expect(calledWithFile.name).toBe(`Pasted file from ${mockFormattedDate}.txt`);
70+
expect(checkFileSharingPermissionModule.checkFileSharingPermission).toHaveBeenCalled();
7071
});
7172

7273
it('ignores paste events with text/plain content', () => {
@@ -79,6 +80,7 @@ describe('useFilePaste', () => {
7980
});
8081

8182
expect(mockOnFilePasted).not.toHaveBeenCalled();
83+
expect(checkFileSharingPermissionModule.checkFileSharingPermission).not.toHaveBeenCalled();
8284
});
8385

8486
it('does nothing when no files are pasted', () => {
@@ -92,12 +94,6 @@ describe('useFilePaste', () => {
9294

9395
expect(mockOnFilePasted).not.toHaveBeenCalled();
9496
});
95-
96-
it('uses checkFileSharingPermission wrapper', () => {
97-
renderHook(() => useFilePaste({onFilePasted: mockOnFilePasted}));
98-
99-
expect(checkFileSharingPermissionModule.checkFileSharingPermission).toHaveBeenCalled();
100-
});
10197
});
10298

10399
/**

src/script/components/InputBar/useFileHandling/useFilePaste/useFilePaste.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,15 @@ export const useFilePaste = ({onFilePasted}: UseFilePasteParams) => {
6060
const files = event.clipboardData?.files;
6161

6262
if (files) {
63-
processClipboardFiles(files);
63+
const permissionHandler = checkFileSharingPermission(processClipboardFiles);
64+
permissionHandler(files);
6465
}
6566
},
6667
[processClipboardFiles],
6768
);
6869

6970
useEffect(() => {
70-
document.addEventListener('paste', checkFileSharingPermission(handlePasteEvent));
71-
return () => document.removeEventListener('paste', checkFileSharingPermission(handlePasteEvent));
71+
document.addEventListener('paste', handlePasteEvent);
72+
return () => document.removeEventListener('paste', handlePasteEvent);
7273
}, [handlePasteEvent]);
7374
};

0 commit comments

Comments
 (0)