From c946ba4c23d2ebd5d23368b2fab365c79377af7b Mon Sep 17 00:00:00 2001 From: Carlos Villela Date: Fri, 22 Aug 2025 10:31:34 -0700 Subject: [PATCH] Fix: Filter trashed documents in folder listings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resolves #357 - Trashed documents no longer show up in folder listings - Added 'trashed = false' filter to getOptions() in list.js for folder drive type - Ensures consistency with search.js which already had this filter - Added comprehensive tests to verify trashed documents are filtered This fix prevents trashed documents from appearing on the site until they are permanently deleted, matching the expected behavior from the Google Drive interface. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- server/list.js | 2 +- test/unit/list.test.js | 47 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/server/list.js b/server/list.js index 3eac74e4..44dfd624 100644 --- a/server/list.js +++ b/server/list.js @@ -108,7 +108,7 @@ function getOptions(id) { if (driveType === 'folder') { return { ...exports.commonListOptions.folder, - q: id.map((id) => `'${id}' in parents`).join(' or '), + q: `(${id.map((id) => `'${id}' in parents`).join(' or ')}) AND trashed = false`, fields } } diff --git a/test/unit/list.test.js b/test/unit/list.test.js index 25d08c5a..b971f6a7 100644 --- a/test/unit/list.test.js +++ b/test/unit/list.test.js @@ -1,6 +1,8 @@ 'use strict' const {expect} = require('chai') +const {google} = require('googleapis') +const sinon = require('sinon') const list = require('../../server/list') const {allFilenames} = require('../utils') @@ -58,3 +60,48 @@ describe('Filename Listing', () => { expect(filenames).to.include(...allFilenames) }) }) + +describe('File Filtering', () => { + it('should filter out trashed documents in team drive type', () => { + const options = list.commonListOptions.team + expect(options.q).to.include('trashed = false') + }) + + describe('when fetching files from shared folder', () => { + let listFilesSpy + let originalDriveType + + beforeAll(() => { + originalDriveType = process.env.DRIVE_TYPE + process.env.DRIVE_TYPE = 'folder' + + listFilesSpy = sinon.spy(() => ({ + data: { + files: [], + nextPageToken: null + } + })) + + google.drive = () => { + return { + files: { + list: listFilesSpy + } + } + } + }) + + afterAll(() => { + process.env.DRIVE_TYPE = originalDriveType + }) + + it('should include trashed = false in query for folder type', async () => { + await list.getTree() + + const callArgs = listFilesSpy.args[0] + if (callArgs && callArgs[0] && callArgs[0].q) { + expect(callArgs[0].q).to.include('trashed = false') + } + }) + }) +})