From aad19f65a35211fad5697fafe5189d4fec813f9f Mon Sep 17 00:00:00 2001 From: Joakim Bygdell Date: Wed, 24 Jul 2024 13:06:55 +0200 Subject: [PATCH] [api] only return files not part of a dataset when listing a users files --- sda/cmd/api/api_test.go | 2 +- sda/internal/database/db_functions.go | 11 +++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/sda/cmd/api/api_test.go b/sda/cmd/api/api_test.go index 367b0d4ee..4b576a022 100644 --- a/sda/cmd/api/api_test.go +++ b/sda/cmd/api/api_test.go @@ -1194,5 +1194,5 @@ func (suite *TestSuite) TestListUserFiles() { files := []database.SubmissionFileInfo{} err = json.NewDecoder(okResponse.Body).Decode(&files) assert.NoError(suite.T(), err, "failed to list users from DB") - assert.Equal(suite.T(), 5, len(files)) + assert.Equal(suite.T(), 2, len(files)) } diff --git a/sda/internal/database/db_functions.go b/sda/internal/database/db_functions.go index 499b4e9e2..8794a8e28 100644 --- a/sda/internal/database/db_functions.go +++ b/sda/internal/database/db_functions.go @@ -635,14 +635,9 @@ func (dbs *SDAdb) getUserFiles(userID string) ([]*SubmissionFileInfo, error) { db := dbs.DB // select all files of the user, each one annotated with its latest event - const query = "SELECT f.submission_file_path, e.event, f.created_at " + - "FROM sda.files f " + - "LEFT JOIN ( " + - "SELECT DISTINCT ON (file_id) file_id, started_at, event " + - "FROM sda.file_event_log " + - "ORDER BY file_id, started_at DESC" + - ") e ON f.id = e.file_id " + - "WHERE f.submission_user = $1; " + const query = "SELECT f.submission_file_path, e.event, f.created_at FROM sda.files f " + + "LEFT JOIN (SELECT DISTINCT ON (file_id) file_id, started_at, event FROM sda.file_event_log ORDER BY file_id, started_at DESC) e ON f.id = e.file_id WHERE f.submission_user = $1 " + + "AND f.id NOT IN (SELECT f.id FROM sda.files f RIGHT JOIN sda.file_dataset d ON f.id = d.file_id); " // nolint:rowserrcheck rows, err := db.Query(query, userID)