🐛Do not show anonymous user is the user list everywhere on UI (#182)
* 🐛Do not show anonymous user is the user list everywhere on UI
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
<node-interpreter value="project" />
|
<node-interpreter value="project" />
|
||||||
<jest-package value="$PROJECT_DIR$/tdrive/backend/node/node_modules/jest" />
|
<jest-package value="$PROJECT_DIR$/tdrive/backend/node/node_modules/jest" />
|
||||||
<working-dir value="$PROJECT_DIR$/tdrive/backend/node" />
|
<working-dir value="$PROJECT_DIR$/tdrive/backend/node" />
|
||||||
<jest-options value="--forceExit --coverage --detectOpenHandles --maxWorkers=1 --testTimeout=30000" />
|
<jest-options value="--forceExit --testTimeout=3000000 --maxWorkers=1" />
|
||||||
<envs>
|
<envs>
|
||||||
<env name="DB_DRIVER" value="mongodb" />
|
<env name="DB_DRIVER" value="mongodb" />
|
||||||
<env name="DB_MONGO_URI" value="mongodb://localhost:27017" />
|
<env name="DB_MONGO_URI" value="mongodb://localhost:27017" />
|
||||||
|
|||||||
@@ -557,7 +557,7 @@ export class DocumentsController {
|
|||||||
if (!document || !document.access || document.access === "none")
|
if (!document || !document.access || document.access === "none")
|
||||||
throw new CrudException("You don't have access to this document", 401);
|
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);
|
let user = await globalResolver.services.users.getByEmail(email);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
user = (
|
user = (
|
||||||
@@ -568,9 +568,12 @@ export class DocumentsController {
|
|||||||
email_canonical: email,
|
email_canonical: email,
|
||||||
username_canonical: (email.replace("@", ".") || "").toLocaleLowerCase(),
|
username_canonical: (email.replace("@", ".") || "").toLocaleLowerCase(),
|
||||||
phone: "",
|
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: "anonymous",
|
||||||
identity_provider_id: email,
|
identity_provider_id: email,
|
||||||
mail_verified: true,
|
mail_verified: true,
|
||||||
|
type: "anonymous",
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
).entity;
|
).entity;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import search from "./user.search";
|
|||||||
import { uuid } from "../../../utils/types";
|
import { uuid } from "../../../utils/types";
|
||||||
|
|
||||||
export const TYPE = "user";
|
export const TYPE = "user";
|
||||||
|
export type UserType = "anonymous" | "tech" | "regular";
|
||||||
|
|
||||||
@Entity(TYPE, {
|
@Entity(TYPE, {
|
||||||
primaryKey: [["id"]],
|
primaryKey: [["id"]],
|
||||||
@@ -92,6 +93,9 @@ export default class User {
|
|||||||
@Column("timezone", "string")
|
@Column("timezone", "string")
|
||||||
timezone: string; //Depreciated (php legacy)
|
timezone: string; //Depreciated (php legacy)
|
||||||
|
|
||||||
|
@Column("type", "string")
|
||||||
|
type: UserType;
|
||||||
|
|
||||||
@Column("preferences", "encoded_json")
|
@Column("preferences", "encoded_json")
|
||||||
preferences: null | {
|
preferences: null | {
|
||||||
locale?: string;
|
locale?: string;
|
||||||
|
|||||||
@@ -163,18 +163,23 @@ export class UserServiceImpl {
|
|||||||
options?: SearchUserOptions,
|
options?: SearchUserOptions,
|
||||||
context?: ExecutionContext,
|
context?: ExecutionContext,
|
||||||
): Promise<ListResult<User>> {
|
): Promise<ListResult<User>> {
|
||||||
return await this.searchRepository.search(
|
return await this.searchRepository
|
||||||
{},
|
.search(
|
||||||
{
|
{},
|
||||||
pagination,
|
{
|
||||||
...(options.companyId ? { $in: [["companies", [options.companyId]]] } : {}),
|
pagination,
|
||||||
...(options.workspaceId ? { $in: [["workspaces", [options.workspaceId]]] } : {}),
|
...(options.companyId ? { $in: [["companies", [options.companyId]]] } : {}),
|
||||||
$text: {
|
...(options.workspaceId ? { $in: [["workspaces", [options.workspaceId]]] } : {}),
|
||||||
$search: options.search,
|
$text: {
|
||||||
|
$search: options.search,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
context,
|
||||||
context,
|
)
|
||||||
);
|
.then(users => {
|
||||||
|
users.filterEntities(u => u.identity_provider != "anonymous" && u.type != "anonymous");
|
||||||
|
return users;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async list(
|
async list(
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ export default class TestHelpers {
|
|||||||
platform: TestPlatform;
|
platform: TestPlatform;
|
||||||
dbService: TestDbService;
|
dbService: TestDbService;
|
||||||
user: User;
|
user: User;
|
||||||
|
anonymous: User;
|
||||||
workspace: Workspace;
|
workspace: Workspace;
|
||||||
jwt: string;
|
jwt: string;
|
||||||
|
|
||||||
@@ -45,6 +46,11 @@ export default class TestHelpers {
|
|||||||
this.workspace = this.platform.workspace;
|
this.workspace = this.platform.workspace;
|
||||||
const workspacePK = {id: this.workspace.workspace_id, company_id: this.workspace.company_id};
|
const workspacePK = {id: this.workspace.workspace_id, company_id: this.workspace.company_id};
|
||||||
this.user = await this.dbService.createUser([workspacePK], options, uuidv1());
|
this.user = await this.dbService.createUser([workspacePK], options, uuidv1());
|
||||||
|
this.anonymous = await this.dbService.createUser([workspacePK],
|
||||||
|
{ ...options,
|
||||||
|
identity_provider: "anonymous",
|
||||||
|
},
|
||||||
|
uuidv1());
|
||||||
} else {
|
} else {
|
||||||
this.user = this.platform.currentUser;
|
this.user = this.platform.currentUser;
|
||||||
this.workspace = this.platform.workspace;
|
this.workspace = this.platform.workspace;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { init, TestPlatform } from "../setup";
|
|||||||
import { TestDbService } from "../utils.prepare.db";
|
import { TestDbService } from "../utils.prepare.db";
|
||||||
import { v1 as uuidv1 } from "uuid";
|
import { v1 as uuidv1 } from "uuid";
|
||||||
import { CompanyLimitsEnum } from "../../../src/services/user/web/types";
|
import { CompanyLimitsEnum } from "../../../src/services/user/web/types";
|
||||||
|
import TestHelpers from "../common/common_test_helpers";
|
||||||
|
|
||||||
describe("The /users API", () => {
|
describe("The /users API", () => {
|
||||||
const url = "/internal/services/users/v1";
|
const url = "/internal/services/users/v1";
|
||||||
@@ -209,8 +210,32 @@ describe("The /users API", () => {
|
|||||||
expect(response.statusCode).toBe(200);
|
expect(response.statusCode).toBe(200);
|
||||||
const json = response.json();
|
const json = response.json();
|
||||||
expect(json).toMatchObject({ resources: expect.any(Array) });
|
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", () => {
|
describe("The GET /users/:user_id/companies route", () => {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { TestPlatform } from "./setup";
|
import { TestPlatform } from "./setup";
|
||||||
import User from "./../../src/services/user/entities/user";
|
import User, { UserType } from "./../../src/services/user/entities/user";
|
||||||
import Company, {
|
import Company, {
|
||||||
getInstance as getCompanyInstance,
|
getInstance as getCompanyInstance,
|
||||||
} from "./../../src/services/user/entities/company";
|
} from "./../../src/services/user/entities/company";
|
||||||
@@ -128,6 +128,8 @@ export class TestDbService {
|
|||||||
username?: string;
|
username?: string;
|
||||||
password?: string;
|
password?: string;
|
||||||
cache?: User["cache"];
|
cache?: User["cache"];
|
||||||
|
identity_provider?: string;
|
||||||
|
type?: UserType;
|
||||||
} = {},
|
} = {},
|
||||||
id: string = uuidv1(),
|
id: string = uuidv1(),
|
||||||
): Promise<User> {
|
): Promise<User> {
|
||||||
@@ -140,6 +142,8 @@ export class TestDbService {
|
|||||||
user.email_canonical = options.email || `test${random}@tdrive.app`;
|
user.email_canonical = options.email || `test${random}@tdrive.app`;
|
||||||
user.identity_provider_id = user.id;
|
user.identity_provider_id = user.id;
|
||||||
user.cache = options.cache || user.cache || { companies: [] };
|
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
|
//Fixme this is cheating, we should correctly set the cache in internal mode in the code
|
||||||
user.cache.companies = [
|
user.cache.companies = [
|
||||||
|
|||||||
Reference in New Issue
Block a user