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 all 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,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);
Wroud marked this conversation as resolved.
Show resolved Hide resolved
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';
}
}
19 changes: 2 additions & 17 deletions webapp/packages/core-authentication/src/TeamsResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ export class TeamsResource extends CachedMapResource<string, TeamInfo, TeamResou
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 +54,21 @@ export class TeamsResource extends CachedMapResource<string, TeamInfo, TeamResou

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 @@ -123,10 +119,6 @@ export class TeamsResource extends CachedMapResource<string, TeamInfo, TeamResou
}
}

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 @@ -140,7 +132,6 @@ export class TeamsResource extends CachedMapResource<string, TeamInfo, TeamResou

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

Expand Down Expand Up @@ -168,12 +159,6 @@ export class TeamsResource extends CachedMapResource<string, TeamInfo, TeamResou
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,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> {

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)
const { user } = await this.graphQLService.sdk.getActiveUserMetaParameters();

return user?.metaParameters;
}
}
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 @@ -60,7 +60,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 @@ -110,7 +110,6 @@ export class UserInfoResource extends CachedDataResource<UserInfo | null, void,
configuration: configurationId,
credentials: processedCredentials,
linkUser,
customIncludeOriginDetails: true,
forceSessionsLogout,
});

Expand Down Expand Up @@ -142,7 +141,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 @@ -288,9 +286,7 @@ export class UserInfoResource extends CachedDataResource<UserInfo | null, void,

private getDefaultIncludes(): UserInfoIncludes {
return {
customIncludeOriginDetails: true,
includeConfigurationParameters: false,
includeMetaParameters: false,
};
}
}
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';
}
}
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';
}
}
14 changes: 0 additions & 14 deletions webapp/packages/core-authentication/src/UsersResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,11 @@ export class UsersResource extends CachedMapResource<string, AdminUser, UserReso
});
}

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

async create({ userId, authRole }: UserCreateOptions): Promise<AdminUser> {
const { user } = await this.graphQLService.sdk.createUser({
userId,
authRole,
enabled: false,
...this.getDefaultIncludes(),
...this.getIncludesMap(userId),
});

Expand Down Expand Up @@ -259,7 +254,6 @@ export class UsersResource extends CachedMapResource<string, AdminUser, UserReso
if (userId !== undefined) {
const { user } = await this.graphQLService.sdk.getAdminUserInfo({
userId,
...this.getDefaultIncludes(),
...this.getIncludesMap(userId, includes),
});

Expand All @@ -284,7 +278,6 @@ export class UsersResource extends CachedMapResource<string, AdminUser, UserReso
userIdMask,
enabledState,
},
...this.getDefaultIncludes(),
...this.getIncludesMap(userId, includes),
});

Expand All @@ -311,13 +304,6 @@ export class UsersResource extends CachedMapResource<string, AdminUser, UserReso
return this.data;
}

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

protected override dataSet(key: string, value: AdminUserInfoFragment): void {
const oldValue = this.data.get(key);
super.dataSet(key, { ...oldValue, ...value });
Expand Down
Loading