mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-13 03:40:48 +00:00
UBERF-5882 (#5018)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
parent
e0f2d0bb42
commit
6e194d133c
@ -89,6 +89,8 @@ export interface Account {
|
||||
admin?: boolean
|
||||
confirmed?: boolean
|
||||
lastWorkspace?: number
|
||||
createdOn: number
|
||||
lastVisit: number
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,6 +106,8 @@ export interface Workspace {
|
||||
|
||||
workspaceUrl?: string | null // An optional url to the workspace, if not set workspace will be used
|
||||
workspaceName?: string // An displayed workspace name
|
||||
createdOn: number
|
||||
lastVisit: number
|
||||
}
|
||||
|
||||
/**
|
||||
@ -552,6 +556,8 @@ export async function createAcc (
|
||||
last,
|
||||
confirmed,
|
||||
workspaces: [],
|
||||
createdOn: Date.now(),
|
||||
lastVisit: Date.now(),
|
||||
...(extra ?? {})
|
||||
})
|
||||
|
||||
@ -674,7 +680,9 @@ async function generateWorkspaceRecord (
|
||||
version,
|
||||
workspaceName,
|
||||
accounts: [],
|
||||
disabled: false
|
||||
disabled: false,
|
||||
createdOn: Date.now(),
|
||||
lastVisit: Date.now()
|
||||
}
|
||||
// Add fixed workspace
|
||||
const id = await coll.insertOne(data)
|
||||
@ -701,7 +709,9 @@ async function generateWorkspaceRecord (
|
||||
version,
|
||||
workspaceName,
|
||||
accounts: [],
|
||||
disabled: false
|
||||
disabled: false,
|
||||
createdOn: Date.now(),
|
||||
lastVisit: Date.now()
|
||||
}
|
||||
// Nice we do not have a workspace or workspaceUrl duplicated.
|
||||
const id = await coll.insertOne(data)
|
||||
@ -953,10 +963,15 @@ export async function getUserWorkspaces (db: Db, productId: string, token: strin
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export async function getWorkspaceInfo (db: Db, productId: string, token: string): Promise<ClientWorkspaceInfo> {
|
||||
export async function getWorkspaceInfo (
|
||||
db: Db,
|
||||
productId: string,
|
||||
token: string,
|
||||
updateLatsVisit: boolean = false
|
||||
): Promise<ClientWorkspaceInfo> {
|
||||
const { email, workspace, extra } = decodeToken(token)
|
||||
const guest = extra?.guest === 'true'
|
||||
let account: Pick<Account, 'admin' | 'workspaces'> | null = null
|
||||
let account: Pick<Account, 'admin' | 'workspaces'> | Account | null = null
|
||||
const query: Filter<Workspace> = {
|
||||
workspace: workspace.name
|
||||
}
|
||||
@ -987,9 +1002,24 @@ export async function getWorkspaceInfo (db: Db, productId: string, token: string
|
||||
if (ws == null) {
|
||||
throw new PlatformError(new Status(Severity.ERROR, platform.status.Forbidden, {}))
|
||||
}
|
||||
if (updateLatsVisit && isAccount(account)) {
|
||||
await updateLastVisit(db, ws, account)
|
||||
}
|
||||
return mapToClientWorkspace(ws)
|
||||
}
|
||||
|
||||
function isAccount (data: Pick<Account, 'admin' | 'workspaces'> | Account | null): data is Account {
|
||||
return (data as Account)._id !== undefined
|
||||
}
|
||||
|
||||
async function updateLastVisit (db: Db, ws: Workspace, account: Account): Promise<void> {
|
||||
const now = Date.now()
|
||||
await db.collection(WORKSPACE_COLLECTION).updateOne({ _id: ws._id }, { $set: { lastVisit: now } })
|
||||
|
||||
// Add workspace to account
|
||||
await db.collection(ACCOUNT_COLLECTION).updateOne({ _id: account._id }, { $set: { lastVisit: now } })
|
||||
}
|
||||
|
||||
async function getWorkspaceAndAccount (
|
||||
db: Db,
|
||||
productId: string,
|
||||
|
@ -175,7 +175,7 @@ class TSessionManager implements SessionManager {
|
||||
},
|
||||
body: JSON.stringify({
|
||||
method: 'getWorkspaceInfo',
|
||||
params: []
|
||||
params: [true]
|
||||
})
|
||||
})
|
||||
).json()
|
||||
|
Loading…
Reference in New Issue
Block a user