-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[server] implement getAuthenticatedUser RPC (#19187)
- Loading branch information
1 parent
da125ed
commit 682878a
Showing
5 changed files
with
84 additions
and
202 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* Copyright (c) 2023 Gitpod GmbH. All rights reserved. | ||
* Licensed under the GNU Affero General Public License (AGPL). | ||
* See License.AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import { HandlerContext, ServiceImpl } from "@connectrpc/connect"; | ||
import { UserService as UserServiceInterface } from "@gitpod/public-api/lib/gitpod/v1/user_connect"; | ||
import { inject, injectable } from "inversify"; | ||
import { PublicAPIConverter } from "@gitpod/public-api-common/lib/public-api-converter"; | ||
import { | ||
UpdateUserRequest, | ||
UpdateUserResponse, | ||
GetAuthenticatedUserRequest, | ||
GetAuthenticatedUserResponse, | ||
SetWorkspaceAutoStartOptionsRequest, | ||
SetWorkspaceAutoStartOptionsResponse, | ||
} from "@gitpod/public-api/lib/gitpod/v1/user_pb"; | ||
import { UserService } from "../user/user-service"; | ||
import { validate as uuidValidate } from "uuid"; | ||
import { ctxUserId } from "../util/request-context"; | ||
import { ApplicationError, ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error"; | ||
|
||
@injectable() | ||
export class UserServiceAPI implements ServiceImpl<typeof UserServiceInterface> { | ||
constructor( | ||
@inject(PublicAPIConverter) private readonly converter: PublicAPIConverter, | ||
@inject(UserService) private readonly userService: UserService, | ||
) {} | ||
|
||
async getAuthenticatedUser( | ||
request: GetAuthenticatedUserRequest, | ||
_: HandlerContext, | ||
): Promise<GetAuthenticatedUserResponse> { | ||
const userId = ctxUserId(); | ||
const user = await this.userService.findUserById(userId, userId); | ||
return new GetAuthenticatedUserResponse({ | ||
user: this.converter.toUser(user), | ||
}); | ||
} | ||
|
||
async updateUser(request: UpdateUserRequest, _: HandlerContext): Promise<UpdateUserResponse> { | ||
throw new ApplicationError(ErrorCodes.UNIMPLEMENTED, "not implemented"); | ||
} | ||
|
||
async setWorkspaceAutoStartOptions( | ||
request: SetWorkspaceAutoStartOptionsRequest, | ||
_: HandlerContext, | ||
): Promise<SetWorkspaceAutoStartOptionsResponse> { | ||
const userId = ctxUserId(); | ||
|
||
const { userId: requestUserId, workspaceAutostartOptions } = request; | ||
|
||
if (!uuidValidate(requestUserId) || !workspaceAutostartOptions) { | ||
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "userId and workspaceAutostartOptions are required"); | ||
} | ||
|
||
const newWorkspaceAutostartOptions = workspaceAutostartOptions.map((o) => | ||
this.converter.fromWorkspaceAutostartOption(o), | ||
); | ||
const currentUser = await this.userService.findUserById(userId, requestUserId); | ||
await this.userService.updateUser(userId, { | ||
id: currentUser.id, | ||
additionalData: { | ||
...currentUser.additionalData, | ||
workspaceAutostartOptions: newWorkspaceAutostartOptions, | ||
}, | ||
}); | ||
|
||
return new SetWorkspaceAutoStartOptionsResponse(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.