diff --git a/.run/Run all e2e [MongoDB].run.xml b/.run/Run all e2e [MongoDB].run.xml index 70d8a37c..c0ac2a18 100644 --- a/.run/Run all e2e [MongoDB].run.xml +++ b/.run/Run all e2e [MongoDB].run.xml @@ -3,7 +3,7 @@ - + diff --git a/tdrive/backend/node/src/services/documents/web/controllers/documents.ts b/tdrive/backend/node/src/services/documents/web/controllers/documents.ts index 32d1f243..8cf87a25 100644 --- a/tdrive/backend/node/src/services/documents/web/controllers/documents.ts +++ b/tdrive/backend/node/src/services/documents/web/controllers/documents.ts @@ -557,7 +557,7 @@ export class DocumentsController { if (!document || !document.access || document.access === "none") throw new CrudException("You don't have access to this document", 401); - const email = `anonymous@${document.item.company_id}.tdrive.com`; + const email = `anonymous@tdrive.${document.item.company_id}.com`; let user = await globalResolver.services.users.getByEmail(email); if (!user) { user = ( @@ -568,9 +568,12 @@ export class DocumentsController { email_canonical: email, username_canonical: (email.replace("@", ".") || "").toLocaleLowerCase(), phone: "", + // TODO fix the identity provider after creating migration script mechanics, + // this is user type of the user account and not the provider identity_provider: "anonymous", identity_provider_id: email, mail_verified: true, + type: "anonymous", }), ) ).entity; diff --git a/tdrive/backend/node/src/services/user/entities/user.ts b/tdrive/backend/node/src/services/user/entities/user.ts index 0be7e75b..fa1acc8c 100644 --- a/tdrive/backend/node/src/services/user/entities/user.ts +++ b/tdrive/backend/node/src/services/user/entities/user.ts @@ -4,6 +4,7 @@ import search from "./user.search"; import { uuid } from "../../../utils/types"; export const TYPE = "user"; +export type UserType = "anonymous" | "tech" | "regular"; @Entity(TYPE, { primaryKey: [["id"]], @@ -92,6 +93,9 @@ export default class User { @Column("timezone", "string") timezone: string; //Depreciated (php legacy) + @Column("type", "string") + type: UserType; + @Column("preferences", "encoded_json") preferences: null | { locale?: string; diff --git a/tdrive/backend/node/src/services/user/services/users/service.ts b/tdrive/backend/node/src/services/user/services/users/service.ts index 69b2e9fe..46ebef29 100644 --- a/tdrive/backend/node/src/services/user/services/users/service.ts +++ b/tdrive/backend/node/src/services/user/services/users/service.ts @@ -163,18 +163,23 @@ export class UserServiceImpl { options?: SearchUserOptions, context?: ExecutionContext, ): Promise> { - return await this.searchRepository.search( - {}, - { - pagination, - ...(options.companyId ? { $in: [["companies", [options.companyId]]] } : {}), - ...(options.workspaceId ? { $in: [["workspaces", [options.workspaceId]]] } : {}), - $text: { - $search: options.search, + return await this.searchRepository + .search( + {}, + { + pagination, + ...(options.companyId ? { $in: [["companies", [options.companyId]]] } : {}), + ...(options.workspaceId ? { $in: [["workspaces", [options.workspaceId]]] } : {}), + $text: { + $search: options.search, + }, }, - }, - context, - ); + context, + ) + .then(users => { + users.filterEntities(u => u.identity_provider != "anonymous" && u.type != "anonymous"); + return users; + }); } async list( diff --git a/tdrive/backend/node/test/e2e/common/common_test_helpers.ts b/tdrive/backend/node/test/e2e/common/common_test_helpers.ts index 6a2ae2f8..03075898 100644 --- a/tdrive/backend/node/test/e2e/common/common_test_helpers.ts +++ b/tdrive/backend/node/test/e2e/common/common_test_helpers.ts @@ -30,6 +30,7 @@ export default class TestHelpers { platform: TestPlatform; dbService: TestDbService; user: User; + anonymous: User; workspace: Workspace; jwt: string; @@ -45,6 +46,11 @@ export default class TestHelpers { this.workspace = this.platform.workspace; const workspacePK = {id: this.workspace.workspace_id, company_id: this.workspace.company_id}; this.user = await this.dbService.createUser([workspacePK], options, uuidv1()); + this.anonymous = await this.dbService.createUser([workspacePK], + { ...options, + identity_provider: "anonymous", + }, + uuidv1()); } else { this.user = this.platform.currentUser; this.workspace = this.platform.workspace; diff --git a/tdrive/backend/node/test/e2e/users/users.spec.ts b/tdrive/backend/node/test/e2e/users/users.spec.ts index 1557a4dc..534db1a4 100644 --- a/tdrive/backend/node/test/e2e/users/users.spec.ts +++ b/tdrive/backend/node/test/e2e/users/users.spec.ts @@ -3,6 +3,7 @@ import { init, TestPlatform } from "../setup"; import { TestDbService } from "../utils.prepare.db"; import { v1 as uuidv1 } from "uuid"; import { CompanyLimitsEnum } from "../../../src/services/user/web/types"; +import TestHelpers from "../common/common_test_helpers"; describe("The /users API", () => { const url = "/internal/services/users/v1"; @@ -209,8 +210,32 @@ describe("The /users API", () => { expect(response.statusCode).toBe(200); const json = response.json(); expect(json).toMatchObject({ resources: expect.any(Array) }); - const resources = json.resources; }); + + it("shouldn't return anonymous accounts ", async () => { + const oneUser = await TestHelpers.getInstance(platform, true); + + const response = await platform.app.inject({ + method: "GET", + url: `${url}/users`, + headers: { + authorization: `Bearer ${oneUser.jwt}`, + }, + query: { + search: "anon", + company_ids: oneUser.workspace.company_id + }, + }); + + expect(response.statusCode).toBe(200); + const json = response.json(); + expect(json).toMatchObject({ resources: expect.any(Array) }); + const resources = json.resources; + console.log(resources); + expect(resources.length).toBe(0); + + }); + }); describe("The GET /users/:user_id/companies route", () => { diff --git a/tdrive/backend/node/test/e2e/utils.prepare.db.ts b/tdrive/backend/node/test/e2e/utils.prepare.db.ts index b3f6ffb3..12284a8e 100644 --- a/tdrive/backend/node/test/e2e/utils.prepare.db.ts +++ b/tdrive/backend/node/test/e2e/utils.prepare.db.ts @@ -1,5 +1,5 @@ import { TestPlatform } from "./setup"; -import User from "./../../src/services/user/entities/user"; +import User, { UserType } from "./../../src/services/user/entities/user"; import Company, { getInstance as getCompanyInstance, } from "./../../src/services/user/entities/company"; @@ -128,6 +128,8 @@ export class TestDbService { username?: string; password?: string; cache?: User["cache"]; + identity_provider?: string; + type?: UserType; } = {}, id: string = uuidv1(), ): Promise { @@ -140,6 +142,8 @@ export class TestDbService { user.email_canonical = options.email || `test${random}@tdrive.app`; user.identity_provider_id = user.id; user.cache = options.cache || user.cache || { companies: [] }; + user.identity_provider = options.identity_provider || "console"; + user.type = options.type || "regular"; //Fixme this is cheating, we should correctly set the cache in internal mode in the code user.cache.companies = [