mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-16 21:35:10 +00:00
Fix workspace join (#2383)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com> Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
parent
a8af08de88
commit
126b7eb772
@ -21,7 +21,16 @@ import contact, {
|
|||||||
Employee,
|
Employee,
|
||||||
getAvatarColorForId
|
getAvatarColorForId
|
||||||
} from '@hcengineering/contact'
|
} from '@hcengineering/contact'
|
||||||
import core, { AccountRole, Data, getWorkspaceId, Ref, Tx, TxOperations, Version } from '@hcengineering/core'
|
import core, {
|
||||||
|
AccountRole,
|
||||||
|
Data,
|
||||||
|
getWorkspaceId,
|
||||||
|
Ref,
|
||||||
|
Tx,
|
||||||
|
TxOperations,
|
||||||
|
Version,
|
||||||
|
WorkspaceId
|
||||||
|
} from '@hcengineering/core'
|
||||||
import { MigrateOperation } from '@hcengineering/model'
|
import { MigrateOperation } from '@hcengineering/model'
|
||||||
import platform, {
|
import platform, {
|
||||||
getMetadata,
|
getMetadata,
|
||||||
@ -129,7 +138,7 @@ export interface WorkspaceLoginInfo extends LoginInfo {
|
|||||||
*/
|
*/
|
||||||
export interface Invite {
|
export interface Invite {
|
||||||
_id: ObjectId
|
_id: ObjectId
|
||||||
workspace: string
|
workspace: WorkspaceId
|
||||||
exp: number
|
exp: number
|
||||||
emailMask: string
|
emailMask: string
|
||||||
limit: number
|
limit: number
|
||||||
@ -256,7 +265,7 @@ export async function getInvite (db: Db, inviteId: ObjectId): Promise<Invite | n
|
|||||||
/**
|
/**
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
export async function checkInvite (invite: Invite | null, email: string): Promise<string> {
|
export async function checkInvite (invite: Invite | null, email: string): Promise<WorkspaceId> {
|
||||||
if (invite === null || invite.limit === 0) {
|
if (invite === null || invite.limit === 0) {
|
||||||
throw new PlatformError(new Status(Severity.ERROR, platform.status.Forbidden, {}))
|
throw new PlatformError(new Status(Severity.ERROR, platform.status.Forbidden, {}))
|
||||||
}
|
}
|
||||||
@ -289,10 +298,10 @@ export async function join (
|
|||||||
): Promise<WorkspaceLoginInfo> {
|
): Promise<WorkspaceLoginInfo> {
|
||||||
const invite = await getInvite(db, inviteId)
|
const invite = await getInvite(db, inviteId)
|
||||||
const workspace = await checkInvite(invite, email)
|
const workspace = await checkInvite(invite, email)
|
||||||
await assignWorkspace(db, productId, email, workspace)
|
await assignWorkspace(db, productId, email, workspace.name)
|
||||||
|
|
||||||
const token = (await login(db, productId, email, password)).token
|
const token = (await login(db, productId, email, password)).token
|
||||||
const result = await selectWorkspace(db, productId, token, workspace)
|
const result = await selectWorkspace(db, productId, token, workspace.name)
|
||||||
await useInvite(db, inviteId)
|
await useInvite(db, inviteId)
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -312,10 +321,10 @@ export async function signUpJoin (
|
|||||||
const invite = await getInvite(db, inviteId)
|
const invite = await getInvite(db, inviteId)
|
||||||
const workspace = await checkInvite(invite, email)
|
const workspace = await checkInvite(invite, email)
|
||||||
await createAccount(db, productId, email, password, first, last)
|
await createAccount(db, productId, email, password, first, last)
|
||||||
await assignWorkspace(db, productId, email, workspace)
|
await assignWorkspace(db, productId, email, workspace.name)
|
||||||
|
|
||||||
const token = (await login(db, productId, email, password)).token
|
const token = (await login(db, productId, email, password)).token
|
||||||
const result = await selectWorkspace(db, productId, token, workspace)
|
const result = await selectWorkspace(db, productId, token, workspace.name)
|
||||||
await useInvite(db, inviteId)
|
await useInvite(db, inviteId)
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -713,7 +722,7 @@ export async function checkJoin (
|
|||||||
const { email } = decodeToken(token)
|
const { email } = decodeToken(token)
|
||||||
const invite = await getInvite(db, inviteId)
|
const invite = await getInvite(db, inviteId)
|
||||||
const workspace = await checkInvite(invite, email)
|
const workspace = await checkInvite(invite, email)
|
||||||
return await selectWorkspace(db, productId, token, workspace)
|
return await selectWorkspace(db, productId, token, workspace.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user