mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-07 02:07:43 +02:00
Fix Github login update (#10683)
Signed-off-by: Artem Savchenko <armisav@gmail.com>
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
<script lang="ts">
|
||||
import { Integration } from '@hcengineering/setting'
|
||||
import type { Integration as AccountIntegration } from '@hcengineering/account-client'
|
||||
import Connect from './Connect.svelte'
|
||||
|
||||
export let integration: Integration
|
||||
export let integration: AccountIntegration | undefined
|
||||
</script>
|
||||
|
||||
<Connect bind:integration on:close />
|
||||
|
||||
@@ -8,20 +8,19 @@
|
||||
|
||||
import GithubPersonProfile from './GithubPersonProfile.svelte'
|
||||
|
||||
import type { Integration as AccountIntegration } from '@hcengineering/account-client'
|
||||
import { Analytics } from '@hcengineering/analytics'
|
||||
import { WithLookup, getCurrentAccount } from '@hcengineering/core'
|
||||
import { GithubAuthentication, GithubIntegration } from '@hcengineering/github'
|
||||
import { getEmbeddedLabel, getMetadata, translate } from '@hcengineering/platform'
|
||||
import presentation, { Card, HTMLViewer, NavLink, createQuery, getClient } from '@hcengineering/presentation'
|
||||
import { Integration } from '@hcengineering/setting'
|
||||
import presentation, { Card, HTMLViewer, NavLink, createQuery } from '@hcengineering/presentation'
|
||||
import tracker, { Project } from '@hcengineering/tracker'
|
||||
import ui, { Button, Label, Loading, TabItem, TabList, location, ticker } from '@hcengineering/ui'
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
import github from '../plugin'
|
||||
import { onAuthorize } from './utils'
|
||||
import { clientId } from '@hcengineering/client'
|
||||
import { onAuthorize, updateGithubAccountIntegrationLogin } from './utils'
|
||||
|
||||
export let integration: Integration
|
||||
export let integration: AccountIntegration | undefined
|
||||
|
||||
const dispatch = createEventDispatcher()
|
||||
|
||||
@@ -59,10 +58,7 @@
|
||||
})
|
||||
|
||||
function save (): void {
|
||||
void getClient().diffUpdate(integration, {
|
||||
value: auth?.login ?? ''
|
||||
})
|
||||
dispatch('close', { value: auth?.login ?? '-' })
|
||||
void updateGithubAccountIntegrationLogin(auth?.login ?? '', integration)
|
||||
}
|
||||
function onConnect (): void {
|
||||
const state = btoa(
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
import {
|
||||
getClient as getAccountClientRaw,
|
||||
type AccountClient,
|
||||
type Integration as AccountIntegration
|
||||
} from '@hcengineering/account-client'
|
||||
import { Analytics } from '@hcengineering/analytics'
|
||||
import { concatLink, getCurrentAccount, toIdMap, type IdMap } from '@hcengineering/core'
|
||||
import {
|
||||
githubIntegrationKind,
|
||||
makeQuery,
|
||||
type GithubAuthentication,
|
||||
type GithubIntegrationRepository,
|
||||
type GithubProject
|
||||
} from '@hcengineering/github'
|
||||
import login from '@hcengineering/login'
|
||||
import { PlatformError, getMetadata, unknownError } from '@hcengineering/platform'
|
||||
import presentation, { createQuery, getClient } from '@hcengineering/presentation'
|
||||
import { location } from '@hcengineering/ui'
|
||||
@@ -41,6 +48,41 @@ export async function onAuthorize (login?: string): Promise<void> {
|
||||
window.open(url)
|
||||
}
|
||||
|
||||
export function getAccountClient (): AccountClient | undefined {
|
||||
const accountsUrl = getMetadata(login.metadata.AccountsUrl)
|
||||
const token = getMetadata(presentation.metadata.Token)
|
||||
if (accountsUrl == null || token == null) {
|
||||
return undefined
|
||||
}
|
||||
return getAccountClientRaw(accountsUrl, token)
|
||||
}
|
||||
|
||||
export async function updateGithubAccountIntegrationLogin (
|
||||
loginVal: string,
|
||||
integration: AccountIntegration | undefined
|
||||
): Promise<void> {
|
||||
try {
|
||||
const accountClient = getAccountClient()
|
||||
if (accountClient === undefined) {
|
||||
throw new Error('Account client is not defined')
|
||||
}
|
||||
const socialId = integration?.socialId ?? getCurrentAccount().primarySocialId
|
||||
const workspaceUuid = integration?.workspaceUuid ?? null
|
||||
|
||||
const key = { socialId, kind: githubIntegrationKind, workspaceUuid }
|
||||
const existing = await accountClient.getIntegration(key)
|
||||
const mergedData = { ...(existing?.data ?? {}), login: loginVal }
|
||||
|
||||
if (existing == null) {
|
||||
throw new Error('Integration not found')
|
||||
}
|
||||
await accountClient.updateIntegration({ ...existing, data: mergedData })
|
||||
} catch (err: any) {
|
||||
console.error('Error updating github account integration login', err)
|
||||
Analytics.handleError(err)
|
||||
}
|
||||
}
|
||||
|
||||
const repositoryQuery = createQuery(true)
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user