mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-07 18:27:44 +02:00
UBERF-8425: Global accounts (#7573)
This commit is contained in:
@@ -9,7 +9,7 @@ import cors from 'cors'
|
||||
import express from 'express'
|
||||
|
||||
import { Analytics } from '@hcengineering/analytics'
|
||||
import { Account, BrandingMap, MeasureContext, Ref } from '@hcengineering/core'
|
||||
import { PersonId, BrandingMap, MeasureContext } from '@hcengineering/core'
|
||||
import { setMetadata } from '@hcengineering/platform'
|
||||
import serverClient from '@hcengineering/server-client'
|
||||
import serverCore from '@hcengineering/server-core'
|
||||
@@ -73,35 +73,37 @@ export async function start (ctx: MeasureContext, brandingMap: BrandingMap): Pro
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||
app.post('/api/v1/installation', async (req, res) => {
|
||||
const payloadData: {
|
||||
installationId: number
|
||||
accountId: Ref<Account>
|
||||
token: string
|
||||
} = req.body
|
||||
try {
|
||||
const decodedToken = decodeToken(payloadData.token)
|
||||
ctx.info('/api/v1/installation', {
|
||||
email: decodedToken.email,
|
||||
workspaceName: decodedToken.workspace.name,
|
||||
body: req.body
|
||||
})
|
||||
// TODO: FIXME
|
||||
throw new Error('Not implemented')
|
||||
// const payloadData: {
|
||||
// installationId: number
|
||||
// accountId: PersonId
|
||||
// token: string
|
||||
// } = req.body
|
||||
// try {
|
||||
// const decodedToken = decodeToken(payloadData.token)
|
||||
// ctx.info('/api/v1/installation', {
|
||||
// email: decodedToken.email,
|
||||
// workspaceName: decodedToken.workspace,
|
||||
// body: req.body
|
||||
// })
|
||||
|
||||
await ctx.with('map-installation', {}, (ctx) =>
|
||||
worker.mapInstallation(ctx, decodedToken.workspace.name, payloadData.installationId, payloadData.accountId)
|
||||
)
|
||||
res.status(200)
|
||||
res.json({})
|
||||
} catch (err: any) {
|
||||
Analytics.handleError(err)
|
||||
const tok = decodeToken(payloadData.token, false)
|
||||
ctx.error('failed to map-installation', {
|
||||
workspace: tok.workspace?.name,
|
||||
installationid: payloadData.installationId,
|
||||
email: tok?.email
|
||||
})
|
||||
res.status(401)
|
||||
res.json({ error: err.message })
|
||||
}
|
||||
// await ctx.with('map-installation', {}, (ctx) =>
|
||||
// worker.mapInstallation(ctx, decodedToken.workspace, payloadData.installationId, payloadData.accountId)
|
||||
// )
|
||||
// res.status(200)
|
||||
// res.json({})
|
||||
// } catch (err: any) {
|
||||
// Analytics.handleError(err)
|
||||
// const tok = decodeToken(payloadData.token, false)
|
||||
// ctx.error('failed to map-installation', {
|
||||
// workspace: tok.workspace,
|
||||
// installationid: payloadData.installationId,
|
||||
// email: tok?.email
|
||||
// })
|
||||
// res.status(401)
|
||||
// res.json({ error: err.message })
|
||||
// }
|
||||
})
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||
@@ -110,26 +112,26 @@ export async function start (ctx: MeasureContext, brandingMap: BrandingMap): Pro
|
||||
const payloadData: {
|
||||
code: string
|
||||
state: string
|
||||
accountId: Ref<Account>
|
||||
accountId: PersonId
|
||||
token: string
|
||||
} = req.body
|
||||
|
||||
const decodedData: {
|
||||
accountId: Ref<Account>
|
||||
accountId: PersonId
|
||||
token: string
|
||||
op: string
|
||||
} = JSON.parse(atob(payloadData.state))
|
||||
|
||||
const decodedToken = decodeToken(decodedData.token)
|
||||
ctx.info('request github access-token', {
|
||||
workspace: decodedToken.workspace.name,
|
||||
workspace: decodedToken.workspace,
|
||||
accountId: payloadData.accountId,
|
||||
code: payloadData.code,
|
||||
state: payloadData.state
|
||||
})
|
||||
await ctx.with('request-github-access-token', {}, async (ctx) => {
|
||||
await worker.requestGithubAccessToken({
|
||||
workspace: decodedToken.workspace.name,
|
||||
workspace: decodedToken.workspace,
|
||||
accountId: payloadData.accountId,
|
||||
code: payloadData.code,
|
||||
state: payloadData.state
|
||||
@@ -146,33 +148,35 @@ export async function start (ctx: MeasureContext, brandingMap: BrandingMap): Pro
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||
app.post('/api/v1/installation-remove', async (req, res) => {
|
||||
try {
|
||||
const payloadData: {
|
||||
installationId: number
|
||||
token: string
|
||||
} = req.body
|
||||
// TODO: FIXME
|
||||
throw new Error('Not implemented')
|
||||
// try {
|
||||
// const payloadData: {
|
||||
// installationId: number
|
||||
// token: string
|
||||
// } = req.body
|
||||
|
||||
const decodedToken = decodeToken(payloadData.token)
|
||||
ctx.info('/api/v1/installation-remove', {
|
||||
email: decodedToken.email,
|
||||
workspaceName: decodedToken.workspace.name,
|
||||
body: req.body
|
||||
})
|
||||
// const decodedToken = decodeToken(payloadData.token)
|
||||
// ctx.info('/api/v1/installation-remove', {
|
||||
// email: decodedToken.email,
|
||||
// workspaceName: decodedToken.workspace,
|
||||
// body: req.body
|
||||
// })
|
||||
|
||||
ctx.info('remove-installation', {
|
||||
workspace: decodedToken.workspace.name,
|
||||
installationId: payloadData.installationId
|
||||
})
|
||||
await ctx.with('remove-installation', {}, (ctx) =>
|
||||
worker.removeInstallation(ctx, decodedToken.workspace.name, payloadData.installationId)
|
||||
)
|
||||
res.status(200)
|
||||
res.json({})
|
||||
} catch (err: any) {
|
||||
Analytics.handleError(err)
|
||||
res.status(401)
|
||||
res.json({ error: err.message })
|
||||
}
|
||||
// ctx.info('remove-installation', {
|
||||
// workspace: decodedToken.workspace,
|
||||
// installationId: payloadData.installationId
|
||||
// })
|
||||
// await ctx.with('remove-installation', {}, (ctx) =>
|
||||
// worker.removeInstallation(ctx, decodedToken.workspace, payloadData.installationId)
|
||||
// )
|
||||
// res.status(200)
|
||||
// res.json({})
|
||||
// } catch (err: any) {
|
||||
// Analytics.handleError(err)
|
||||
// res.status(401)
|
||||
// res.json({ error: err.message })
|
||||
// }
|
||||
})
|
||||
|
||||
const server = app.listen(port, () => {
|
||||
|
||||
Reference in New Issue
Block a user