-
Notifications
You must be signed in to change notification settings - Fork 395
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CB-4461 removes includeMetaParameters for users resources
- Loading branch information
1 parent
f101b9a
commit 05093a5
Showing
22 changed files
with
213 additions
and
73 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
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,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 { 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 Jenkins-CI-integration / CheckStyle TypeScript Reportwebapp/packages/core-authentication/src/UserInfoMetaParametersResource.ts#L26
|
||
try { | ||
const { user } = await this.graphQLService.sdk.getActiveUserMetaParameters(); | ||
|
||
return user?.metaParameters; | ||
} catch (exception: any) { | ||
return null; | ||
} | ||
} | ||
} |
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
112 changes: 112 additions & 0 deletions
112
webapp/packages/core-authentication/src/UsersMetaDataResource.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,112 @@ | ||
/* | ||
* 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 { | ||
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 { 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); | ||
} | ||
|
||
// TODO after CB-5511 is merged. fix the logic according to the UsersResource loader | ||
protected async loader(originalKey: ResourceKey<string>): Promise<Map<string, UserMetaParameter>> { | ||
const all = this.aliases.isAlias(originalKey, CachedMapAllKey); | ||
const keys: 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); | ||
} 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)); | ||
|
||
this.offsetPagination.setPageEnd(CachedResourceOffsetPageListKey(offset, users.length).setTarget(filterKey), users.length === limit); | ||
} | ||
}); | ||
|
||
this.set(resourceKeyList(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
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
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
3 changes: 1 addition & 2 deletions
3
webapp/packages/core-sdk/src/queries/authentication/getActiveUser.gql
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
5 changes: 5 additions & 0 deletions
5
webapp/packages/core-sdk/src/queries/authentication/getActiveUserMetaParameters.gql
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,5 @@ | ||
query getActiveUserMetaParameters { | ||
user: activeUser { | ||
metaParameters | ||
} | ||
} |
8 changes: 1 addition & 7 deletions
8
webapp/packages/core-sdk/src/queries/authentication/updateUserPreferences.gql
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
16 changes: 3 additions & 13 deletions
16
webapp/packages/core-sdk/src/queries/authentication/users/createUser.gql
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 |
---|---|---|
@@ -1,15 +1,5 @@ | ||
query createUser( | ||
$userId: ID! | ||
$enabled: Boolean! | ||
$authRole: String | ||
$includeMetaParameters: Boolean! | ||
$customIncludeOriginDetails: Boolean! | ||
) { | ||
user: createUser( | ||
userId: $userId | ||
enabled: $enabled | ||
authRole: $authRole | ||
) { | ||
query createUser($userId: ID!, $enabled: Boolean!, $authRole: String, $customIncludeOriginDetails: Boolean!) { | ||
user: createUser(userId: $userId, enabled: $enabled, authRole: $authRole) { | ||
...AdminUserInfo | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
webapp/packages/core-sdk/src/queries/authentication/users/getAdminUserMetaParameters.gql
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,5 @@ | ||
query getAdminUserMetaParameters($userId: ID!) { | ||
user: adminUserInfo(userId: $userId) { | ||
metaParameters | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
webapp/packages/core-sdk/src/queries/authentication/users/getUserById.gql
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
2 changes: 1 addition & 1 deletion
2
webapp/packages/core-sdk/src/queries/authentication/users/getUsersList.gql
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
6 changes: 6 additions & 0 deletions
6
webapp/packages/core-sdk/src/queries/authentication/users/getUsersMetaParametersList.gql
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,6 @@ | ||
query getUsersMetaParametersList($page: PageInput!, $filter: AdminUserFilterInput!) { | ||
users: listUsers(page: $page, filter: $filter) { | ||
userId | ||
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
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
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.