From fafdb89b081dc4208748c310239d96fa9f20823a Mon Sep 17 00:00:00 2001 From: Wroud Date: Thu, 28 May 2020 15:46:56 +0300 Subject: [PATCH] feat(authentication): implement createUser CB-109 --- .../Users/UsersTable/UsersTable.tsx | 2 +- .../src/Administration/UsersManagerService.ts | 24 ++++++++++++++++++- .../authentication/src/AuthProviderService.ts | 2 +- .../src/Dialog/AuthDialogController.ts | 2 +- .../Authentication/Users/createUser.gql | 9 +++++++ webapp/packages/core/src/sdk/sdk.ts | 17 +++++++++++++ 6 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 webapp/packages/core/src/queries/Authentication/Users/createUser.gql diff --git a/webapp/packages/authentication/src/Administration/Users/UsersTable/UsersTable.tsx b/webapp/packages/authentication/src/Administration/Users/UsersTable/UsersTable.tsx index 964f5be4da..6f89a84c91 100644 --- a/webapp/packages/authentication/src/Administration/Users/UsersTable/UsersTable.tsx +++ b/webapp/packages/authentication/src/Administration/Users/UsersTable/UsersTable.tsx @@ -34,7 +34,7 @@ export const UsersTable = observer(function UsersTable({ users }: Props) { return styled(useStyles(styles))( - User login + User name diff --git a/webapp/packages/authentication/src/Administration/UsersManagerService.ts b/webapp/packages/authentication/src/Administration/UsersManagerService.ts index 6c1c4fbd55..bbaec01945 100644 --- a/webapp/packages/authentication/src/Administration/UsersManagerService.ts +++ b/webapp/packages/authentication/src/Administration/UsersManagerService.ts @@ -9,14 +9,36 @@ import { injectable } from '@dbeaver/core/di'; import { CachedResource, GraphQLService, AdminUserInfo } from '@dbeaver/core/sdk'; +import { AuthProviderService } from '../AuthProviderService'; + @injectable() export class UsersManagerService { readonly users = new CachedResource([], this.refreshAsync.bind(this), data => !!data.length) constructor( - private graphQLService: GraphQLService + private graphQLService: GraphQLService, + private authProviderService: AuthProviderService, ) { } + async create(userId: string): Promise { + const { user } = await this.graphQLService.gql.createUser({ userId }); + + // TODO: maybe better to do refresh + this.users.data.push(user as AdminUserInfo); + return user as AdminUserInfo; + } + + async updateCredentials(userId: string, credentials: Record) { + const provider = 'local'; + const processedCredentials = this.authProviderService.processCredentials(provider, credentials); + + await this.graphQLService.gql.setUserCredentials({ + providerId: provider, + userId, + credentials: processedCredentials, + }); + } + private async refreshAsync(data: AdminUserInfo[]): Promise { const { users } = await this.graphQLService.gql.getUsersList(); diff --git a/webapp/packages/authentication/src/AuthProviderService.ts b/webapp/packages/authentication/src/AuthProviderService.ts index 9d9bd18ff7..216711787b 100644 --- a/webapp/packages/authentication/src/AuthProviderService.ts +++ b/webapp/packages/authentication/src/AuthProviderService.ts @@ -23,7 +23,7 @@ export class AuthProviderService { private graphQLService: GraphQLService, ) { } - processCredentials(providerId: string, credentials: any) { + processCredentials(providerId: string, credentials: Record) { const provider = this.providers.data.find(provider => provider.id === providerId); if (!provider) { diff --git a/webapp/packages/authentication/src/Dialog/AuthDialogController.ts b/webapp/packages/authentication/src/Dialog/AuthDialogController.ts index a74771168a..c99acac017 100644 --- a/webapp/packages/authentication/src/Dialog/AuthDialogController.ts +++ b/webapp/packages/authentication/src/Dialog/AuthDialogController.ts @@ -8,11 +8,11 @@ import { observable, computed } from 'mobx'; +import { ErrorDetailsDialog } from '@dbeaver/core/app'; import { injectable, IInitializableController, IDestructibleController } from '@dbeaver/core/di'; import { CommonDialogService } from '@dbeaver/core/dialogs'; import { NotificationService } from '@dbeaver/core/eventsLog'; import { GQLErrorCatcher } from '@dbeaver/core/sdk'; -import { ErrorDetailsDialog } from '@dbeaver/core/app'; import { AuthInfoService } from '../AuthInfoService'; import { AuthProviderService, AuthProvider } from '../AuthProviderService'; diff --git a/webapp/packages/core/src/queries/Authentication/Users/createUser.gql b/webapp/packages/core/src/queries/Authentication/Users/createUser.gql new file mode 100644 index 0000000000..3b9a9d3915 --- /dev/null +++ b/webapp/packages/core/src/queries/Authentication/Users/createUser.gql @@ -0,0 +1,9 @@ +query createUser($userId: ID!) { + user: createUser(userId: $userId) { + userId + + #metaParameters + #configurationParameters + #grantedRoles + } +} \ No newline at end of file diff --git a/webapp/packages/core/src/sdk/sdk.ts b/webapp/packages/core/src/sdk/sdk.ts index f50630ea6a..5c2348fb50 100644 --- a/webapp/packages/core/src/sdk/sdk.ts +++ b/webapp/packages/core/src/sdk/sdk.ts @@ -821,6 +821,13 @@ export type ChangeSessionLanguageMutationVariables = { export type ChangeSessionLanguageMutation = Pick; +export type CreateUserQueryVariables = { + userId: Scalars['ID']; +}; + + +export type CreateUserQuery = { user: Pick }; + export type DeleteUserQueryVariables = { userId: Scalars['ID']; }; @@ -1337,6 +1344,13 @@ export const ChangeSessionLanguageDocument = ` changeSessionLanguage(locale: $locale) } `; +export const CreateUserDocument = ` + query createUser($userId: ID!) { + user: createUser(userId: $userId) { + userId + } +} + `; export const DeleteUserDocument = ` query deleteUser($userId: ID!) { deleteUser(userId: $userId) @@ -1835,6 +1849,9 @@ export function getSdk(client: GraphQLClient, withWrapper: SdkFunctionWrapper = changeSessionLanguage(variables: ChangeSessionLanguageMutationVariables): Promise { return withWrapper(() => client.request(ChangeSessionLanguageDocument, variables)); }, + createUser(variables: CreateUserQueryVariables): Promise { + return withWrapper(() => client.request(CreateUserDocument, variables)); + }, deleteUser(variables: DeleteUserQueryVariables): Promise { return withWrapper(() => client.request(DeleteUserDocument, variables)); },