-
Notifications
You must be signed in to change notification settings - Fork 403
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: mr-anton-t <[email protected]>
- Loading branch information
1 parent
d230275
commit 1746d91
Showing
91 changed files
with
897 additions
and
337 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
webapp/packages/core-authentication/src/TeamInfoMetaParametersResource.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* CloudBeaver - Cloud Database Manager | ||
* Copyright (C) 2020-2024 DBeaver Corp and others | ||
* | ||
* Licensed under the Apache License, Version 2.0. | ||
* you may not use this file except in compliance with the License. | ||
*/ | ||
import { injectable } from '@cloudbeaver/core-di'; | ||
import { CachedMapAllKey, CachedMapResource, isResourceAlias, type ResourceKey, resourceKeyList, ResourceKeyUtils } from '@cloudbeaver/core-resource'; | ||
import { GraphQLService } from '@cloudbeaver/core-sdk'; | ||
|
||
import type { TeamMetaParameter } from './TeamMetaParametersResource.js'; | ||
import { TeamsResource } from './TeamsResource.js'; | ||
|
||
@injectable() | ||
export class TeamInfoMetaParametersResource extends CachedMapResource<string, TeamMetaParameter> { | ||
constructor( | ||
private readonly graphQLService: GraphQLService, | ||
private readonly teamsResource: TeamsResource, | ||
) { | ||
super(); | ||
|
||
this.sync(this.teamsResource); | ||
this.teamsResource.onItemDelete.addHandler(this.delete.bind(this)); | ||
} | ||
|
||
protected async loader(param: ResourceKey<string>): Promise<Map<string, TeamMetaParameter>> { | ||
const all = this.aliases.isAlias(param, CachedMapAllKey); | ||
const teamsList: [string, TeamMetaParameter][] = []; | ||
|
||
await ResourceKeyUtils.forEachAsync(param, async key => { | ||
let teamId: string | undefined; | ||
|
||
if (!isResourceAlias(key)) { | ||
teamId = key; | ||
} | ||
|
||
const { teams } = await this.graphQLService.sdk.getTeamsListMetaParameters({ | ||
teamId, | ||
}); | ||
|
||
if (!teams.length) { | ||
throw new Error(`Team ${teamId} not found`); | ||
} | ||
|
||
const metaParameters = teams[0]?.metaParameters; | ||
|
||
if (teamId) { | ||
teamsList.push([teamId, metaParameters]); | ||
} | ||
}); | ||
|
||
const key = resourceKeyList(teamsList.map(([teamId]) => teamId)); | ||
const value = teamsList.map(([_, metaParameters]) => metaParameters); | ||
|
||
if (all) { | ||
this.replace(key, value); | ||
} else { | ||
this.set(key, value); | ||
} | ||
|
||
return this.data; | ||
} | ||
|
||
async setMetaParameters(teamId: string, parameters: Record<string, any>): Promise<void> { | ||
await this.performUpdate(teamId, [], async () => { | ||
await this.graphQLService.sdk.saveTeamMetaParameters({ teamId, parameters }); | ||
|
||
if (this.data) { | ||
this.data.set(teamId, parameters as TeamMetaParameter); | ||
} | ||
}); | ||
} | ||
|
||
protected validateKey(key: string): boolean { | ||
return typeof key === 'string'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
webapp/packages/core-authentication/src/UserInfoMetaParametersResource.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* CloudBeaver - Cloud Database Manager | ||
* Copyright (C) 2020-2024 DBeaver Corp and others | ||
* | ||
* Licensed under the Apache License, Version 2.0. | ||
* you may not use this file except in compliance with the License. | ||
*/ | ||
import { injectable } from '@cloudbeaver/core-di'; | ||
import { CachedDataResource, type ResourceKey } from '@cloudbeaver/core-resource'; | ||
import { GraphQLService } from '@cloudbeaver/core-sdk'; | ||
|
||
import { UserInfoResource } from './UserInfoResource.js'; | ||
import type { UserMetaParameter } from './UserMetaParametersResource.js'; | ||
|
||
@injectable() | ||
export class UserInfoMetaParametersResource extends CachedDataResource<UserMetaParameter | undefined> { | ||
constructor( | ||
private readonly graphQLService: GraphQLService, | ||
private readonly userInfoResource: UserInfoResource, | ||
) { | ||
super(() => undefined, undefined); | ||
|
||
this.sync(this.userInfoResource); | ||
} | ||
|
||
protected async loader(param: ResourceKey<void>): Promise<UserMetaParameter | undefined> { | ||
const { user } = await this.graphQLService.sdk.getActiveUserMetaParameters(); | ||
|
||
return user?.metaParameters; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
webapp/packages/core-authentication/src/UsersMetaParametersResource.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* CloudBeaver - Cloud Database Manager | ||
* Copyright (C) 2020-2024 DBeaver Corp and others | ||
* | ||
* Licensed under the Apache License, Version 2.0. | ||
* you may not use this file except in compliance with the License. | ||
*/ | ||
import { injectable } from '@cloudbeaver/core-di'; | ||
import { CachedMapAllKey, CachedMapResource, isResourceAlias, type ResourceKey, resourceKeyList, ResourceKeyUtils } from '@cloudbeaver/core-resource'; | ||
import { GraphQLService } from '@cloudbeaver/core-sdk'; | ||
|
||
import type { UserMetaParameter } from './UserMetaParametersResource.js'; | ||
import { UsersResource } from './UsersResource.js'; | ||
|
||
@injectable() | ||
export class UsersMetaParametersResource extends CachedMapResource<string, UserMetaParameter> { | ||
constructor( | ||
private readonly graphQLService: GraphQLService, | ||
private readonly usersResource: UsersResource, | ||
) { | ||
super(); | ||
|
||
this.sync(this.usersResource); | ||
this.usersResource.onItemDelete.addHandler(this.delete.bind(this)); | ||
} | ||
|
||
async setMetaParameters(userId: string, parameters: Record<string, any>): Promise<void> { | ||
await this.performUpdate(userId, undefined, async () => { | ||
await this.graphQLService.sdk.saveUserMetaParameters({ userId, parameters }); | ||
|
||
if (this.data) { | ||
this.data.set(userId, parameters as UserMetaParameter); | ||
} | ||
}); | ||
} | ||
|
||
protected async loader(originalKey: ResourceKey<string>): Promise<Map<string, UserMetaParameter>> { | ||
const all = this.aliases.isAlias(originalKey, CachedMapAllKey); | ||
const keys = resourceKeyList<string>([]); | ||
|
||
if (all) { | ||
throw new Error('Loading all users is prohibited'); | ||
} | ||
|
||
const userMetaParametersList: UserMetaParameter[] = []; | ||
|
||
await ResourceKeyUtils.forEachAsync(originalKey, async key => { | ||
let userId: string | undefined; | ||
|
||
if (!isResourceAlias(key)) { | ||
userId = key; | ||
} | ||
|
||
if (userId !== undefined) { | ||
const { user } = await this.graphQLService.sdk.getAdminUserMetaParameters({ | ||
userId, | ||
}); | ||
|
||
keys.push(userId); | ||
userMetaParametersList.push(user.metaParameters); | ||
} | ||
}); | ||
|
||
this.set(keys, userMetaParametersList); | ||
|
||
return this.data; | ||
} | ||
|
||
protected validateKey(key: string): boolean { | ||
return typeof key === 'string'; | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
webapp/packages/core-authentication/src/UsersOriginDetailsResource.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* CloudBeaver - Cloud Database Manager | ||
* Copyright (C) 2020-2024 DBeaver Corp and others | ||
* | ||
* Licensed under the Apache License, Version 2.0. | ||
* you may not use this file except in compliance with the License. | ||
*/ | ||
import { injectable } from '@cloudbeaver/core-di'; | ||
import { CachedMapAllKey, CachedMapResource, isResourceAlias, type ResourceKey, resourceKeyList, ResourceKeyUtils } from '@cloudbeaver/core-resource'; | ||
import { type AdminOriginDetailsFragment, GraphQLService } from '@cloudbeaver/core-sdk'; | ||
|
||
import { UsersResource } from './UsersResource.js'; | ||
|
||
@injectable() | ||
export class UsersOriginDetailsResource extends CachedMapResource<string, AdminOriginDetailsFragment> { | ||
constructor( | ||
private readonly graphQLService: GraphQLService, | ||
private readonly usersResource: UsersResource, | ||
) { | ||
super(); | ||
|
||
this.sync(this.usersResource); | ||
this.usersResource.onItemDelete.addHandler(this.delete.bind(this)); | ||
} | ||
|
||
protected async loader(originalKey: ResourceKey<string>): Promise<Map<string, AdminOriginDetailsFragment>> { | ||
const all = this.aliases.isAlias(originalKey, CachedMapAllKey); | ||
const keys = resourceKeyList<string>([]); | ||
|
||
if (all) { | ||
throw new Error('Loading all users is prohibited'); | ||
} | ||
|
||
const userMetaParametersList: AdminOriginDetailsFragment[] = []; | ||
|
||
await ResourceKeyUtils.forEachAsync(originalKey, async key => { | ||
let userId: string | undefined; | ||
|
||
if (!isResourceAlias(key)) { | ||
userId = key; | ||
} | ||
|
||
if (userId !== undefined) { | ||
const { user } = await this.graphQLService.sdk.getAdminUserOriginDetails({ | ||
userId, | ||
}); | ||
|
||
keys.push(userId); | ||
userMetaParametersList.push(user); | ||
} | ||
}); | ||
|
||
this.set(keys, userMetaParametersList); | ||
|
||
return this.data; | ||
} | ||
|
||
protected validateKey(key: string): boolean { | ||
return typeof key === 'string'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.