UBERF-5882 (#5018)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2024-03-19 19:47:50 +06:00 committed by GitHub
parent e0f2d0bb42
commit 6e194d133c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 35 additions and 5 deletions

View File

@ -89,6 +89,8 @@ export interface Account {
admin?: boolean admin?: boolean
confirmed?: boolean confirmed?: boolean
lastWorkspace?: number 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 workspaceUrl?: string | null // An optional url to the workspace, if not set workspace will be used
workspaceName?: string // An displayed workspace name workspaceName?: string // An displayed workspace name
createdOn: number
lastVisit: number
} }
/** /**
@ -552,6 +556,8 @@ export async function createAcc (
last, last,
confirmed, confirmed,
workspaces: [], workspaces: [],
createdOn: Date.now(),
lastVisit: Date.now(),
...(extra ?? {}) ...(extra ?? {})
}) })
@ -674,7 +680,9 @@ async function generateWorkspaceRecord (
version, version,
workspaceName, workspaceName,
accounts: [], accounts: [],
disabled: false disabled: false,
createdOn: Date.now(),
lastVisit: Date.now()
} }
// Add fixed workspace // Add fixed workspace
const id = await coll.insertOne(data) const id = await coll.insertOne(data)
@ -701,7 +709,9 @@ async function generateWorkspaceRecord (
version, version,
workspaceName, workspaceName,
accounts: [], accounts: [],
disabled: false disabled: false,
createdOn: Date.now(),
lastVisit: Date.now()
} }
// Nice we do not have a workspace or workspaceUrl duplicated. // Nice we do not have a workspace or workspaceUrl duplicated.
const id = await coll.insertOne(data) const id = await coll.insertOne(data)
@ -953,10 +963,15 @@ export async function getUserWorkspaces (db: Db, productId: string, token: strin
/** /**
* @public * @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 { email, workspace, extra } = decodeToken(token)
const guest = extra?.guest === 'true' 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> = { const query: Filter<Workspace> = {
workspace: workspace.name workspace: workspace.name
} }
@ -987,9 +1002,24 @@ export async function getWorkspaceInfo (db: Db, productId: string, token: string
if (ws == null) { if (ws == null) {
throw new PlatformError(new Status(Severity.ERROR, platform.status.Forbidden, {})) throw new PlatformError(new Status(Severity.ERROR, platform.status.Forbidden, {}))
} }
if (updateLatsVisit && isAccount(account)) {
await updateLastVisit(db, ws, account)
}
return mapToClientWorkspace(ws) 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 ( async function getWorkspaceAndAccount (
db: Db, db: Db,
productId: string, productId: string,

View File

@ -175,7 +175,7 @@ class TSessionManager implements SessionManager {
}, },
body: JSON.stringify({ body: JSON.stringify({
method: 'getWorkspaceInfo', method: 'getWorkspaceInfo',
params: [] params: [true]
}) })
}) })
).json() ).json()