mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-23 03:22:19 +03:00
account pod works
Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
parent
83f68f7e00
commit
5e1dc72513
@ -162,7 +162,8 @@ module.exports = {
|
||||
},
|
||||
proxy: {
|
||||
'/account': {
|
||||
target: 'https://ftwm71rwag.execute-api.us-west-2.amazonaws.com/stage/',
|
||||
// target: 'https://ftwm71rwag.execute-api.us-west-2.amazonaws.com/stage/',
|
||||
target: 'https://account.hc.engineering/',
|
||||
changeOrigin: true,
|
||||
pathRewrite: { '^/account': '' },
|
||||
logLevel: 'debug'
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -18,7 +18,7 @@ import { program } from 'commander'
|
||||
import { MongoClient, Db } from 'mongodb'
|
||||
import { getAccount, createAccount, assignWorkspace, createWorkspace, ACCOUNT_DB } from '@anticrm/account'
|
||||
import { createContributingClient } from '@anticrm/contrib'
|
||||
import core, { TxOperations } from '@anticrm/core'
|
||||
import core, { TxOperations, TxFactory, DOMAIN_TX } from '@anticrm/core'
|
||||
import { encode } from 'jwt-simple'
|
||||
import { Client } from 'minio'
|
||||
import { initWorkspace } from './workspace'
|
||||
@ -63,11 +63,11 @@ const minio = new Client({
|
||||
secretKey: minioSecretKey
|
||||
})
|
||||
|
||||
async function withDatabase (uri: string, f: (db: Db) => Promise<any>): Promise<void> {
|
||||
async function withDatabase (uri: string, f: (db: Db, client: MongoClient) => Promise<any>): Promise<void> {
|
||||
console.log(`connecting to database '${uri}'...`)
|
||||
|
||||
const client = await MongoClient.connect(uri)
|
||||
await f(client.db(ACCOUNT_DB))
|
||||
await f(client.db(ACCOUNT_DB), client)
|
||||
await client.close()
|
||||
}
|
||||
|
||||
@ -75,15 +75,15 @@ program.version('0.0.1')
|
||||
|
||||
// create-user john.appleseed@gmail.com --password 123 --workspace workspace --fullname "John Appleseed"
|
||||
program
|
||||
.command('create-user <email>')
|
||||
.command('create-account <email>')
|
||||
.description('create user and corresponding account in master database')
|
||||
.requiredOption('-p, --password <password>', 'user password')
|
||||
.requiredOption('-f, --first <firstname>', 'first name')
|
||||
.requiredOption('-l, --last <lastname>', 'first name')
|
||||
.requiredOption('-f, --first <first>', 'first name')
|
||||
.requiredOption('-l, --last <last>', 'first name')
|
||||
.action(async (email: string, cmd) => {
|
||||
return await withDatabase(mongodbUri, async (db) => {
|
||||
console.log(`creating account ${cmd.firstname as string} ${cmd.lastname as string} (${email})...`)
|
||||
await createAccount(db, email, cmd.password, cmd.firstname, cmd.lastname)
|
||||
console.log(`creating account ${cmd.first as string} ${cmd.last as string} (${email})...`)
|
||||
await createAccount(db, email, cmd.password, cmd.first, cmd.last)
|
||||
})
|
||||
})
|
||||
|
||||
@ -91,28 +91,37 @@ program
|
||||
.command('assign-workspace <email> <workspace>')
|
||||
.description('assign workspace')
|
||||
.action(async (email: string, workspace: string, cmd) => {
|
||||
return await withDatabase(mongodbUri, async (db) => {
|
||||
return await withDatabase(mongodbUri, async (db, client) => {
|
||||
console.log(`retrieveing account from ${email}...`)
|
||||
const account = await getAccount(db, email)
|
||||
if (account === null) {
|
||||
throw new Error('account not found')
|
||||
}
|
||||
|
||||
console.log(`assigning user ${email} to ${workspace}...`)
|
||||
await assignWorkspace(db, email, workspace)
|
||||
|
||||
console.log('connecting to transactor...')
|
||||
const token = encode({ email: 'anticrm@hc.engineering', workspace }, 'secret')
|
||||
const url = new URL(`/${token}`, transactorUrl)
|
||||
const contrib = await createContributingClient(url.href)
|
||||
const txop = new TxOperations(contrib, core.account.System)
|
||||
|
||||
console.log('create user in target workspace...')
|
||||
const employee = await txop.createDoc(contact.class.Employee, contact.space.Employee, {
|
||||
firstName: account.first,
|
||||
lastName: account.last,
|
||||
city: 'Mountain View',
|
||||
channels: []
|
||||
})
|
||||
|
||||
console.log('create account in target workspace...')
|
||||
await txop.createDoc(contact.class.EmployeeAccount, core.space.Model, {
|
||||
email,
|
||||
employee
|
||||
})
|
||||
|
||||
contrib.close()
|
||||
})
|
||||
})
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -19,3 +19,4 @@ import { writeFileSync } from 'fs'
|
||||
const content = JSON.stringify(builder.getTxes(), undefined, 2)
|
||||
writeFileSync('../../dev/storage/src/model.tx.json', content)
|
||||
writeFileSync('../../server/workspace/src/model.tx.json', content)
|
||||
writeFileSync('../../dev/tool/src/model.tx.json', content)
|
||||
|
@ -38,9 +38,12 @@ async function connect(): Promise<Client | undefined> {
|
||||
|
||||
const getClient = await getResource(client.function.GetClient)
|
||||
const instance = await getClient(token, endpoint)
|
||||
const me = await instance.findOne(contact.class.Employee, { email })
|
||||
const me = await instance.findOne(contact.class.EmployeeAccount, { email })
|
||||
if (me !== undefined) {
|
||||
setCurrentAccount(me._id)
|
||||
console.log('login: employee account', me)
|
||||
setCurrentAccount(me)
|
||||
} else {
|
||||
console.log('WARNING: no employee account found.')
|
||||
}
|
||||
return instance
|
||||
}
|
||||
|
@ -17,17 +17,16 @@
|
||||
import type { Ref, Obj, Class } from '@anticrm/core'
|
||||
import type { Asset } from '@anticrm/platform'
|
||||
import type { Client } from '@anticrm/core'
|
||||
import type { Employee } from '@anticrm/contact'
|
||||
import type { EmployeeAccount } from '@anticrm/contact'
|
||||
|
||||
export function classIcon(client: Client, _class: Ref<Class<Obj>>): Asset | undefined {
|
||||
return client.getHierarchy().getClass(_class).icon
|
||||
}
|
||||
|
||||
let currentAccount: Ref<Employee>
|
||||
let currentAccount: EmployeeAccount
|
||||
|
||||
export function getCurrentAccount(): Ref<Employee> { return currentAccount }
|
||||
export function getCurrentAccount(): EmployeeAccount { return currentAccount }
|
||||
|
||||
export function setCurrentAccount(account: Ref<Employee>): void {
|
||||
export function setCurrentAccount(account: EmployeeAccount): void {
|
||||
currentAccount = account
|
||||
console.log('current account', currentAccount)
|
||||
}
|
||||
|
@ -19,5 +19,5 @@ spec:
|
||||
- containerPort: 3000
|
||||
imagePullPolicy: Always
|
||||
env:
|
||||
- name: MONGO_URL
|
||||
value: mongodb://root:WZCwnHRazX@mng-mongodb:27017/
|
||||
- name: MONGO_URL
|
||||
value: mongodb://root:WZCwnHRazX@mng-mongodb:27017/
|
||||
|
@ -24,7 +24,12 @@ import Router from 'koa-router'
|
||||
import bodyParser from 'koa-bodyparser'
|
||||
import cors from '@koa/cors'
|
||||
|
||||
const dbUri = process.env.MONGO_URL ?? 'mongodb://localhost:27017'
|
||||
const dbUri = process.env.MONGO_URL
|
||||
if (dbUri === undefined) {
|
||||
console.log('Please provide mongodb url')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
let client: MongoClient
|
||||
|
||||
const app = new Koa()
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user