Skip to content

Commit fa0a0b6

Browse files
Add account method to get full social ids by person ids (#9654)
Signed-off-by: Artem Savchenko <[email protected]>
1 parent f6b1b33 commit fa0a0b6

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

packages/account-client/src/client.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ export interface AccountClient {
124124
findPersonBySocialId: (socialId: PersonId, requireAccount?: boolean) => Promise<PersonUuid | undefined>
125125
findSocialIdBySocialKey: (socialKey: string) => Promise<PersonId | undefined>
126126
findFullSocialIdBySocialKey: (socialKey: string) => Promise<SocialId | undefined>
127+
findFullSocialIds: (socialIds: PersonId[]) => Promise<SocialId[]>
127128
getMailboxOptions: () => Promise<MailboxOptions>
128129
createMailbox: (name: string, domain: string) => Promise<{ mailbox: string, socialId: PersonId }>
129130
getMailboxes: () => Promise<MailboxInfo[]>
@@ -740,6 +741,14 @@ class AccountClientImpl implements AccountClient {
740741
return await this.rpc(request)
741742
}
742743

744+
async findFullSocialIds (socialIds: PersonId[]): Promise<SocialId[]> {
745+
const request = {
746+
method: 'findFullSocialIds' as const,
747+
params: { socialIds }
748+
}
749+
return await this.rpc(request)
750+
}
751+
743752
async listWorkspaces (region?: string | null, mode: WorkspaceMode | null = null): Promise<WorkspaceInfoWithStatus[]> {
744753
const request = {
745754
method: 'listWorkspaces' as const,

server/account/src/serviceOperations.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ export async function getPersonInfo (
555555
): Promise<PersonInfo> {
556556
const { account } = params
557557
const { extra } = decodeTokenVerbose(ctx, token)
558-
verifyAllowedServices(['workspace', 'tool'], extra)
558+
verifyAllowedServices(['workspace', 'tool', 'gmail'], extra)
559559

560560
if (account == null || account === '') {
561561
throw new PlatformError(new Status(Severity.ERROR, platform.status.BadRequest, {}))
@@ -908,6 +908,24 @@ export async function findFullSocialIdBySocialKey (
908908
return await db.socialId.findOne({ key: socialKey })
909909
}
910910

911+
export async function findFullSocialIds (
912+
ctx: MeasureContext,
913+
db: AccountDB,
914+
branding: Branding | null,
915+
token: string,
916+
params: { socialIds: PersonId[] }
917+
): Promise<SocialId[]> {
918+
const { socialIds } = params
919+
const { extra } = decodeTokenVerbose(ctx, token)
920+
verifyAllowedServices(['gmail', 'tool', 'workspace'], extra)
921+
922+
if (socialIds == null || socialIds.length === 0) {
923+
throw new PlatformError(new Status(Severity.ERROR, platform.status.BadRequest, {}))
924+
}
925+
926+
return await db.socialId.find({ _id: { $in: socialIds } })
927+
}
928+
911929
export async function mergeSpecifiedPersons (
912930
ctx: MeasureContext,
913931
db: AccountDB,
@@ -1009,6 +1027,7 @@ export type AccountServiceMethods =
10091027
| 'mergeSpecifiedAccounts'
10101028
| 'findPersonBySocialKey'
10111029
| 'listAccounts'
1030+
| 'findFullSocialIds'
10121031

10131032
/**
10141033
* @public
@@ -1037,6 +1056,7 @@ export function getServiceMethods (): Partial<Record<AccountServiceMethods, Acco
10371056
getIntegrationSecret: wrap(getIntegrationSecret),
10381057
listIntegrationsSecrets: wrap(listIntegrationsSecrets),
10391058
findFullSocialIdBySocialKey: wrap(findFullSocialIdBySocialKey),
1059+
findFullSocialIds: wrap(findFullSocialIds),
10401060
mergeSpecifiedPersons: wrap(mergeSpecifiedPersons),
10411061
mergeSpecifiedAccounts: wrap(mergeSpecifiedAccounts),
10421062
findPersonBySocialKey: wrap(findPersonBySocialKey),

0 commit comments

Comments
 (0)