🐛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" />
|
||||
<jest-package value="$PROJECT_DIR$/tdrive/backend/node/node_modules/jest" />
|
||||
<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>
|
||||
<env name="DB_DRIVER" value="mongodb" />
|
||||
<env name="DB_MONGO_URI" value="mongodb://localhost:27017" />
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -163,18 +163,23 @@ export class UserServiceImpl {
|
||||
options?: SearchUserOptions,
|
||||
context?: ExecutionContext,
|
||||
): Promise<ListResult<User>> {
|
||||
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(
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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", () => {
|
||||
|
||||
@@ -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<User> {
|
||||
@@ -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 = [
|
||||
|
||||
Reference in New Issue
Block a user