Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🛠 global resolver #2023

Merged
merged 19 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
65e7312
global resolver
romanesko Mar 22, 2022
3bfdb4d
global resolver
romanesko Mar 23, 2022
9114cfd
global resolver
romanesko Mar 24, 2022
4df4aed
global resolver
romanesko Mar 29, 2022
12f50f2
global resolver
romanesko Mar 30, 2022
ad436d7
global resolver
romanesko Mar 30, 2022
e9df269
merge conflicts fix
romanesko Apr 1, 2022
a22bb3b
Merge remote-tracking branch 'origin/develop' into global-resolver
romanesko Apr 11, 2022
34fdf1c
global-resolver merge issues
romanesko Apr 11, 2022
4740bd5
Merge branch 'develop' of https://github.com/linagora/Twake into glob…
romanesko Apr 11, 2022
3197225
Merge branch 'develop' of https://github.com/linagora/Twake into glob…
romanesko Apr 11, 2022
eafc1e5
Merge branch 'develop' of https://github.com/linagora/Twake into glob…
romanesko Apr 11, 2022
721d39b
Merge branch 'develop' of https://github.com/linagora/Twake into glob…
romanesko Apr 11, 2022
67028a4
Merge branch 'develop' of https://github.com/linagora/Twake into glob…
romanesko Apr 11, 2022
ab7daec
Merge branch 'develop' of https://github.com/linagora/Twake into glob…
romanesko Apr 11, 2022
56c5271
Merge branch 'develop' of https://github.com/linagora/Twake into glob…
romanesko Apr 12, 2022
8752f73
Merge branch 'develop' of https://github.com/linagora/Twake into glob…
romanesko Apr 13, 2022
803f0a2
Merge branch 'develop' of https://github.com/linagora/Twake into glob…
romanesko Apr 14, 2022
dc84425
Merge branch 'develop' of github.com:romanesko/Twake into global-reso…
romanesko Apr 14, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions twake/backend/node/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@
"database": "twake"
},
"cassandra": {
"contactPoints": ["scylladb:9042"],
"contactPoints": [
"scylladb:9042"
],
"localDataCenter": "datacenter1",
"keyspace": "twake",
"wait": false,
Expand All @@ -107,7 +109,9 @@
"// possible 'type' values are": "'amqp' or 'local'",
"type": "amqp",
"amqp": {
"urls": ["amqp://guest:guest@rabbitmq:5672"]
"urls": [
"amqp://guest:guest@rabbitmq:5672"
]
}
},
"search": {
Expand Down Expand Up @@ -148,6 +152,7 @@
"webserver",
"websocket",
"database",
"cron",
"search",
"pubsub",
"realtime",
Expand All @@ -164,10 +169,8 @@
"workspaces",
"console",
"previews",
"platform-services",
"counter",
"statistics",
"cron",
"online"
]
}
12,877 changes: 0 additions & 12,877 deletions twake/backend/node/package-lock.json

This file was deleted.

1 change: 1 addition & 0 deletions twake/backend/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"serve:debug": "nodemon --inspect dist/server.js | pino-pretty",
"start": "npm run serve",
"test": "jest --forceExit --coverage --detectOpenHandles --runInBand --verbose false | pino-pretty",
"test:local": "jest --forceExit --detectOpenHandles --runInBand mock.spec.ts",
"test:watch": "npm run test -- --watchAll --verbose false | pino-pretty",
"test:e2e": "node ./test/e2e/run-all.js",
"test:unit": "jest test/unit --forceExit --coverage --detectOpenHandles --maxWorkers=1 --testTimeout=30000 --verbose false",
Expand Down
10 changes: 4 additions & 6 deletions twake/backend/node/src/cli/cmds/applications_cmds/ls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import yargs from "yargs";
import ora from "ora";
import twake from "../../../twake";
import Table from "cli-table";
import { ApplicationServiceAPI } from "../../../services/applications/api";
import * as process from "process";
import gr from "../../../services/global-resolver";

/**
* Merge command parameters. Check the builder definition below for more details.
*/
type CLIArgs = {};
type CLIArgs = Record<string, unknown>;

const services = [
"storage",
Expand All @@ -33,9 +33,9 @@ const command: yargs.CommandModule<unknown, CLIArgs> = {
handler: async argv => {
const spinner = ora({ text: "Retrieving applications" }).start();
const platform = await twake.run(services);
const applicationService = platform.getProvider<ApplicationServiceAPI>("applications");
await gr.doInit(platform);
//
const unpublished = await applicationService.applications.listUnpublished();
const unpublished = await gr.services.applications.marketplaceApps.listUnpublished();
//
const table = new Table({
head: ["ID", "Name", "Description"],
Expand All @@ -51,6 +51,4 @@ const command: yargs.CommandModule<unknown, CLIArgs> = {
},
};

const showUnpublishedApplications = async () => {};

export default command;
11 changes: 5 additions & 6 deletions twake/backend/node/src/cli/cmds/applications_cmds/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import yargs from "yargs";
import ora from "ora";
import twake from "../../../twake";
import Table from "cli-table";
import { ApplicationServiceAPI } from "../../../services/applications/api";
import * as process from "process";

import gr from "../../../services/global-resolver";
/**
* Merge command parameters. Check the builder definition below for more details.
*/
Expand Down Expand Up @@ -43,8 +42,8 @@ const command: yargs.CommandModule<unknown, CLIArgs> = {
if (argv.id) {
let spinner = ora({ text: "Retrieving application" }).start();
const platform = await twake.run(services);
const service = platform.getProvider<ApplicationServiceAPI>("applications");
let app = await service.applications.get({ id: argv.id });
await gr.doInit(platform);
let app = await gr.services.applications.marketplaceApps.get({ id: argv.id });
spinner.stop();
if (!app) {
console.error(`Application ${argv.id} not found`);
Expand Down Expand Up @@ -72,8 +71,8 @@ const command: yargs.CommandModule<unknown, CLIArgs> = {
}

spinner = ora({ text: "Publishing application" }).start();
await service.applications.publish({ id: argv.id });
app = await service.applications.get({ id: argv.id });
await gr.services.applications.marketplaceApps.publish({ id: argv.id });
app = await gr.services.applications.marketplaceApps.get({ id: argv.id });

spinner.stop();
console.log("Application published");
Expand Down
11 changes: 5 additions & 6 deletions twake/backend/node/src/cli/cmds/applications_cmds/unpublish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import yargs from "yargs";
import ora from "ora";
import twake from "../../../twake";
import Table from "cli-table";
import { ApplicationServiceAPI } from "../../../services/applications/api";
import * as process from "process";

import gr from "../../../services/global-resolver";
/**
* Merge command parameters. Check the builder definition below for more details.
*/
Expand Down Expand Up @@ -35,8 +34,8 @@ const command: yargs.CommandModule<unknown, CLIArgs> = {
if (argv.id) {
let spinner = ora({ text: "Retrieving application" }).start();
const platform = await twake.run(services);
const service = platform.getProvider<ApplicationServiceAPI>("applications");
let app = await service.applications.get({ id: argv.id });
await gr.doInit(platform);
let app = await gr.services.applications.marketplaceApps.get({ id: argv.id });
spinner.stop();
if (!app) {
console.error(`Application ${argv.id} not found`);
Expand All @@ -57,8 +56,8 @@ const command: yargs.CommandModule<unknown, CLIArgs> = {
}

spinner = ora({ text: "Unpublishing application" }).start();
await service.applications.unpublish({ id: argv.id });
app = await service.applications.get({ id: argv.id });
await gr.services.applications.marketplaceApps.unpublish({ id: argv.id });
app = await gr.services.applications.marketplaceApps.get({ id: argv.id });
spinner.stop();
console.log("Application unpublished");

Expand Down
2 changes: 2 additions & 0 deletions twake/backend/node/src/cli/cmds/console_cmds/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import twake from "../../../twake";
import { ConsoleServiceAPI } from "../../../services/console/api";
import { CompanyReport, UserReport } from "../../../services/console/types";
import Company from "../../../services/user/entities/company";
import gr from "../../../services/global-resolver";

/**
* Merge command parameters. Check the builder definition below for more details.
Expand Down Expand Up @@ -80,6 +81,7 @@ const command: yargs.CommandModule<MergeParams, MergeParams> = {
handler: async argv => {
const spinner = ora({ text: `Importing Twake data on ${argv.url}` }).start();
const platform = await twake.run(services);
await gr.doInit(platform);
const consoleService = platform.getProvider<ConsoleServiceAPI>("console");
const merge = consoleService.merge(
argv.url,
Expand Down
58 changes: 27 additions & 31 deletions twake/backend/node/src/cli/cmds/export_cmds/export_company.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import yargs from "yargs";
import twake from "../../../twake";
import UserServiceAPI from "../../../services/user/api";
import { mkdirSync, writeFileSync } from "fs";
import { WorkspaceServiceAPI } from "../../../services/workspaces/api";
import { Pagination } from "../../../core/platform/framework/api/crud-service";
import WorkspaceUser from "../../../services/workspaces/entities/workspace_user";
import { ApplicationServiceAPI } from "../../../services/applications/api";
import ChannelServiceAPI from "../../../services/channels/provider";
import { ChannelVisibility } from "../../../services/channels/types";
import { Channel, ChannelMember } from "../../../services/channels/entities";
import { MessageServiceAPI } from "../../../services/messages/api";
import { Thread } from "../../../services/messages/entities/threads";
import { Message } from "../../../services/messages/entities/messages";
import { MessageWithReplies } from "../../../services/messages/types";
import { formatCompany } from "../../../services/user/utils";
import gr from "../../../services/global-resolver";
import { formatUser } from "../../../utils/users";

/**
* Merge command parameters. Check the builder definition below for more details.
Expand Down Expand Up @@ -59,9 +55,9 @@ const command: yargs.CommandModule<unknown, CLIArgs> = {
},
handler: async argv => {
const platform = await twake.run(services);
const userService = platform.getProvider<UserServiceAPI>("user");
await gr.doInit(platform);

const company = await userService.companies.getCompany({ id: argv.id });
const company = await gr.services.companies.getCompany({ id: argv.id });

if (!company) {
return "No such company";
Expand All @@ -73,33 +69,33 @@ const command: yargs.CommandModule<unknown, CLIArgs> = {
mkdirSync(output, { recursive: true });

//Company
console.log(`- Create company json file`);
console.log("- Create company json file");
writeFileSync(`${output}/company.json`, JSON.stringify(formatCompany(company)));

//Workspaces
console.log(`- Create workspaces json file`);
const workspaces = await userService.workspaces.getAllForCompany(company.id);
console.log("- Create workspaces json file");
const workspaces = await gr.services.workspaces.getAllForCompany(company.id);
writeFileSync(`${output}/workspaces.json`, JSON.stringify(workspaces));

//Users
console.log(`- Create users json file`);
let users = [];
console.log("- Create users json file");
const users = [];
for (const workspace of workspaces) {
let workspace_users = [];
const workspace_users = [];
let workspaceUsers: WorkspaceUser[] = [];
let pagination = new Pagination();
do {
const res = await userService.workspaces.getUsers(
const res = await gr.services.workspaces.getUsers(
{ workspaceId: workspace.id },
pagination,
);
workspaceUsers = [...workspaceUsers, ...res.getEntities()];
pagination = res.nextPage as Pagination;
} while (pagination.page_token);
for (const workspaceUser of workspaceUsers) {
const user = await userService.users.get({ id: workspaceUser.userId });
const user = await gr.services.users.get({ id: workspaceUser.userId });
if (user) {
users.push(await userService.formatUser(user));
users.push(await formatUser(user));
workspace_users.push({ ...workspaceUser, user });
}
}
Expand All @@ -112,26 +108,27 @@ const command: yargs.CommandModule<unknown, CLIArgs> = {
writeFileSync(`${output}/users.json`, JSON.stringify(users));

//Applications
console.log(`- Create applications json file`);
const applicationService = platform.getProvider<ApplicationServiceAPI>("applications");
const applications = await applicationService.companyApplications.list(
console.log("- Create applications json file");
const applications = await gr.services.applications.companyApps.list(
new Pagination(),
{},
{ company: { id: company.id }, user: { id: "", server_request: true } },
);
writeFileSync(`${output}/applications.json`, JSON.stringify(applications));

//Channels
console.log(`- Create channels json file`);
let directChannels: Channel[] = [];
console.log("- Create channels json file");
const directChannels: Channel[] = [];
let allPublicChannels: Channel[] = [];
const channelService = platform.getProvider<ChannelServiceAPI>("channels");

let pagination = new Pagination();
do {
const page = await channelService.channels.getDirectChannelsInCompany(pagination, company.id);
const page = await gr.services.channels.channels.getDirectChannelsInCompany(
pagination,
company.id,
);
for (const channel of page.getEntities()) {
const channelDetail = await channelService.channels.get(
const channelDetail = await gr.services.channels.channels.get(
{
company_id: channel.company_id,
workspace_id: "direct",
Expand All @@ -153,7 +150,7 @@ const command: yargs.CommandModule<unknown, CLIArgs> = {
let publicChannels: Channel[] = [];
pagination = new Pagination();
do {
const page = await channelService.channels.list(
const page = await gr.services.channels.channels.list(
pagination,
{},
{
Expand All @@ -176,12 +173,12 @@ const command: yargs.CommandModule<unknown, CLIArgs> = {
writeFileSync(`${output}/direct_channels.json`, JSON.stringify(directChannels));

//Channels users
console.log(`- Create channels users json file`);
console.log("- Create channels users json file");
for (const channel of [...allPublicChannels /*, ...directChannels*/]) {
let members: ChannelMember[] = [];
let pagination = new Pagination();
do {
const page = await channelService.members.list(
const page = await gr.services.channels.members.list(
pagination,
{},
{
Expand All @@ -207,16 +204,15 @@ const command: yargs.CommandModule<unknown, CLIArgs> = {
}

//Messages
console.log(`- Create messages json file`);
const messageService = platform.getProvider<MessageServiceAPI>("messages");
console.log("- Create messages json file");
//Note: direct channels content is private and not needed for R&D
for (const channel of [...allPublicChannels /*, ...directChannels*/]) {
let threads: MessageWithReplies[] = [];
let messages: Message[] = [];
let pagination = new Pagination();
try {
do {
const page = await messageService.views.listChannel(
const page = await gr.services.messages.views.listChannel(
pagination,
{
include_users: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import Company, {
getInstance as getCompanyInstance,
} from "../../../services/user/entities/company";
import CompanyUser from "../../../services/user/entities/company_user";
import UserServiceAPI from "../../../services/user/api";
import twake from "../../../twake";
import User, { getInstance as getUserInstance } from "../../../services/user/entities/user";
import gr from "../../../services/global-resolver";

type CLIArgs = {
company: number;
Expand Down Expand Up @@ -64,21 +64,21 @@ const command: yargs.CommandModule<{}, CLIArgs> = {
const nbUsersPerCompany = argv.user;
const nbCompanies = argv.company;
const platform = await twake.run(services);
const userService = platform.getProvider<UserServiceAPI>("user");
await gr.doInit(platform);
const companies = getCompanies(nbCompanies);
const createUser = async (userInCompany: {
user: User;
company: Company;
}): Promise<CompanyUser> => {
console.log("Creating user", userInCompany);
const created = await userService.users.create(getUserInstance(userInCompany.user));
const created = await gr.services.users.create(getUserInstance(userInCompany.user));

return (await userService.companies.setUserRole(userInCompany.company.id, created.entity.id))
return (await gr.services.companies.setUserRole(userInCompany.company.id, created.entity.id))
?.entity;
};
const createCompany = (company: Company) => {
console.log("Creating company", company);
return userService.companies.createCompany(company);
return gr.services.companies.createCompany(company);
};

const obsv$ = from(companies).pipe(
Expand Down
Loading