Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cb 4661 remove includes concept from resources api #2910

Merged
merged 31 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
f32a086
CB-4461 replaces includeMetaParameters concept for resource in Team f…
sergeyteleshev Sep 9, 2024
f101b9a
Merge branch 'devel' into CB-4661-remove-includes-concept-from-resour…
sergeyteleshev Sep 10, 2024
05093a5
CB-4461 removes includeMetaParameters for users resources
sergeyteleshev Sep 11, 2024
d4d60b9
Merge branch 'devel' into CB-4661-remove-includes-concept-from-resour…
sergeyteleshev Sep 12, 2024
e20583b
CB-4461 removes includeOriginDetails for users
sergeyteleshev Sep 13, 2024
ac10b68
CB-44661 renames to UsersMetaParametersResource
sergeyteleshev Sep 13, 2024
e9ff24c
CB-4461 removes includeOrigin and customIncludeOriginDetails includes…
sergeyteleshev Sep 13, 2024
1ff7028
CB-4461 removes the comment
sergeyteleshev Sep 13, 2024
5df3f4c
Merge branch 'devel' into CB-4661-remove-includes-concept-from-resour…
sergeyteleshev Sep 13, 2024
ee4b614
CB-4461 cleanup
sergeyteleshev Sep 16, 2024
3a24404
Merge branch 'devel' into CB-4661-remove-includes-concept-from-resour…
sergeyteleshev Sep 16, 2024
398a7f5
CB-4461 fixes pagination for new resources
sergeyteleshev Sep 16, 2024
865903d
CB-4661 pr fixes
sergeyteleshev Sep 16, 2024
23a1901
CB-4661 pr fixes 2
sergeyteleshev Sep 16, 2024
396429b
Merge branch 'devel' into CB-4661-remove-includes-concept-from-resour…
sergeyteleshev Sep 17, 2024
438ce9f
CB-4661 fixes origin info for connection templates table
sergeyteleshev Sep 17, 2024
ad22f29
CB-4661 fix pr
sergeyteleshev Sep 17, 2024
3f071f8
CB-4661 cleanup
sergeyteleshev Sep 17, 2024
ad8c5a2
Merge branch 'devel' into CB-4661-remove-includes-concept-from-resour…
sergeyteleshev Sep 18, 2024
84240cd
CB-4461 pr fixes
sergeyteleshev Sep 18, 2024
f077160
CB-4661 cleanup
sergeyteleshev Sep 18, 2024
82c0637
Merge branch 'devel' into CB-4661-remove-includes-concept-from-resour…
sergeyteleshev Sep 18, 2024
4493dc6
CB-4661 fix parallel loading of request for teams
sergeyteleshev Sep 18, 2024
9c850ca
CB-4661 cleanup
sergeyteleshev Sep 18, 2024
f2ff0ea
Merge branch 'devel' into CB-4661-remove-includes-concept-from-resour…
mr-anton-t Sep 19, 2024
d888fdc
Merge branch 'devel' into CB-4661-remove-includes-concept-from-resour…
sergeyteleshev Sep 20, 2024
4e57ce5
CB-4661 fixes aws/azure/gcp and other tabs in edit cloud connection
sergeyteleshev Sep 20, 2024
5f06d8e
Revert "CB-4661 fixes aws/azure/gcp and other tabs in edit cloud conn…
sergeyteleshev Sep 23, 2024
c3d52e4
CB-4661 adds correct fix for origin tab
sergeyteleshev Sep 23, 2024
35f0bdf
Merge branch 'devel' into CB-4661-remove-includes-concept-from-resour…
sergeyteleshev Sep 23, 2024
8a34a78
Merge branch 'devel' into CB-4661-remove-includes-concept-from-resour…
mr-anton-t Sep 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* 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, ResourceKey, resourceKeyList, ResourceKeyUtils } from '@cloudbeaver/core-resource';
import { GraphQLService } from '@cloudbeaver/core-sdk';

import type { TeamMetaParameter } from './TeamMetaParametersResource';
import { TeamsResource } from './TeamsResource';

@injectable()
export class TeamInfoMetaParametersResource extends CachedMapResource<string, TeamMetaParameter> {
constructor(
private readonly graphQLService: GraphQLService,
private readonly teamsResource: TeamsResource,
) {
super();

this.sync(this.teamsResource);
Wroud marked this conversation as resolved.
Show resolved Hide resolved
}

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,
});
const metaParameters = teams[0].metaParameters;
Wroud marked this conversation as resolved.
Show resolved Hide resolved

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.graphQLService.sdk.saveTeamMetaParameters({ teamId, parameters });
}
Wroud marked this conversation as resolved.
Show resolved Hide resolved

protected validateKey(key: string): boolean {
return typeof key === 'string';
}
}
21 changes: 4 additions & 17 deletions webapp/packages/core-authentication/src/TeamsResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
} from '@cloudbeaver/core-sdk';
import { isArraysEqual, UndefinedToNull } from '@cloudbeaver/core-utils';

import type { TeamMetaParameter } from './TeamMetaParametersResource';

Check warning on line 27 in webapp/packages/core-authentication/src/TeamsResource.ts

View check run for this annotation

Jenkins-CI-integration / CheckStyle TypeScript Report

webapp/packages/core-authentication/src/TeamsResource.ts#L27

TeamMetaParameter is defined but never used. (@typescript-eslint/no-unused-vars)

const NEW_TEAM_SYMBOL = Symbol('new-team');

export type TeamInfo = AdminTeamInfoFragment;
Expand All @@ -38,12 +40,11 @@
super();
}

async createTeam({ teamId, teamPermissions, teamName, description, metaParameters }: TeamInfo): Promise<TeamInfo> {
async createTeam({ teamId, teamPermissions, teamName, description }: TeamInfo): Promise<TeamInfo> {
const response = await this.graphQLService.sdk.createTeam({
teamId,
teamName,
description,
...this.getDefaultIncludes(),
...this.getIncludesMap(teamId),
});

Expand All @@ -55,24 +56,21 @@

this.set(newTeam.teamId, newTeam);

await this.setMetaParameters(newTeam.teamId, metaParameters);
await this.setSubjectPermissions(newTeam.teamId, teamPermissions);

return this.get(teamId)!;
}

async updateTeam({ teamId, teamPermissions, teamName, description, metaParameters }: TeamInfo): Promise<TeamInfo> {
async updateTeam({ teamId, teamPermissions, teamName, description }: TeamInfo): Promise<TeamInfo> {
const { team } = await this.graphQLService.sdk.updateTeam({
teamId,
teamName,
description,
...this.getDefaultIncludes(),
...this.getIncludesMap(teamId),
});

this.set(team.teamId, team);

await this.setMetaParameters(team.teamId, metaParameters);
await this.setSubjectPermissions(team.teamId, teamPermissions);

this.markOutdated(team.teamId);
Expand Down Expand Up @@ -119,10 +117,6 @@
}
}

async setMetaParameters(teamId: string, parameters: Record<string, any>): Promise<void> {
await this.graphQLService.sdk.saveTeamMetaParameters({ teamId, parameters });
}

protected async loader(originalKey: ResourceKey<string>, includes?: string[]): Promise<Map<string, TeamInfo>> {
const all = this.aliases.isAlias(originalKey, CachedMapAllKey);
const teamsList: TeamInfo[] = [];
Expand All @@ -136,7 +130,6 @@

const { teams } = await this.graphQLService.sdk.getTeamsList({
teamId,
...this.getDefaultIncludes(),
...this.getIncludesMap(teamId, includes),
});

Expand Down Expand Up @@ -164,12 +157,6 @@
super.dataSet(key, { ...oldTeam, ...value });
}

private getDefaultIncludes(): TeamResourceIncludes {
return {
includeMetaParameters: false,
};
}

protected validateKey(key: string): boolean {
return typeof key === 'string';
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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, ResourceKey } from '@cloudbeaver/core-resource';
import { GraphQLService } from '@cloudbeaver/core-sdk';

import { UserInfoResource } from './UserInfoResource';
import type { UserMetaParameter } from './UserMetaParametersResource';

@injectable()
export class UserInfoMetaParametersResource extends CachedDataResource<UserMetaParameter | null> {
constructor(
private readonly graphQLService: GraphQLService,
private readonly userInfoResource: UserInfoResource,
) {
super(() => null, undefined);

this.sync(this.userInfoResource);
}

protected async loader(param: ResourceKey<void>): Promise<UserMetaParameter | null> {

Check warning on line 26 in webapp/packages/core-authentication/src/UserInfoMetaParametersResource.ts

View check run for this annotation

Jenkins-CI-integration / CheckStyle TypeScript Report

webapp/packages/core-authentication/src/UserInfoMetaParametersResource.ts#L26

param is defined but never used. (@typescript-eslint/no-unused-vars)
try {
const { user } = await this.graphQLService.sdk.getActiveUserMetaParameters();

return user?.metaParameters;
Wroud marked this conversation as resolved.
Show resolved Hide resolved
} catch (exception: any) {
return null;
}
Wroud marked this conversation as resolved.
Show resolved Hide resolved
}
}
6 changes: 1 addition & 5 deletions webapp/packages/core-authentication/src/UserInfoResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class UserInfoResource extends CachedDataResource<UserInfo | null, void,
private readonly authProviderService: AuthProviderService,
private readonly sessionResource: SessionResource,
) {
super(() => null, undefined, ['customIncludeOriginDetails', 'includeConfigurationParameters']);
super(() => null, undefined, ['includeConfigurationParameters']);

this.onUserChange = new SyncExecutor();
this.onException = new SyncExecutor();
Expand Down Expand Up @@ -103,7 +103,6 @@ export class UserInfoResource extends CachedDataResource<UserInfo | null, void,
configuration: configurationId,
credentials: processedCredentials,
linkUser,
customIncludeOriginDetails: true,
forceSessionsLogout,
});

Expand Down Expand Up @@ -135,7 +134,6 @@ export class UserInfoResource extends CachedDataResource<UserInfo | null, void,
const { authInfo } = await this.graphQLService.sdk.getAuthStatus({
authId,
linkUser,
customIncludeOriginDetails: true,
});
return authInfo as AuthInfo;
},
Expand Down Expand Up @@ -281,9 +279,7 @@ export class UserInfoResource extends CachedDataResource<UserInfo | null, void,

private getDefaultIncludes(): UserInfoIncludes {
return {
customIncludeOriginDetails: true,
includeConfigurationParameters: false,
includeMetaParameters: false,
};
}
}
125 changes: 125 additions & 0 deletions webapp/packages/core-authentication/src/UsersMetaParametersResource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* 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 { runInAction } from 'mobx';

import { injectable } from '@cloudbeaver/core-di';
import {
CACHED_RESOURCE_DEFAULT_PAGE_LIMIT,
CACHED_RESOURCE_DEFAULT_PAGE_OFFSET,
CachedMapAllKey,
CachedMapResource,
CachedResourceOffsetPageKey,
CachedResourceOffsetPageListKey,
isResourceAlias,
ResourceKey,
resourceKeyList,
ResourceKeyUtils,
} from '@cloudbeaver/core-resource';
import { GraphQLService } from '@cloudbeaver/core-sdk';

import type { UserMetaParameter } from './UserMetaParametersResource';
import { UsersResource, UsersResourceFilterKey } from './UsersResource';

@injectable()
export class UsersMetaParametersResource extends CachedMapResource<string, UserMetaParameter> {
constructor(
private readonly graphQLService: GraphQLService,
private readonly usersResource: UsersResource,
) {
super();

this.sync(this.usersResource);
}

async setMetaParameters(userId: string, parameters: Record<string, any>): Promise<void> {
await this.graphQLService.sdk.saveUserMetaParameters({ userId, parameters });
this.markOutdated(userId);
}

protected async loader(originalKey: ResourceKey<string>): Promise<Map<string, UserMetaParameter>> {
const all = this.aliases.isAlias(originalKey, CachedMapAllKey);
const keys: string[] = [];
const pages: Parameters<typeof this.offsetPagination.setPage>[] = [];

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);
} else {
const pageKey =
this.aliases.isAlias(originalKey, CachedResourceOffsetPageKey) || this.aliases.isAlias(originalKey, CachedResourceOffsetPageListKey);
const filterKey = this.aliases.isAlias(originalKey, UsersResourceFilterKey);
let offset = CACHED_RESOURCE_DEFAULT_PAGE_OFFSET;
let limit = CACHED_RESOURCE_DEFAULT_PAGE_LIMIT;
let userIdMask: string | undefined;
let enabledState: boolean | undefined;

if (pageKey) {
offset = pageKey.options.offset;
limit = pageKey.options.limit;
}

if (filterKey) {
userIdMask = filterKey.options.userId;
enabledState = filterKey.options.enabledState;
}

const { users } = await this.graphQLService.sdk.getUsersMetaParametersList({
page: {
offset,
limit,
},
filter: {
userIdMask,
enabledState,
},
});

userMetaParametersList.push(...users.map(user => user.metaParameters));
keys.push(...users.map(user => user.userId));

pages.push([
CachedResourceOffsetPageListKey(offset, users.length).setParent(filterKey!),
users.map(user => user.userId),
users.length === limit,
]);
}
});

const key = resourceKeyList(keys);

runInAction(() => {
this.set(key, userMetaParametersList);
for (const pageArgs of pages) {
this.offsetPagination.setPage(...pageArgs);
}
});

return this.data;
}

protected validateKey(key: string): boolean {
return typeof key === 'string';
}
}
Loading
Loading