From 732467634ee22a4100a9ab8acd2482952c734934 Mon Sep 17 00:00:00 2001 From: Ian Chen Date: Mon, 9 Dec 2024 18:49:16 +0800 Subject: [PATCH 1/2] chore: prevent updating last accessed at when using admin portal (#813) Prevent updating last accessed at when `context.isAdminOperation` is true --- .../queries/tiles/get-all-rows.itest.ts | 39 +++++++++++++++++++ .../src/graphql/queries/tiles/get-all-rows.ts | 2 +- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/graphql/__tests__/queries/tiles/get-all-rows.itest.ts b/packages/backend/src/graphql/__tests__/queries/tiles/get-all-rows.itest.ts index 9fdecadb5..08400183f 100644 --- a/packages/backend/src/graphql/__tests__/queries/tiles/get-all-rows.itest.ts +++ b/packages/backend/src/graphql/__tests__/queries/tiles/get-all-rows.itest.ts @@ -172,4 +172,43 @@ describe('get all rows query', () => { ), ).rejects.toThrow('Table not found') }) + + describe('last accessed at', () => { + it('should update last accessed at for current user', async () => { + const oldLastAccessedAt = new Date().toISOString() + await TableCollaborator.query() + .patch({ + lastAccessedAt: oldLastAccessedAt, + }) + .where('table_id', dummyTable.id) + .andWhere('user_id', context.currentUser.id) + await getAllRows(null, { tableId: dummyTable.id }, context) + const { lastAccessedAt } = await TableCollaborator.query().findOne({ + table_id: dummyTable.id, + user_id: context.currentUser.id, + }) + expect(new Date(lastAccessedAt).getTime()).toBeGreaterThan( + new Date(oldLastAccessedAt).getTime(), + ) + }) + + it('should not update last accessed at for admin operations', async () => { + context.isAdminOperation = true + const oldLastAccessedAt = new Date().toISOString() + await TableCollaborator.query() + .patch({ + lastAccessedAt: oldLastAccessedAt, + }) + .where('table_id', dummyTable.id) + .andWhere('user_id', context.currentUser.id) + await getAllRows(null, { tableId: dummyTable.id }, context) + const { lastAccessedAt } = await TableCollaborator.query().findOne({ + table_id: dummyTable.id, + user_id: context.currentUser.id, + }) + expect(new Date(lastAccessedAt).getTime()).toEqual( + new Date(oldLastAccessedAt).getTime(), + ) + }) + }) }) diff --git a/packages/backend/src/graphql/queries/tiles/get-all-rows.ts b/packages/backend/src/graphql/queries/tiles/get-all-rows.ts index 59798e599..c67136baf 100644 --- a/packages/backend/src/graphql/queries/tiles/get-all-rows.ts +++ b/packages/backend/src/graphql/queries/tiles/get-all-rows.ts @@ -30,7 +30,7 @@ const getAllRows: QueryResolvers['getAllRows'] = async ( .throwIfNotFound() // update last accessed at for collaborator/table - if (!context.tilesViewKey) { + if (!context.tilesViewKey && !context.isAdminOperation) { await table.$relatedQuery('collaborators').patch({ lastAccessedAt: new Date().toISOString(), }) From 00875d62bb136065233e90a3a3c2cb30d45d2099 Mon Sep 17 00:00:00 2001 From: Ian Chen Date: Mon, 9 Dec 2024 18:53:06 +0800 Subject: [PATCH 2/2] v1.31.1 --- package-lock.json | 6 +++--- packages/backend/package.json | 2 +- packages/frontend/package.json | 2 +- packages/types/package.json | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5be5b19e7..dfde0d7a7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23451,7 +23451,7 @@ } }, "packages/backend": { - "version": "1.31.0", + "version": "1.31.1", "dependencies": { "@apollo/server": "4.9.4", "@aws-sdk/client-dynamodb": "3.460.0", @@ -23551,7 +23551,7 @@ } }, "packages/frontend": { - "version": "1.31.0", + "version": "1.31.1", "hasInstallScript": true, "dependencies": { "@datadog/browser-rum": "^5.2.0", @@ -23762,7 +23762,7 @@ }, "packages/types": { "name": "@plumber/types", - "version": "1.31.0" + "version": "1.31.1" } } } diff --git a/packages/backend/package.json b/packages/backend/package.json index 695fb6cfe..55097c99c 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -105,5 +105,5 @@ "tsconfig-paths": "^4.2.0", "type-fest": "4.10.3" }, - "version": "1.31.0" + "version": "1.31.1" } diff --git a/packages/frontend/package.json b/packages/frontend/package.json index b9fd78fbf..8f3876f03 100644 --- a/packages/frontend/package.json +++ b/packages/frontend/package.json @@ -1,6 +1,6 @@ { "name": "frontend", - "version": "1.31.0", + "version": "1.31.1", "scripts": { "dev": "wait-on tcp:3000 && vite --host --force", "build": "tsc && vite build --mode=${VITE_MODE:-prod}", diff --git a/packages/types/package.json b/packages/types/package.json index 412c97f98..fe00608d3 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -2,5 +2,5 @@ "name": "@plumber/types", "description": "Shared types for plumber", "types": "./index.d.ts", - "version": "1.31.0" + "version": "1.31.1" }