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

Support basic account action for admin #934

Merged

Conversation

gusah009
Copy link
Contributor

@gusah009 gusah009 commented Jul 20, 2024

What this PR does / why we need it:

Added the admin APIs ChangePassword and DeleteAccount.

As their names suggest, these are APIs for changing passwords and deleting accounts.

Which issue(s) this PR fixes:

Fixes #849

Special notes for your reviewer:

  • I've verified that it works with mongoDB and in-memory DBs using postman.

  • As mentioned below, we will need to open an endpoint to access this API from your dashboard or CLI. client development is not included in this PR.

  • I generated the files with the make proto command, which broke the formatting of the api/docs/yorkie/v1/*.openapi.yaml files.

  • I wanted the validation of username or password on ChangePassword to be the same as SignUp, but I didn't know how to separate them into a common string, so I added a warning as a comment. If there's a good way to do it, I'd love to hear about it :)

Does this PR introduce a user-facing change?:

NONE

There is no user impact yet. we need to open an endpoint that the client can access from the dashboard or CLI.

Additional documentation:


Checklist:

  • Added relevant tests or not required
  • Didn't break anything

Summary by CodeRabbit

  • New Features

    • Added functionalities for users to change their passwords, create new accounts, and delete accounts via new API endpoints.
    • Implemented corresponding methods on the server side for secure account management operations.
    • Marked the previous signup endpoint as deprecated to facilitate the transition to the new account creation process.
  • Bug Fixes

    • Improved error handling for account management operations to ensure accurate feedback during deletions and password changes.
  • Documentation

    • Updated API documentation to reflect the new endpoints and their corresponding request/response schemas.

@CLAassistant
Copy link

CLAassistant commented Jul 20, 2024

CLA assistant check
All committers have signed the CLA.

Copy link

coderabbitai bot commented Jul 20, 2024

Warning

Rate limit exceeded

@gusah009 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 11 minutes and 52 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between ddfdff5 and 6982a77.

Walkthrough

This update enhances the AdminService by introducing functionalities for changing passwords, creating accounts, and deleting accounts. The changes include new API endpoints, RPC methods, and database operations, significantly improving administrative capabilities for managing accounts.

Changes

File(s) Change Summary
api/docs/yorkie/v1/admin.openapi.yaml Added endpoints for changing passwords, creating accounts, and deleting accounts, with necessary schemas.
api/yorkie/v1/admin.proto Introduced new RPC methods: CreateAccount, DeleteAccount, and ChangePassword with associated messages.
server/backend/database/database.go Updated database methods to reflect account management changes, including errors and new functions for accounts.
server/rpc/admin_server.go Added server methods for account deletion and password changes with appropriate validation.
server/rpc/testcases/testcases.go Updated tests to reflect new account actions and added tests for deleting accounts and changing passwords.
test/helper/helper.go Introduced a new variable for enhanced account creation password management.

Assessment against linked issues

Objective Addressed Explanation
Support basic account actions (e.g., ChangePassword, DeleteAccount) (#849)

🐇 In the meadow, with joy we bounce,
New powers for admin, we gladly announce!
Change a password, delete with ease,
User management now flows like a breeze.
Hoppy updates, oh what a delight,
For all the admin bunnies, it's a wondrous sight! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@krapie krapie requested review from krapie and hackerwins and removed request for krapie July 20, 2024 07:54
@krapie krapie added the enhancement 🌟 New feature or request label Jul 20, 2024
@gusah009 gusah009 force-pushed the support-basic-account-action-for-admin branch from 6d60b0a to 98dc7c5 Compare July 20, 2024 07:54
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a4ce314 and 98dc7c5.

Files ignored due to path filters (1)
  • api/yorkie/v1/admin.pb.go is excluded by !**/*.pb.go
Files selected for processing (10)
  • api/docs/yorkie/v1/admin.openapi.yaml (8 hunks)
  • api/types/user_fields.go (2 hunks)
  • api/yorkie/v1/admin.proto (2 hunks)
  • api/yorkie/v1/v1connect/admin.connect.go (9 hunks)
  • server/backend/database/database.go (1 hunks)
  • server/backend/database/memory/database.go (1 hunks)
  • server/backend/database/mongo/client.go (1 hunks)
  • server/rpc/admin_server.go (1 hunks)
  • server/rpc/interceptors/admin.go (1 hunks)
  • server/users/users.go (1 hunks)
Additional comments not posted (34)
api/types/user_fields.go (3)

25-25: LGTM!

The comment update provides clarity on the relationship between SignupFields and ChangePasswordFields.


39-47: LGTM!

The ChangePasswordFields struct is well-defined and consistent with SignupFields. The validation rules are appropriate.


49-52: LGTM!

The Validate method for ChangePasswordFields is consistent with the existing SignupFields validation.

server/users/users.go (1)

98-109: LGTM!

The DeleteAccountByName function is straightforward and handles errors appropriately.

api/yorkie/v1/admin.proto (6)

31-31: LGTM!

The DeleteAccount RPC is well-defined and follows the existing pattern.


32-32: LGTM!

The ChangePassword RPC is well-defined and follows the existing pattern.


67-70: LGTM!

The DeleteAccountRequest message is well-defined and includes necessary fields for account deletion.


72-73: LGTM!

The DeleteAccountResponse message is appropriately defined as an acknowledgment.


75-79: LGTM!

The ChangePasswordRequest message is well-defined and includes necessary fields for password change.


81-82: LGTM!

The ChangePasswordResponse message is appropriately defined as an acknowledgment.

server/rpc/interceptors/admin.go (1)

45-47: Verify the security implications of excluding ChangePassword and DeleteAccount from authentication.

Excluding these methods from authentication checks might expose security vulnerabilities. Ensure that these methods should indeed be accessible without authentication.

server/backend/database/database.go (2)

146-147: LGTM! Verify error handling for DeleteUserInfoByName.

The method enhances the interface's functionality for user management. Ensure that potential errors and edge cases are handled correctly.


149-150: LGTM! Verify error handling for ChangePassword.

The method enhances the interface's functionality for user management. Ensure that potential errors and edge cases are handled correctly.

server/rpc/admin_server.go (2)

98-119: LGTM! Verify error handling for DeleteAccount.

The method enhances the server's capabilities for user account management. Ensure that potential errors and edge cases are handled correctly.


121-147: LGTM! Verify error handling for ChangePassword.

The method enhances the server's capabilities for user account management. Ensure that potential errors and edge cases are handled correctly.

api/yorkie/v1/v1connect/admin.connect.go (13)

55-57: LGTM!

The addition of AdminServiceDeleteAccountProcedure is correct and aligns with the new RPC procedure.


58-60: LGTM!

The addition of AdminServiceChangePasswordProcedure is correct and aligns with the new RPC procedure.


99-99: LGTM!

The addition of the DeleteAccount method in the AdminServiceClient interface is correct and aligns with the new RPC procedure.


100-100: LGTM!

The addition of the ChangePassword method in the AdminServiceClient interface is correct and aligns with the new RPC procedure.


206-206: LGTM!

The addition of the deleteAccount client in the adminServiceClient struct is correct and aligns with the new RPC procedure.


207-207: LGTM!

The addition of the changePassword client in the adminServiceClient struct is correct and aligns with the new RPC procedure.


231-234: LGTM!

The addition of the DeleteAccount method in the adminServiceClient implementation is correct and aligns with the new RPC procedure.


236-239: LGTM!

The addition of the ChangePassword method in the adminServiceClient implementation is correct and aligns with the new RPC procedure.


300-300: LGTM!

The addition of the DeleteAccount method in the AdminServiceHandler interface is correct and aligns with the new RPC procedure.


301-301: LGTM!

The addition of the ChangePassword method in the AdminServiceHandler interface is correct and aligns with the new RPC procedure.


331-335: LGTM!

The addition of the adminServiceDeleteAccountHandler in the NewAdminServiceHandler function is correct and aligns with the new RPC procedure.


336-340: LGTM!

The addition of the adminServiceChangePasswordHandler in the NewAdminServiceHandler function is correct and aligns with the new RPC procedure.


445-451: LGTM!

The addition of the unimplemented DeleteAccount and ChangePassword methods in the UnimplementedAdminServiceHandler is correct and aligns with the new RPC procedures.

api/docs/yorkie/v1/admin.openapi.yaml (6)

18-20: Ensure response schema exists.

The response references yorkie.v1.AdminService.ChangePassword.yorkie.v1.ChangePasswordResponse. Verify that this schema is defined correctly under components/responses.

Verification successful

Ensure response schema exists.

The yorkie.v1.AdminService.ChangePassword.yorkie.v1.ChangePasswordResponse schema is correctly referenced and defined under components/schemas as yorkie.v1.ChangePasswordResponse.

  • api/docs/yorkie/v1/admin.openapi.yaml: Lines defining the schema reference and its title.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of the ChangePasswordResponse schema.

# Test: Search for the ChangePasswordResponse schema. Expect: Schema definition exists.
rg --type yaml $'ChangePasswordResponse'

Length of output: 677


42-44: Ensure response schema exists.

The response references yorkie.v1.AdminService.DeleteAccount.yorkie.v1.DeleteAccountResponse. Verify that this schema is defined correctly under components/responses.

Verification successful

The DeleteAccountResponse schema is defined and correctly referenced.

The schema DeleteAccountResponse exists under components/schemas and is correctly referenced in the api/docs/yorkie/v1/admin.openapi.yaml file.

  • Lines confirming the existence and definition:
    • api/docs/yorkie/v1/admin.openapi.yaml: yorkie.v1.AdminService.DeleteAccount.yorkie.v1.DeleteAccountResponse:
    • api/docs/yorkie/v1/admin.openapi.yaml: $ref: '#/components/schemas/yorkie.v1.DeleteAccountResponse'
    • api/docs/yorkie/v1.admin.openapi.yaml: yorkie.v1.DeleteAccountResponse:
    • api/docs/yorkie/v1/admin.openapi.yaml: title: DeleteAccountResponse
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of the DeleteAccountResponse schema.

# Test: Search for the DeleteAccountResponse schema. Expect: Schema definition exists.
rg --type yaml $'DeleteAccountResponse'

Length of output: 668


674-693: Ensure property data types are correct.

The properties currentPassword, newPassword, and username are defined as strings. Verify that these properties align with the expected data types.

Verification successful

Ensure property data types are correct.

The properties currentPassword, newPassword, and username in the yorkie.v1.ChangePasswordRequest schema are correctly defined as strings.

  • currentPassword: type: string
  • newPassword: type: string
  • username: type: string
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the data types of properties in ChangePasswordRequest schema.

# Test: Search for the property definitions. Expect: Properties are defined as strings.
rg --type yaml -A 5 $'ChangePasswordRequest'

Length of output: 2395


Script:

#!/bin/bash
# Description: Verify the complete property definitions in ChangePasswordRequest schema.

# Test: Search for the complete property definitions. Expect: Properties are defined as strings.
rg --type yaml -A 10 $'yorkie.v1.ChangePasswordRequest'

Length of output: 3029


Script:

#!/bin/bash
# Description: Verify the complete property definitions in ChangePasswordRequest schema.

# Test: Search for the complete property definitions. Expect: Properties are defined as strings.
rg --type yaml -A 20 $'yorkie.v1.ChangePasswordRequest'

Length of output: 5272


13-17: Ensure request body schema exists.

The request body references yorkie.v1.AdminService.ChangePassword.yorkie.v1.ChangePasswordRequest. Verify that this schema is defined correctly under components/requestBodies.


723-737: Ensure property data types are correct.

The properties password and username are defined as strings. Verify that these properties align with the expected data types.

Verification successful

Ensure property data types are correct.

The properties password and username in the DeleteAccountRequest schema are both correctly defined as strings.

  • password: type: string
  • username: type: string
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the data types of properties in DeleteAccountRequest schema.

# Test: Search for the property definitions. Expect: Properties are defined as strings.
rg --type yaml -A 5 $'DeleteAccountRequest'

Length of output: 2371


Script:

#!/bin/bash
# Description: Verify the data types of properties in DeleteAccountRequest schema.

# Test: Search for the specific data type definitions of the `password` and `username` properties.
rg --type yaml -A 3 -B 2 $'password:\n  type: string' api/docs/yorkie/v1/admin.openapi.yaml
rg --type yaml -A 3 -B 2 $'username:\n  type: string' api/docs/yorkie/v1/admin.openapi.yaml

Length of output: 567


Script:

#!/bin/bash
# Description: Verify the data types of properties in DeleteAccountRequest schema.

# Test: Search for the specific data type definitions of the `password` and `username` properties using multiline mode.
rg --multiline --type yaml -A 3 -B 2 $'password:\n  type: string' api/docs/yorkie/v1/admin.openapi.yaml
rg --multiline --type yaml -A 3 -B 2 $'username:\n  type: string' api/docs/yorkie/v1/admin.openapi.yaml

Length of output: 207


Script:

#!/bin/bash
# Description: Verify the data types of properties in DeleteAccountRequest schema.

# Test: Search for the entire schema definition of `DeleteAccountRequest` and include surrounding lines for context.
rg --multiline --type yaml -A 10 -B 2 'yorkie.v1.DeleteAccountRequest' api/docs/yorkie/v1/admin.openapi.yaml

Length of output: 1714


Script:

#!/bin/bash
# Description: Verify the data types of properties in DeleteAccountRequest schema.

# Test: Search for the entire schema definition of `DeleteAccountRequest` and include more surrounding lines for context.
rg --multiline --type yaml -A 15 -B 2 'yorkie.v1.DeleteAccountRequest' api/docs/yorkie/v1/admin.openapi.yaml

Length of output: 2307


37-41: Ensure request body schema exists.

The request body references yorkie.v1.AdminService.DeleteAccount.yorkie.v1.DeleteAccountRequest. Verify that this schema is defined correctly under components/requestBodies.

Verification successful

The yorkie.v1.DeleteAccountRequest schema is defined in the admin.openapi.yaml file.

  • The schema yorkie.v1.DeleteAccountRequest is present under components/schemas.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of the DeleteAccountRequest schema.

# Test: Search for the DeleteAccountRequest schema. Expect: Schema definition exists.
rg --type yaml $'DeleteAccountRequest'

Length of output: 663


Script:

#!/bin/bash
# Description: Verify the existence of the yorkie.v1.DeleteAccountRequest schema.

# Test: Search for the yorkie.v1.DeleteAccountRequest schema. Expect: Schema definition exists.
rg --type yaml $'components:\n  schemas:\n    yorkie.v1.DeleteAccountRequest'

Length of output: 268


Script:

#!/bin/bash
# Description: Verify the existence of the yorkie.v1.DeleteAccountRequest schema.

# Test: Search for the yorkie.v1.DeleteAccountRequest schema. Expect: Schema definition exists.
rg --type yaml --multiline $'components:\n  schemas:\n    yorkie.v1.DeleteAccountRequest'

Length of output: 88


Script:

#!/bin/bash
# Description: Search for any occurrence of the yorkie.v1.DeleteAccountRequest schema.

# Test: Search for the yorkie.v1.DeleteAccountRequest schema. Expect: Schema definition or reference exists.
rg --type yaml 'yorkie.v1.DeleteAccountRequest'

Length of output: 601


Script:

#!/bin/bash
# Description: Search for the definition of the yorkie.v1.DeleteAccountRequest schema.

# Test: Search for the definition of yorkie.v1.DeleteAccountRequest. Expect: Schema definition exists.
rg --type yaml --multiline 'yorkie.v1.DeleteAccountRequest:\n'

Length of output: 249

server/backend/database/mongo/client.go Outdated Show resolved Hide resolved
server/backend/database/mongo/client.go Outdated Show resolved Hide resolved
server/users/users.go Outdated Show resolved Hide resolved
server/backend/database/memory/database.go Outdated Show resolved Hide resolved
server/backend/database/memory/database.go Outdated Show resolved Hide resolved
Copy link
Member

@krapie krapie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution.
I have two things to suggest:

  1. User vs. Account
    As you can see in the database, we are using the word User, so we might need to keep consistency for the word describing "user".

  2. Test codes for Admin RPC
    How about adding test codes for newly introduced APIs? TestAdminRPCServerBackend() test function in server/rpc/server_test.go will be the best place to put test codes.

api/types/user_fields.go Outdated Show resolved Hide resolved
api/types/user_fields.go Outdated Show resolved Hide resolved
api/yorkie/v1/admin.proto Show resolved Hide resolved
server/backend/database/database.go Outdated Show resolved Hide resolved
server/backend/database/database.go Outdated Show resolved Hide resolved
server/backend/database/mongo/client.go Outdated Show resolved Hide resolved
server/backend/database/mongo/client.go Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (3)
api/types/user_fields_test.go (1)

34-34: Update function name for consistency.

Ensure that the function name TestSignupFields is updated to TestUserFields to reflect the new struct name.

  • api/types/user_fields_test.go: func TestSignupFields(t *testing.T)
Analysis chain

LGTM! But verify the struct usage in the codebase.

The code changes are approved.

However, ensure that all struct instances of UserFields match the new name.


Verify the struct renaming consistency.

The renaming of the struct to UserFields appears consistent across the codebase. To ensure completeness, verify that there are no remaining instances of the old struct name SignupFields.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all struct instances of `UserFields` match the new name.

# Test: Search for the struct usage. Expect: Only occurrences of the new name.
rg --type go -A 5 $'UserFields'

Length of output: 4169


Script:

#!/bin/bash
# Description: Verify there are no remaining instances of the old struct name `SignupFields`.

# Test: Search for any lingering instances of `SignupFields`. Expect: No occurrences.
rg --type go -A 5 $'SignupFields'

Length of output: 404

admin/client.go (1)

159-165: Ensure all instances of the SignUp method are updated to CreateUser.

The transition from SignUp to CreateUser is in progress, but there are still references to the deprecated SignUp method. Verify that all calls to the old method have been updated to use the new CreateUser method.

  • server/rpc/admin_server.go: Deprecated SignUp method still present.
  • server/rpc/testcases/testcases.go: Test cases still using SignUp.
  • api/yorkie/v1/v1connect/admin.connect.go: Deprecated SignUp method still present.
Analysis chain

LGTM! Ensure the new method is used correctly throughout the codebase.

The CreateUser method replaces the previous SignUp method, improving clarity. Verify that all calls to the old method have been updated.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `CreateUser` match the new method signature.

# Test: Search for the function usage. Expect: Only occurrences of the new method name.
rg --type go -A 5 $'CreateUser'

Length of output: 23349

server/rpc/testcases/testcases.go (1)

641-641: Update function documentation to reflect method name change.

The function documentation should be updated to reflect the change from SignUp to CreateUser for clarity.

-// RunAdminSignUpTest runs the CreateUser test in admin.
+// RunAdminCreateUserTest runs the CreateUser test in admin.
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 98dc7c5 and 35895c7.

Files ignored due to path filters (1)
  • api/yorkie/v1/admin.pb.go is excluded by !**/*.pb.go
Files selected for processing (12)
  • admin/client.go (1 hunks)
  • api/docs/yorkie/v1/admin.openapi.yaml (9 hunks)
  • api/types/user_fields.go (1 hunks)
  • api/types/user_fields_test.go (1 hunks)
  • api/yorkie/v1/admin.proto (3 hunks)
  • api/yorkie/v1/v1connect/admin.connect.go (9 hunks)
  • server/backend/database/memory/database.go (1 hunks)
  • server/rpc/admin_server.go (2 hunks)
  • server/rpc/interceptors/admin.go (1 hunks)
  • server/rpc/testcases/testcases.go (2 hunks)
  • server/users/users.go (2 hunks)
  • test/integration/user_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (5)
  • api/docs/yorkie/v1/admin.openapi.yaml
  • api/types/user_fields.go
  • server/backend/database/memory/database.go
  • server/rpc/interceptors/admin.go
  • server/users/users.go
Additional context used
GitHub Check: build
api/yorkie/v1/v1connect/admin.connect.go

[failure] 422-422:
duplicate case AdminServiceCreateUserProcedure (constant "/yorkie.v1.AdminService/CreateUser" of type string) in expression switch


[failure] 422-422:
duplicate case AdminServiceCreateUserProcedure (constant "/yorkie.v1.AdminService/CreateUser" of type string) in expression switch


[failure] 422-422:
duplicate case AdminServiceCreateUserProcedure (constant "/yorkie.v1.AdminService/CreateUser" of type string) in expression switch


[failure] 422-422:
duplicate case AdminServiceCreateUserProcedure (constant "/yorkie.v1.AdminService/CreateUser" of type string) in expression switch

GitHub Check: bench
api/yorkie/v1/v1connect/admin.connect.go

[failure] 422-422:
duplicate case AdminServiceCreateUserProcedure (constant "/yorkie.v1.AdminService/CreateUser" of type string) in expression switch

GitHub Check: sharding_test
api/yorkie/v1/v1connect/admin.connect.go

[failure] 422-422:
duplicate case AdminServiceCreateUserProcedure (constant "/yorkie.v1.AdminService/CreateUser" of type string) in expression switch

Additional comments not posted (29)
test/integration/user_test.go (3)

46-46: LGTM! But verify the method usage in the codebase.

The code changes are approved.

However, ensure that all method calls to CreateUser match the new name.

Verification successful

All method calls to CreateUser are consistent with the new name.

The verification confirms that all occurrences of CreateUser match the new name across the codebase.

  • server/users/users.go
  • server/rpc/admin_server.go
  • server/rpc/testcases/testcases.go
  • server/rpc/interceptors/admin.go
  • server/backend/database/database.go
  • test/integration/user_test.go
  • server/backend/database/mongo/client.go
  • server/backend/database/memory/database.go
  • server/backend/database/testcases/testcases.go
  • admin/client.go
  • api/yorkie/v1/admin.pb.go
  • api/yorkie/v1/v1connect/admin.connect.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all method calls to `CreateUser` match the new name.

# Test: Search for the method usage. Expect: Only occurrences of the new name.
rg --type go -A 5 $'CreateUser'

Length of output: 23349


43-43: LGTM! But verify the method usage in the codebase.

The code changes are approved.

However, ensure that all method calls to CreateUser match the new name.

Verification successful

The method usage of CreateUser is consistent across the codebase.

The renaming from SignUp to CreateUser has been correctly applied throughout the codebase.

  • All instances of the method call use CreateUser.
  • No remaining references to the old method name SignUp were found.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all method calls to `CreateUser` match the new name.

# Test: Search for the method usage. Expect: Only occurrences of the new name.
rg --type go -A 5 $'CreateUser'

Length of output: 23349


49-49: LGTM! But verify the method usage in the codebase.

The code changes are approved.

However, ensure that all method calls to CreateUser match the new name.

Verification successful

All instances of CreateUser match the expected usage.

The method CreateUser is consistently used across the codebase, and there are no discrepancies in its naming.

  • server/users/users.go
  • test/integration/user_test.go
  • server/rpc/admin_server.go
  • server/rpc/testcases/testcases.go
  • server/rpc/interceptors/admin.go
  • server/backend/database/database.go
  • server/backend/database/memory/database.go
  • server/backend/database/mongo/client.go
  • server/backend/database/testcases/testcases.go
  • admin/client.go
  • api/yorkie/v1/admin.pb.go
  • api/yorkie/v1/v1connect/admin.connect.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all method calls to `CreateUser` match the new name.

# Test: Search for the method usage. Expect: Only occurrences of the new name.
rg --type go -A 5 $'CreateUser'

Length of output: 23349

api/types/user_fields_test.go (7)

41-41: LGTM! But verify the struct usage in the codebase.

The code changes are approved.

However, ensure that all struct instances of UserFields match the new name.

Verification successful

LGTM! All struct instances of UserFields match the new name.

The verification confirms that all instances of UserFields in the codebase are consistent with the new name.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all struct instances of `UserFields` match the new name.

# Test: Search for the struct usage. Expect: Only occurrences of the new name.
rg --type go -A 5 $'UserFields'

Length of output: 4169


48-48: LGTM! But verify the struct usage in the codebase.

The code changes are approved.

However, ensure that all struct instances of UserFields match the new name.

Verification successful

Verification Successful: All instances of UserFields match the new name.

The struct UserFields is consistently used across the codebase without any discrepancies.

  • server/rpc/admin_server.go
  • api/types/user_fields_test.go
  • api/types/user_fields.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all struct instances of `UserFields` match the new name.

# Test: Search for the struct usage. Expect: Only occurrences of the new name.
rg --type go -A 5 $'UserFields'

Length of output: 4169


69-69: LGTM! But verify the struct usage in the codebase.

The code changes are approved.

However, ensure that all struct instances of UserFields match the new name.

Verification successful

Verification Successful: Struct Usage Consistent

All instances of the UserFields struct match the new name across the codebase.

  • server/rpc/admin_server.go
  • api/types/user_fields_test.go
  • api/types/user_fields.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all struct instances of `UserFields` match the new name.

# Test: Search for the struct usage. Expect: Only occurrences of the new name.
rg --type go -A 5 $'UserFields'

Length of output: 4169


55-55: LGTM! But verify the struct usage in the codebase.

The code changes are approved.

However, ensure that all struct instances of UserFields match the new name.

Verification successful

All instances of UserFields match the new name.

The struct UserFields is consistently used across the codebase without any discrepancies in naming.

  • server/rpc/admin_server.go
  • api/types/user_fields.go
  • api/types/user_fields_test.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all struct instances of `UserFields` match the new name.

# Test: Search for the struct usage. Expect: Only occurrences of the new name.
rg --type go -A 5 $'UserFields'

Length of output: 4169


62-62: LGTM! But verify the struct usage in the codebase.

The code changes are approved.

However, ensure that all struct instances of UserFields match the new name.

Verification successful

Verification successful: All instances of UserFields match the expected name.

  • server/rpc/admin_server.go
  • api/types/user_fields.go
  • api/types/user_fields_test.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all struct instances of `UserFields` match the new name.

# Test: Search for the struct usage. Expect: Only occurrences of the new name.
rg --type go -A 5 $'UserFields'

Length of output: 4169


76-76: LGTM! But verify the struct usage in the codebase.

The code changes are approved.

However, ensure that all struct instances of UserFields match the new name.

Verification successful

Verification successful: All instances of UserFields are consistent.

  • The struct UserFields is used consistently across the codebase without any indication of a new name.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all struct instances of `UserFields` match the new name.

# Test: Search for the struct usage. Expect: Only occurrences of the new name.
rg --type go -A 5 $'UserFields'

Length of output: 4169


83-83: LGTM! But verify the struct usage in the codebase.

The code changes are approved.

However, ensure that all struct instances of UserFields match the new name.

Verification successful

The script output shows multiple instances of UserFields in various files. To confirm if there has been a name change, we need to verify the definition of the UserFields struct. Let's search for the struct definition to see if it has a new name.


Verified: The struct name UserFields has not changed, and all instances in the codebase are consistent with this name.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all struct instances of `UserFields` match the new name.

# Test: Search for the struct usage. Expect: Only occurrences of the new name.
rg --type go -A 5 $'UserFields'

Length of output: 4169


Script:

#!/bin/bash
# Description: Verify the definition of the UserFields struct to check for any name changes.

# Search for the definition of the UserFields struct.
rg --type go 'type UserFields struct'

Length of output: 89

api/yorkie/v1/admin.proto (11)

60-63: LGTM!

The code changes are approved.


65-67: LGTM!

The code changes are approved.


78-81: LGTM!

The code changes are approved.


83-84: LGTM!

The code changes are approved.


86-89: LGTM!

The code changes are approved.


92-93: LGTM!

The code changes are approved.


Line range hint 54-57:
LGTM!

The code changes are approved.


59-59: LGTM!

The code changes are approved.


31-31: LGTM! But verify the RPC usage in the codebase.

The code changes are approved.

However, ensure that all RPC calls to CreateUser match the new name.

Verification successful

Let's update the shell script to search for the CreateUser RPC in all .proto files without specifying the file type.


LGTM! But verify the RPC usage in the codebase.

The code changes are approved.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all RPC calls to `CreateUser` match the new name.

# Test: Search for the RPC usage. Expect: Only occurrences of the new name.
rg --type proto -A 5 $'CreateUser'

Length of output: 63


Script:

#!/bin/bash
# Description: Verify all RPC calls to `CreateUser` match the new name.

# Test: Search for the RPC usage. Expect: Only occurrences of the new name.
rg 'CreateUser' --glob '*.proto' -A 5

Length of output: 1167


33-33: LGTM! But verify the RPC usage in the codebase.

The code changes are approved.

However, ensure that all RPC calls to DeleteAccount match the new name.

Verification successful

RPC usage for DeleteAccount is consistent.

The search results show that the DeleteAccount RPC and its related request/response messages are defined in api/yorkie/v1/admin.proto, and there are no other occurrences in the .proto files.

  • api/yorkie/v1/admin.proto: rpc DeleteAccount(DeleteAccountRequest) returns (DeleteAccountResponse) {}
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all RPC calls to `DeleteAccount` match the new name.

# Test: Search for the RPC usage. Expect: Only occurrences of the new name.
rg --type proto -A 5 $'DeleteAccount'

Length of output: 66


Script:

#!/bin/bash
# Description: Verify all RPC calls to `DeleteAccount` match the new name.

# Test: Search for the RPC usage in .proto files. Expect: Only occurrences of the new name.
rg --glob '*.proto' -A 5 'DeleteAccount'

Length of output: 1063


34-34: LGTM! But verify the RPC usage in the codebase.

The code changes are approved.

However, ensure that all RPC calls to ChangePassword match the new name.

Verification successful

Verification Complete: RPC usage of ChangePassword is consistent across the codebase.

The ChangePassword RPC call is used in multiple files, including server/users/users.go, server/rpc/admin_server.go, and others. All occurrences match the new name and implementation in admin.proto.

  • server/users/users.go
  • server/rpc/admin_server.go
  • server/rpc/interceptors/admin.go
  • server/backend/database/database.go
  • server/backend/database/mongo/client.go
  • server/backend/database/memory/database.go
  • api/yorkie/v1/admin.proto
  • api/yorkie/v1/admin.pb.go
  • api/yorkie/v1/v1connect/admin.connect.go
  • api/docs/yorkie/v1/admin.openapi.yaml
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all RPC calls to `ChangePassword` match the new name.

# Test: Search for the RPC usage. Expect: Only occurrences of the new name.
rg --type proto -A 5 $'ChangePassword'

Length of output: 67


Script:

#!/bin/bash
# Description: Verify all RPC calls to `ChangePassword` match the new name.

# Find all .proto files and search for the RPC usage.
fd -e proto -x rg 'ChangePassword' {}

Length of output: 184


Script:

#!/bin/bash
# Description: Verify all RPC calls to `ChangePassword` match the new name.

# Search for the RPC usage in all file types.
rg 'ChangePassword'

Length of output: 7270

server/rpc/admin_server.go (2)

131-156: LGTM! Verify the implementation of called functions.

The ChangePassword method is well-structured, with proper error handling and validation. Ensure that the users.IsCorrectPassword and users.ChangePassword functions are correctly implemented and handle errors appropriately.

Verification successful

Verification successful.

The IsCorrectPassword and ChangePassword functions are correctly implemented with proper error handling.

  • IsCorrectPassword retrieves user info, compares the hashed password, and returns the user info if the password matches.
  • ChangePassword hashes the new password and updates it in the database.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of `users.IsCorrectPassword` and `users.ChangePassword`.

# Test: Search for the function definitions. Expect: Correct implementation with proper error handling.
rg --type go -A 10 $'func IsCorrectPassword'
rg --type go -A 10 $'func ChangePassword'

Length of output: 1035


Script:

#!/bin/bash
# Fetch the complete implementation of `IsCorrectPassword` function.
rg --type go -A 20 'func IsCorrectPassword' server/users/users.go

# Fetch the complete implementation of `ChangePassword` function.
rg --type go -A 20 'func ChangePassword' server/users/users.go

Length of output: 854


108-128: LGTM! Verify the implementation of called functions.

The DeleteAccount method is well-structured, with proper error handling and validation. Ensure that the users.IsCorrectPassword and users.DeleteAccountByName functions are correctly implemented and handle errors appropriately.

Verification successful

Verified: The DeleteAccount method in admin_server.go is well-structured, with proper error handling and validation. Both users.IsCorrectPassword and users.DeleteAccountByName are correctly implemented and handle errors appropriately.

  • IsCorrectPassword retrieves user info and compares the provided password with the stored hash.
  • DeleteAccountByName deletes the user info from the database and handles any errors that may arise.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of `users.IsCorrectPassword` and `users.DeleteAccountByName`.

# Test: Search for the function definitions. Expect: Correct implementation with proper error handling.
rg --type go -A 10 $'func IsCorrectPassword'
rg --type go -A 10 $'func DeleteAccountByName'

Length of output: 988


Script:

#!/bin/bash
# Description: Retrieve the full implementation of `users.IsCorrectPassword` and `users.DeleteAccountByName`.

# Fetch the complete implementation of `IsCorrectPassword`.
rg --type go -A 20 'func IsCorrectPassword' server/users/users.go

# Fetch the complete implementation of `DeleteAccountByName`.
rg --type go -A 20 'func DeleteAccountByName' server/users/users.go

Length of output: 936

api/yorkie/v1/v1connect/admin.connect.go (5)

143-152: LGTM! Ensure correct initialization of new clients.

The NewAdminServiceClient function initializes clients for the new RPC procedures. Verify their correct initialization.

Verification successful

Verified: Correct initialization of new clients.

The NewAdminServiceClient function correctly initializes clients for the new RPC procedures deleteAccount and changePassword.

  • deleteAccount client initialized with connect.NewClient[v1.DeleteAccountRequest, v1.DeleteAccountResponse]
  • changePassword client initialized with connect.NewClient[v1.ChangePasswordRequest, v1.ChangePasswordResponse]
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the initialization of new clients in `NewAdminServiceClient`.

# Test: Search for the client initialization. Expect: Correct initialization in the function.
rg --type go -A 10 $'connect.NewClient'

Length of output: 9805


216-217: LGTM! Ensure correct integration of new clients.

The adminServiceClient struct includes new fields for the DeleteAccount and ChangePassword clients. Verify their correct integration.

Verification successful

LGTM! The deleteAccount and changePassword clients are correctly integrated into the adminServiceClient struct.

The new clients are properly added and utilized in the respective methods, ensuring their correct integration.

  • deleteAccount client initialization and usage found.
  • changePassword client initialization and usage found.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the integration of new clients in `adminServiceClient`.

# Test: Search for the client fields. Expect: Correct integration in the struct.
rg --type go -A 5 $'deleteAccount'
rg --type go -A 5 $'changePassword'

Length of output: 3780


57-62: LGTM! Ensure correct integration of new RPC procedures.

The new RPC procedures DeleteAccount and ChangePassword enhance the AdminService. Verify their correct integration.

Verification successful

LGTM! The new RPC procedures DeleteAccount and ChangePassword are correctly integrated.

The integration of the new RPC procedures DeleteAccount and ChangePassword enhances the AdminService. The procedures are well-defined and implemented across various files, ensuring proper functionality.

  • server/rpc/admin_server.go: Implementation of DeleteAccount and ChangePassword.
  • server/users/users.go: Supporting functions for DeleteAccount and ChangePassword.
  • api/yorkie/v1/admin.pb.go: Definitions for request and response messages.
  • api/yorkie/v1/v1connect/admin.connect.go: Client-side and server-side handlers for the procedures.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the integration of new RPC procedures.

# Test: Search for the procedure usage. Expect: Correct integration in the service.
rg --type go -A 5 $'DeleteAccount'
rg --type go -A 5 $'ChangePassword'

Length of output: 34678


103-104: LGTM! Ensure correct implementation of new methods.

The new methods DeleteAccount and ChangePassword enhance the AdminServiceClient interface. Verify their correct implementation.

Verification successful

The methods DeleteAccount and ChangePassword are correctly implemented in the adminServiceClient.

  • DeleteAccount method implementation found in api/yorkie/v1/v1connect/admin.connect.go.
  • ChangePassword method implementation found in api/yorkie/v1/v1connect/admin.connect.go.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of new methods in `AdminServiceClient`.

# Test: Search for the method definitions. Expect: Correct implementation in the client.
rg --type go -A 10 $'func (c *adminServiceClient) DeleteAccount'
rg --type go -A 10 $'func (c *adminServiceClient) ChangePassword'

Length of output: 132


Script:

#!/bin/bash
# Description: Verify the implementation of new methods in `AdminServiceClient`.

# Test: Search for the method definitions more broadly.
rg 'func (c \*adminServiceClient) DeleteAccount' --type go -A 10
rg 'func (c \*adminServiceClient) ChangePassword' --type go -A 10

Length of output: 134


Script:

#!/bin/bash
# Description: Verify the presence of any references to `DeleteAccount` and `ChangePassword` methods in the codebase.

# Test: Search for references to the methods.
rg 'DeleteAccount' --type go
rg 'ChangePassword' --type go

Length of output: 10493


473-479: LGTM! Ensure appropriate error messages for unimplemented methods.

The UnimplementedAdminServiceHandler struct includes unimplemented methods for DeleteAccount and ChangePassword, ensuring appropriate error messages.

server/rpc/testcases/testcases.go (1)

649-649: Ensure CreateUser method aligns with intended functionality.

Verify that the CreateUser method correctly replaces the SignUp method and that the test cases remain valid.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

Outside diff range, codebase verification and nitpick comments (3)
api/docs/yorkie/v1/admin.openapi.yaml (3)

13-24: Ensure the description field is filled.

The description field for the ChangeUserPassword endpoint is currently empty. Providing a meaningful description enhances the API documentation.

-      description: ""
+      description: "Endpoint to change a user's password."

37-48: Ensure the description field is filled.

The description field for the CreateUser endpoint is currently empty. Providing a meaningful description enhances the API documentation.

-      description: ""
+      description: "Endpoint to create a new user."

49-60: Ensure the description field is filled.

The description field for the DeleteAccount endpoint is currently empty. Providing a meaningful description enhances the API documentation.

-      description: ""
+      description: "Endpoint to delete a user account."
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 35895c7 and dadbca8.

Files ignored due to path filters (1)
  • api/yorkie/v1/admin.pb.go is excluded by !**/*.pb.go
Files selected for processing (9)
  • api/docs/yorkie/v1/admin.openapi.yaml (9 hunks)
  • api/yorkie/v1/admin.proto (3 hunks)
  • api/yorkie/v1/v1connect/admin.connect.go (9 hunks)
  • server/backend/database/database.go (1 hunks)
  • server/backend/database/memory/database.go (1 hunks)
  • server/backend/database/mongo/client.go (1 hunks)
  • server/rpc/admin_server.go (2 hunks)
  • server/rpc/interceptors/admin.go (1 hunks)
  • server/users/users.go (2 hunks)
Files skipped from review as they are similar to previous changes (5)
  • api/yorkie/v1/admin.proto
  • server/backend/database/database.go
  • server/backend/database/memory/database.go
  • server/rpc/interceptors/admin.go
  • server/users/users.go
Additional context used
GitHub Check: bench
server/rpc/admin_server.go

[failure] 134-134:
undefined: api.ChangePasswordRequest


[failure] 135-135:
undefined: api.ChangePasswordResponse


[failure] 156-156:
undefined: api.ChangePasswordResponse

GitHub Check: sharding_test
server/rpc/admin_server.go

[failure] 134-134:
undefined: api.ChangePasswordRequest


[failure] 135-135:
undefined: api.ChangePasswordResponse


[failure] 156-156:
undefined: api.ChangePasswordResponse

GitHub Check: build
server/rpc/admin_server.go

[failure] 134-134:
undefined: api.ChangePasswordRequest


[failure] 135-135:
undefined: api.ChangePasswordResponse


[failure] 156-156:
undefined: api.ChangePasswordResponse (typecheck)


[failure] 134-134:
undefined: api.ChangePasswordRequest


[failure] 135-135:
undefined: api.ChangePasswordResponse


[failure] 156-156:
undefined: api.ChangePasswordResponse) (typecheck)


[failure] 134-134:
undefined: api.ChangePasswordRequest


[failure] 135-135:
undefined: api.ChangePasswordResponse

Additional comments not posted (7)
api/yorkie/v1/v1connect/admin.connect.go (1)

101-101: LGTM!

The CreateUser procedure is correctly implemented.

Also applies to: 237-239

api/docs/yorkie/v1/admin.openapi.yaml (6)

17-17: Verify the schema reference for the request body.

Ensure that #/components/requestBodies/yorkie.v1.AdminService.ChangeUserPassword.yorkie.v1.ChangeUserPasswordRequest is correctly defined in the components section.

Verification successful

Schema reference for the request body is correctly defined.

The schema #/components/requestBodies/yorkie.v1.AdminService.ChangeUserPassword.yorkie.v1.ChangeUserPasswordRequest is correctly defined and references the valid schema #/components/schemas/yorkie.v1.ChangeUserPasswordRequest, which includes the necessary properties.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the schema reference for the request body of ChangeUserPassword endpoint.

# Test: Search for the schema definition. Expect: Correct definition.
rg --type yaml $'yorkie.v1.AdminService.ChangeUserPassword.yorkie.v1.ChangeUserPasswordRequest'

Length of output: 374


Script:

#!/bin/bash
# Description: Locate and display the definition of the schema reference for the request body of ChangeUserPassword endpoint.

# Search for the definition of the schema in the components section.
rg --type yaml -A 10 'yorkie.v1.AdminService.ChangeUserPassword.yorkie.v1.ChangeUserPasswordRequest:' api/docs/yorkie/v1/admin.openapi.yaml

Length of output: 589


Script:

#!/bin/bash
# Description: Locate and display the definition of the schema 'yorkie.v1.ChangeUserPasswordRequest' in the components section.

# Search for the definition of the schema in the components section.
rg --type yaml -A 10 'yorkie.v1.ChangeUserPasswordRequest:' api/docs/yorkie/v1/admin.openapi.yaml

Length of output: 870


20-20: Verify the schema reference for the response body.

Ensure that #/components/responses/yorkie.v1.AdminService.ChangeUserPassword.yorkie.v1.ChangeUserPasswordResponse is correctly defined in the components section.

Verification successful

The schema reference for the response body is correctly defined.

The #/components/responses/yorkie.v1.AdminService.ChangeUserPassword.yorkie.v1.ChangeUserPasswordResponse reference and its corresponding schema yorkie.v1.ChangeUserPasswordResponse are properly defined in the components section of the admin.openapi.yaml file.

  • The response reference is located in components/responses.
  • The schema definition is located in components/schemas.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the schema reference for the response body of ChangeUserPassword endpoint.

# Test: Search for the schema definition. Expect: Correct definition.
rg --type yaml $'yorkie.v1.AdminService.ChangeUserPassword.yorkie.v1.ChangeUserPasswordResponse'

Length of output: 375


Script:

#!/bin/bash
# Description: Extract and display the definition of yorkie.v1.AdminService.ChangeUserPassword.yorkie.v1.ChangeUserPasswordResponse from the components/responses section.

# Extract the definition of the specified schema reference.
rg -A 10 'yorkie.v1.AdminService.ChangeUserPassword.yorkie.v1.ChangeUserPasswordResponse:' api/docs/yorkie/v1/admin.openapi.yaml

Length of output: 583


Script:

#!/bin/bash
# Description: Extract and display the definition of yorkie.v1.ChangeUserPasswordResponse from the components/schemas section.

# Extract the definition of the specified schema reference.
rg -A 10 'yorkie.v1.ChangeUserPasswordResponse:' api/docs/yorkie/v1/admin.openapi.yaml

Length of output: 863


56-56: Verify the schema reference for the response body.

Ensure that #/components/responses/yorkie.v1.AdminService.DeleteAccount.yorkie.v1.DeleteAccountResponse is correctly defined in the components section.

Verification successful

The schema reference for the response body is correctly defined.

  • The reference #/components/responses/yorkie.v1.AdminService.DeleteAccount.yorkie.v1.DeleteAccountResponse exists and correctly points to the schema yorkie.v1.DeleteAccountResponse.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the schema reference for the response body of DeleteAccount endpoint.

# Test: Search for the schema definition. Expect: Correct definition.
rg --type yaml $'yorkie.v1.AdminService.DeleteAccount.yorkie.v1.DeleteAccountResponse'

Length of output: 345


Script:

#!/bin/bash
# Description: Extract the definition of the schema reference for the response body of DeleteAccount endpoint.

# Extract the definition of the schema reference.
rg -A 10 'yorkie.v1.AdminService.DeleteAccount.yorkie.v1.DeleteAccountResponse' api/docs/yorkie/v1/admin.openapi.yaml

Length of output: 990


Script:

#!/bin/bash
# Description: Extract the definition of the schema referenced by DeleteAccountResponse.

# Extract the definition of the schema reference.
rg -A 10 'yorkie.v1.DeleteAccountResponse' api/docs/yorkie/v1/admin.openapi.yaml

Length of output: 1546


44-44: Verify the schema reference for the response body.

Ensure that #/components/responses/yorkie.v1.AdminService.CreateUser.yorkie.v1.CreateUserResponse is correctly defined in the components section.

Verification successful

The schema reference for the response body is correctly defined.

  • The reference #/components/responses/yorkie.v1.AdminService.CreateUser.yorkie.v1.CreateUserResponse is present in the components section.
  • The referenced schema #/components/schemas/yorkie.v1.CreateUserResponse is also properly defined.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the schema reference for the response body of CreateUser endpoint.

# Test: Search for the schema definition. Expect: Correct definition.
rg --type yaml $'yorkie.v1.AdminService.CreateUser.yorkie.v1.CreateUserResponse'

Length of output: 327


Script:

#!/bin/bash
# Description: Extract the full definition of the schema reference for the response body of CreateUser endpoint.

# Test: Search for the full definition of the schema reference.
rg -A 10 'yorkie.v1.AdminService.CreateUser.yorkie.v1.CreateUserResponse:' api/docs/yorkie/v1/admin.openapi.yaml

Length of output: 535


Script:

#!/bin/bash
# Description: Verify the schema reference for yorkie.v1.CreateUserResponse.

# Test: Search for the definition of yorkie.v1.CreateUserResponse.
rg -A 10 'yorkie.v1.CreateUserResponse:' api/docs/yorkie/v1/admin.openapi.yaml

Length of output: 821


41-41: Verify the schema reference for the request body.

Ensure that #/components/requestBodies/yorkie.v1.AdminService.CreateUser.yorkie.v1.CreateUserRequest is correctly defined in the components section.

Verification successful

The schema reference for the request body is correctly defined.

The #/components/requestBodies/yorkie.v1.AdminService.CreateUser.yorkie.v1.CreateUserRequest reference points to a valid schema definition in the components section.

  • The schema definition for yorkie.v1.AdminService.CreateUser.yorkie.v1.CreateUserRequest correctly references #/components/schemas/yorkie.v1.CreateUserRequest.
  • The yorkie.v1.CreateUserRequest schema is properly defined with the necessary properties.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the schema reference for the request body of CreateUser endpoint.

# Test: Search for the schema definition. Expect: Correct definition.
rg --type yaml $'yorkie.v1.AdminService.CreateUser.yorkie.v1.CreateUserRequest'

Length of output: 326


Script:

#!/bin/bash
# Description: Extract and display the schema definition for yorkie.v1.AdminService.CreateUser.yorkie.v1.CreateUserRequest

# Extract the relevant section from the YAML file
rg -A 10 'yorkie.v1.AdminService.CreateUser.yorkie.v1.CreateUserRequest:' api/docs/yorkie/v1/admin.openapi.yaml

Length of output: 529


Script:

#!/bin/bash
# Description: Verify the schema definition for yorkie.v1.CreateUserRequest

# Search for the schema definition in the YAML file
rg -A 10 'yorkie.v1.CreateUserRequest:' api/docs/yorkie/v1/admin.openapi.yaml

Length of output: 792


53-53: Verify the schema reference for the request body.

Ensure that #/components/requestBodies/yorkie.v1.AdminService.DeleteAccount.yorkie.v1.DeleteAccountRequest is correctly defined in the components section.

Verification successful

The schema reference for the request body is correctly defined.

The reference #/components/requestBodies/yorkie.v1.AdminService.DeleteAccount.yorkie.v1.DeleteAccountRequest and its associated schema yorkie.v1.DeleteAccountRequest are both properly structured and complete.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the schema reference for the request body of DeleteAccount endpoint.

# Test: Search for the schema definition. Expect: Correct definition.
rg --type yaml $'yorkie.v1.AdminService.DeleteAccount.yorkie.v1.DeleteAccountRequest'

Length of output: 344


Script:

#!/bin/bash
# Description: Extract and display the schema definition for the request body of DeleteAccount endpoint.

# Extract the schema definition for detailed inspection.
rg -A 10 'yorkie.v1.AdminService.DeleteAccount.yorkie.v1.DeleteAccountRequest:' api/docs/yorkie/v1/admin.openapi.yaml

Length of output: 543


Script:

#!/bin/bash
# Description: Verify the schema definition for yorkie.v1.DeleteAccountRequest.

# Search for the schema definition to ensure it is correctly defined.
rg -A 10 'yorkie.v1.DeleteAccountRequest:' api/docs/yorkie/v1/admin.openapi.yaml

Length of output: 806

server/rpc/admin_server.go Show resolved Hide resolved
server/rpc/admin_server.go Outdated Show resolved Hide resolved
api/yorkie/v1/v1connect/admin.connect.go Outdated Show resolved Hide resolved
api/yorkie/v1/v1connect/admin.connect.go Outdated Show resolved Hide resolved
server/backend/database/mongo/client.go Outdated Show resolved Hide resolved
@krapie
Copy link
Member

krapie commented Jul 21, 2024

@gusah009 There seems to be lint error causing CI to fail. Could you please lint it again?

@gusah009 gusah009 force-pushed the support-basic-account-action-for-admin branch from dadbca8 to 8168ab6 Compare July 21, 2024 08:09
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Outside diff range, codebase verification and nitpick comments (7)
api/docs/yorkie/v1/admin.openapi.yaml (7)

14-15: Add a description for the ChangeUserPassword endpoint.

The description field is currently empty. Adding a description will improve the documentation.

-      description: ""
+      description: "Allows an admin to change a user's password."

39-40: Add a description for the CreateUser endpoint.

The description field is currently empty. Adding a description will improve the documentation.

-      description: ""
+      description: "Allows an admin to create a new user."

51-52: Add a description for the DeleteUser endpoint.

The description field is currently empty. Adding a description will improve the documentation.

-      description: ""
+      description: "Allows an admin to delete a user."

705-723: Add descriptions for the fields in ChangeUserPasswordRequest.

The descriptions for the fields are currently empty. Adding descriptions will improve the documentation.

-          description: ""
+          description: "The current password of the user."
-          description: ""
+          description: "The new password for the user."
-          description: ""
+          description: "The username of the user."

754-767: Add descriptions for the fields in CreateUserRequest.

The descriptions for the fields are currently empty. Adding descriptions will improve the documentation.

-          description: ""
+          description: "The password for the new user."
-          description: ""
+          description: "The username for the new user."

770-779: Add a description for the user field in CreateUserResponse.

The description for the user field is currently empty. Adding a description will improve the documentation.

-          description: ""
+          description: "The newly created user."

782-795: Add descriptions for the fields in DeleteUserRequest.

The descriptions for the fields are currently empty. Adding descriptions will improve the documentation.

-          description: ""
+          description: "The password for the user to be deleted."
-          description: ""
+          description: "The username of the user to be deleted."
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between dadbca8 and 8168ab6.

Files ignored due to path filters (1)
  • api/yorkie/v1/admin.pb.go is excluded by !**/*.pb.go
Files selected for processing (12)
  • api/docs/yorkie/v1/admin.openapi.yaml (9 hunks)
  • api/yorkie/v1/admin.proto (3 hunks)
  • api/yorkie/v1/v1connect/admin.connect.go (9 hunks)
  • server/backend/database/database.go (1 hunks)
  • server/backend/database/memory/database.go (1 hunks)
  • server/backend/database/mongo/client.go (1 hunks)
  • server/rpc/admin_server.go (3 hunks)
  • server/rpc/interceptors/admin.go (1 hunks)
  • server/rpc/server_test.go (1 hunks)
  • server/rpc/testcases/testcases.go (2 hunks)
  • server/users/users.go (2 hunks)
  • test/sharding/server_test.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • test/sharding/server_test.go
Files skipped from review as they are similar to previous changes (5)
  • api/yorkie/v1/admin.proto
  • server/backend/database/database.go
  • server/backend/database/memory/database.go
  • server/rpc/interceptors/admin.go
  • server/users/users.go
Additional context used
GitHub Check: build
server/rpc/testcases/testcases.go

[failure] 647-647:
string 123! has 3 occurrences, make it a constant (goconst)

Additional comments not posted (18)
server/rpc/server_test.go (3)

178-180: LGTM!

The test case name change from "admin signup test" to "admin create user test" accurately reflects the functionality being tested.


186-188: LGTM!

The new test case for deleting a user (admin delete user test) is correctly named and calls the appropriate function.


190-192: LGTM!

The new test case for changing a user's password (admin change password test) is correctly named and calls the appropriate function.

server/rpc/admin_server.go (3)

75-93: LGTM!

The CreateUser method correctly validates the user fields and creates a new user. Error handling is also appropriately managed.


120-141: LGTM!

The DeleteUser method correctly validates the user's password and deletes the user account. Error handling is also appropriately managed.


143-169: LGTM!

The ChangeUserPassword method correctly validates the new password fields, checks the current password, and updates the password. Error handling is also appropriately managed.

api/yorkie/v1/v1connect/admin.connect.go (6)

53-54: LGTM!

The AdminServiceCreateUserProcedure is correctly defined with its fully-qualified name.


57-58: LGTM!

The AdminServiceDeleteUserProcedure is correctly defined with its fully-qualified name.


60-61: LGTM!

The AdminServiceChangeUserPasswordProcedure is correctly defined with its fully-qualified name.


100-101: LGTM!

The CreateUser method is correctly added to the AdminServiceClient interface and implemented in the adminServiceClient struct.

Also applies to: 235-238


102-103: LGTM!

The DeleteUser method is correctly added to the AdminServiceClient interface and implemented in the adminServiceClient struct.

Also applies to: 245-248


103-103: LGTM!

The ChangeUserPassword method is correctly added to the AdminServiceClient interface and implemented in the adminServiceClient struct.

Also applies to: 250-253

server/rpc/testcases/testcases.go (3)

734-801: LGTM! But verify the function usage in the codebase.

The new function RunAdminChangePasswordTest is well-structured and includes necessary error handling.

However, ensure that the function is correctly integrated and used within the codebase.

Verification successful

The function RunAdminChangePasswordTest is correctly integrated and used within the codebase.

  • It is invoked in the server/rpc/server_test.go file, indicating proper integration into the test suite.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the function usage of `RunAdminChangePasswordTest` in the codebase.

# Test: Search for the function usage. Expect: Appropriate integration and usage.
rg --type go -A 5 $'RunAdminChangePasswordTest'

Length of output: 908


696-732: LGTM! But verify the function usage in the codebase.

The new function RunAdminDeleteUserTest is well-structured and includes necessary error handling.

However, ensure that the function is correctly integrated and used within the codebase.

Verification successful

The function RunAdminDeleteUserTest is correctly integrated and used within the codebase.

  • The function is utilized in server/rpc/server_test.go.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the function usage of `RunAdminDeleteUserTest` in the codebase.

# Test: Search for the function usage. Expect: Appropriate integration and usage.
rg --type go -A 5 $'RunAdminDeleteUserTest'

Length of output: 859


641-661: LGTM! But verify the function usage in the codebase.

The renaming from RunAdminSignUpTest to RunAdminCreateUserTest and the update from SignUp to CreateUser are appropriate.

However, ensure that all function calls to RunAdminCreateUserTest match the new name and method call.

Verification successful

Verification successful!

The function RunAdminCreateUserTest is correctly used in the codebase with the new name and method call.

  • server/rpc/server_test.go
  • test/sharding/server_test.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `RunAdminCreateUserTest` match the new name and method call.

# Test: Search for the function usage. Expect: Only occurrences of the new name and method call.
rg --type go -A 5 $'RunAdminCreateUserTest'

Length of output: 1181

Tools
GitHub Check: build

[failure] 647-647:
string 123! has 3 occurrences, make it a constant (goconst)

server/backend/database/mongo/client.go (1)

660-673: Enhance error handling and logging.

Consider adding more specific error messages and logging for better traceability.

updateResult, err := c.collection(ColUsers).UpdateOne(ctx,
	bson.M{"username": username},
	bson.M{"$set": bson.M{"hashed_password": hashedNewPassword}},
)
if err != nil {
+	logging.DefaultLogger().Errorf("Failed to update password for user: %s, error: %v", username, err)
	return fmt.Errorf("failed to update password for user %s: %w", username, err)
}
if updateResult.ModifiedCount == 0 {
+	logging.DefaultLogger().Warnf("No user found to update password with username: %s", username)
	return fmt.Errorf("no user found with username %s", username)
}
+logging.DefaultLogger().Infof("Password updated for user: %s", username)
return nil

Likely invalid or redundant comment.

api/docs/yorkie/v1/admin.openapi.yaml (2)

183-183: Deprecation notice is clear and correctly references the new functionality.

The deprecation notice for the SignUp endpoint is clear and correctly references the CreateUser functionality.


726-729: Confirm if ChangeUserPasswordResponse is intended to be empty.

The schema has no properties. If no properties are needed, this should be explicitly stated.

-      description: ""
+      description: "Response schema for ChangeUserPassword. No properties are needed."

server/backend/database/mongo/client.go Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8168ab6 and fe4397a.

Files selected for processing (2)
  • server/rpc/testcases/testcases.go (2 hunks)
  • test/helper/helper.go (1 hunks)
Additional comments not posted (4)
test/helper/helper.go (1)

67-67: LGTM! But verify the usage of the new variable.

The new variable AdminPasswordForCreateUser is defined correctly. Ensure that it is used appropriately in the codebase.

Verification successful

LGTM! The new variable AdminPasswordForCreateUser is used appropriately in the codebase.

The variable is used in the functions RunAdminCreateUserTest, RunAdminDeleteUserTest, and RunAdminChangePasswordTest for setting the adminPassword in user creation tests.

  • server/rpc/testcases/testcases.go: Lines where AdminPasswordForCreateUser is used.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the new variable `AdminPasswordForCreateUser`.

# Test: Search for the usage of the new variable. Expect: Appropriate usage in the codebase.
rg --type go 'AdminPasswordForCreateUser'

Length of output: 385


Script:

#!/bin/bash
# Description: Extract the relevant lines from `server/rpc/testcases/testcases.go` to review the context of the usage of `AdminPasswordForCreateUser`.

# Extract 5 lines before and after each occurrence of `AdminPasswordForCreateUser` for context.
rg --type go 'AdminPasswordForCreateUser' -A 5 -B 5 server/rpc/testcases/testcases.go

Length of output: 1046

server/rpc/testcases/testcases.go (3)

641-661: LGTM! The renaming and method call update are appropriate.

The function RunAdminSignUpTest has been correctly renamed to RunAdminCreateUserTest, and the internal method call has been updated from SignUp to CreateUser.


696-731: LGTM! The new test function is comprehensive.

The function RunAdminDeleteUserTest correctly tests the deletion of a user and ensures appropriate error handling for non-existent users.


734-801: LGTM! The new test function is comprehensive.

The function RunAdminChangePasswordTest correctly tests the password change process and ensures appropriate error handling for invalid operations.

@gusah009
Copy link
Contributor Author

@krapie hello. I agree with all of your suggestions in the comments, so I've made the following changes.

  1. In response to User vs Account, I have unified to use User. ex) DeleteAccount -> DeleteUser

  2. I also agree that the Admin RPC needs test code, so I added a test case that is simple but covers a few cases.

In addition, I also included the review. Thank you for your careful review.

@gusah009 gusah009 requested a review from krapie July 21, 2024 08:20
Copy link
Member

@krapie krapie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I'm a bit confused by the word RunAdminCreateUserTest. Does this mean admin can create other user or create itself(admin)? RunAdminSignUpTest makes more sense in terms of creating itself(admin).

Sorry, but I think we should reconsider which word to use. Using the word User may confuse others between admin creating user(not admin), or creating itself(admin).

Any ideas? @hackerwins

server/backend/database/database.go Outdated Show resolved Hide resolved
@krapie
Copy link
Member

krapie commented Jul 23, 2024

Also, I did not get what below comment means:

I wanted the validation of username or password on ChangePassword to be the same as SignUp, but I didn't know how to separate them into a common string, so I added a warning as a comment. If there's a good way to do it, I'd love to hear about it :)

@gusah009
Copy link
Contributor Author

Also, I did not get what below comment means:

I wanted the validation of username or password on ChangePassword to be the same as SignUp, but I didn't know how to separate them into a common string, so I added a warning as a comment. If there's a good way to do it, I'd love to hear about it :)

@krapie
Well, this is not a very important comment because I merged ChangePasswordFields and SignUpFields into UserFields in this PR: #934 (comment)

Anyway, that means, what it means is that I want to refactor the duplicated validation strings like "required,min=2,max=30,slug" or "required,min=8,max=30,alpha_num_special" because signup and changePassword must have the same validation. However, default strings in struct cannot be extracted as constants or anything in golang. That's all.

type SignupFields struct {
	// Username is the name of user.
	Username *string `bson:"username" validate:"required,min=2,max=30,slug"`
	// Password is the password of user.
	Password *string `bson:"password" validate:"required,min=8,max=30,alpha_num_special"`
}

type ChangePasswordFields struct {
	// Username is the name of user.
	Username *string `bson:"username" validate:"required,min=2,max=30,slug"`

	// NewPassword is the new password of user
	NewPassword *string `bson:"new_password" validate:"required,min=8,max=30,alpha_num_special"`
}

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between fe4397a and 94a25ea.

Files selected for processing (2)
  • server/backend/database/database.go (1 hunks)
  • server/backend/database/mongo/client.go (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • server/backend/database/database.go
  • server/backend/database/mongo/client.go

@krapie
Copy link
Member

krapie commented Jul 24, 2024

@gusah009 How about changing the word user to account? If we use the word user in the context of admin, it sounds like the action is for normal user, not admin user. So if we use the word account instead, we can clarify the meaning; that these RPCs performs action on the admin itself. Currently Google is using the word account for their user system.

It will look something like below:

service AdminService {
  rpc LogIn(LogInRequest) returns (LogInResponse) {}
  rpc CreateAccount(CreateAccountRequest) returns (CreateAccountResponse) {}
  rpc DeleteAccount(DeleteAccountRequest) returns (DeleteAccountResponse) {}
  rpc ChangePassword(ChangePasswordRequest) returns (ChangePasswordResponse) {}
}

@gusah009
Copy link
Contributor Author

gusah009 commented Jul 26, 2024

@krapie Oh, that's a good idea. I'll do it right away.

Well, then I'll change the user table with admin to account table and accountName will be more appropriate than username.

@krapie
Copy link
Member

krapie commented Jul 26, 2024

@gusah009 Hmm. I'm not sure about changing username to accountName. I think we can organize like below:

  • Account is an object which contains Username, Password fields.
  • Account parent of Admin and User (Normal User, TBD).

@gusah009
Copy link
Contributor Author

Account parent of Admin and User (Normal User, TBD).

@krapie Looking at it like this, I don’t think I need to change the username. Thank you for your good advice.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 15

Outside diff range, codebase verification and nitpick comments (5)
test/integration/account_test.go (1)

43-49: Ensure consistency by removing deprecated SignUp references

The transition to using CreateAccount is incomplete. There are still several references to the deprecated SignUp method that need to be addressed:

  • server/rpc/admin_server.go: Function definition and comments.
  • server/rpc/interceptors/admin.go: Interceptor checks.
  • api/yorkie/v1/admin.pb.go: Protobuf message types and descriptors.
  • api/yorkie/v1/v1connect/admin.connect.go: RPC handlers and client definitions.

Please update these references to ensure consistency throughout the codebase.

Analysis chain

LGTM! Updating the method calls enhances clarity.

The changes to use CreateAccount instead of SignUp align with the new terminology and improve the readability of the test cases.

However, ensure that all method calls to CreateAccount are consistent throughout the codebase.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all method calls to `CreateAccount` are consistent throughout the codebase.

# Test: Search for the method usage. Expect: Only occurrences of the new method name.
rg --type go -A 5 $'CreateAccount'

Length of output: 25657


Script:

#!/bin/bash
# Description: Verify if there are any remaining calls to the deprecated `SignUp` method in the codebase.

# Test: Search for the deprecated method usage. Expect: No occurrences of the old method name.
rg --type go -A 5 $'SignUp'

Length of output: 16168

server/accounts/accounts.go (1)

Line range hint 55-68: Add validation for username and password.

The function should validate the username and password parameters before proceeding with the password check. This will ensure that the input data meets the required criteria and prevent potential issues with invalid data.

+  if err := validateUsername(username); err != nil {
+    return nil, fmt.Errorf("invalid username: %w", err)
+  }
+  if err := validatePassword(password); err != nil {
+    return nil, fmt.Errorf("invalid password: %w", err)
+  }
server/backend/database/database.go (2)

130-131: Action Required: Update references to FindUserInfoByID in test cases.

The method FindAccountInfoByID has been correctly updated, but some test cases still refer to the old method name FindUserInfoByID. These references need to be updated to ensure consistency and validity of the tests.

  • server/backend/database/testcases/testcases.go
  • server/backend/database/mongo/client_test.go
  • server/backend/database/memory/database_test.go
#!/bin/bash
# Description: Identify all instances of `FindUserInfoByID` in the codebase, focusing on test files.

# Test: Search for the old method name in test files.
rg --type go 'FindUserInfoByID'
Analysis chain

Change Approved: Updated method to FindAccountInfoByID.

The method name and return type changes align with the shift to account-centric terminology.

Verify that all calls to this method have been updated to match the new signature.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `FindAccountInfoByID` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type go -A 5 $'FindAccountInfoByID'

Length of output: 4002


133-137: Outdated Test Function Names: Update Required

The test functions still use the old names RunFindUserInfoByNameTest and RunListUserInfosTest. Please update these test function names to reflect the new method names to maintain consistency.

  • server/backend/database/memory/database_test.go: Update RunFindUserInfoByNameTest to RunFindAccountInfoByNameTest.
  • server/backend/database/memory/database_test.go: Update RunListUserInfosTest to RunListAccountInfosTest.
  • server/backend/database/testcases/testcases.go: Update RunFindUserInfoByNameTest to RunFindAccountInfoByNameTest.
  • server/backend/database/testcases/testcases.go: Update RunListUserInfosTest to RunListAccountInfosTest.
  • server/backend/database/mongo/client_test.go: Update RunFindUserInfoByNameTest to RunFindAccountInfoByNameTest.
  • server/backend/database/mongo/client_test.go: Update RunListUserInfosTest to RunListAccountInfosTest.
  • test/sharding/mongo_client_test.go: Update RunListUserInfosTest to RunListAccountInfosTest.
Analysis chain

Change Approved: Updated methods to FindAccountInfoByName and ListAccountInfos.

The method names and return type changes align with the shift to account-centric terminology.

Verify that all calls to these methods have been updated to match the new signatures.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `FindAccountInfoByName` and `ListAccountInfos` match the new signatures.

# Test: Search for the function usage. Expect: Only occurrences of the new signatures.
rg --type go -A 5 $'FindAccountInfoByName'
rg --type go -A 5 $'ListAccountInfos'

Length of output: 8444

server/backend/database/mongo/client.go (1)

Line range hint 123-154:
Update error message to reflect account-centric model.

The error message "upsert default user info" should be updated to "upsert default account info" for consistency.

	if err != nil {
		return nil, fmt.Errorf("upsert default user info: %w", err)
	}

should be:

	if err != nil {
		return nil, fmt.Errorf("upsert default account info: %w", err)
	}
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 94a25ea and e06f7f9.

Files ignored due to path filters (2)
  • api/yorkie/v1/admin.pb.go is excluded by !**/*.pb.go
  • api/yorkie/v1/resources.pb.go is excluded by !**/*.pb.go
Files selected for processing (36)
  • admin/client.go (1 hunks)
  • api/converter/from_pb.go (1 hunks)
  • api/converter/to_pb.go (1 hunks)
  • api/docs/yorkie/v1/admin.openapi.yaml (12 hunks)
  • api/docs/yorkie/v1/resources.openapi.yaml (2 hunks)
  • api/types/account.go (1 hunks)
  • api/types/account_fields.go (1 hunks)
  • api/types/account_fields_test.go (1 hunks)
  • api/yorkie/v1/admin.proto (5 hunks)
  • api/yorkie/v1/resources.proto (1 hunks)
  • api/yorkie/v1/v1connect/admin.connect.go (9 hunks)
  • cmd/yorkie/login.go (1 hunks)
  • cmd/yorkie/server.go (1 hunks)
  • design/presence.md (2 hunks)
  • pkg/index/tree.go (1 hunks)
  • server/accounts/accounts.go (4 hunks)
  • server/accounts/context.go (1 hunks)
  • server/backend/backend.go (1 hunks)
  • server/backend/database/account_info.go (1 hunks)
  • server/backend/database/client_info.go (1 hunks)
  • server/backend/database/database.go (3 hunks)
  • server/backend/database/memory/database.go (3 hunks)
  • server/backend/database/memory/database_test.go (1 hunks)
  • server/backend/database/memory/indexes.go (2 hunks)
  • server/backend/database/mongo/client.go (5 hunks)
  • server/backend/database/mongo/client_test.go (1 hunks)
  • server/backend/database/mongo/indexes.go (3 hunks)
  • server/backend/database/testcases/testcases.go (2 hunks)
  • server/rpc/admin_server.go (16 hunks)
  • server/rpc/connecthelper/status.go (2 hunks)
  • server/rpc/interceptors/admin.go (6 hunks)
  • server/rpc/server_test.go (1 hunks)
  • server/rpc/testcases/testcases.go (2 hunks)
  • test/helper/helper.go (1 hunks)
  • test/integration/account_test.go (1 hunks)
  • test/sharding/mongo_client_test.go (1 hunks)
Files skipped from review due to trivial changes (6)
  • cmd/yorkie/login.go
  • cmd/yorkie/server.go
  • design/presence.md
  • pkg/index/tree.go
  • server/backend/database/memory/database_test.go
  • test/sharding/mongo_client_test.go
Files skipped from review as they are similar to previous changes (6)
  • admin/client.go
  • api/docs/yorkie/v1/admin.openapi.yaml
  • server/rpc/interceptors/admin.go
  • server/rpc/server_test.go
  • server/rpc/testcases/testcases.go
  • test/helper/helper.go
Additional comments not posted (74)
api/types/account.go (1)

22-23: LGTM! Renaming User to Account is consistent with the new functionality.

The renaming aligns with the broader scope of the struct.

server/accounts/context.go (4)

17-17: LGTM! Changing the package name to accounts aligns with the new functionality.

The package name change is consistent with the shift to account-centric operations.


25-26: LGTM! Renaming userKey to accountKey is consistent with the new functionality.

The renaming aligns with the broader scope of the key type.


29-30: LGTM! Updating the function signature to handle *types.Account is consistent with the new functionality.

The function correctly retrieves an *types.Account from the context.


34-35: LGTM! Updating the function signature to handle *types.Account is consistent with the new functionality.

The function correctly sets an *types.Account into the context.

api/types/account_fields.go (4)

24-25: LGTM! Renaming SignupFields to AccountFields is consistent with the new functionality.

The renaming aligns with the broader scope of the struct.


26-26: LGTM! The updated comment accurately reflects the purpose of the Username field.

The comment is consistent with the new struct name.


29-29: LGTM! The updated comment accurately reflects the purpose of the Password field.

The comment is consistent with the new struct name.


33-34: LGTM! Updating the method to operate on AccountFields is consistent with the new functionality.

The method correctly validates the AccountFields struct.

test/integration/account_test.go (2)

31-31: LGTM! Renaming the test function enhances clarity.

The renaming of TestUser to TestAccount aligns with the new terminology and improves the readability of the test suite.


35-35: LGTM! Renaming the test case enhances clarity.

The renaming of the test case to "account test" aligns with the new terminology and improves the readability of the test suite.

api/types/account_fields_test.go (2)

41-83: LGTM! Updating the struct name enhances clarity.

The changes to use AccountFields instead of SignupFields align with the new terminology and improve the readability of the test cases.


34-34: LGTM! Updating the struct name enhances clarity.

The changes to use AccountFields instead of SignupFields align with the new terminology and improve the readability of the test cases.

However, ensure that all struct usages of AccountFields are consistent throughout the codebase.

Verification successful

Verification successful. The struct AccountFields is used consistently throughout the codebase.

  • server/rpc/admin_server.go
  • api/types/account_fields.go
  • api/types/account_fields_test.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all struct usages of `AccountFields` are consistent throughout the codebase.

# Test: Search for the struct usage. Expect: Only occurrences of the new struct name.
rg --type go -A 5 $'AccountFields'

Length of output: 4824

server/backend/database/account_info.go (4)

33-34: LGTM! Renaming the struct enhances clarity.

The changes to use AccountInfo instead of UserInfo align with the new terminology and improve the readability of the code.


41-43: LGTM! Renaming the function enhances clarity.

The changes to use NewAccountInfo instead of NewUserInfo align with the new terminology and improve the readability of the code.


50-56: LGTM! Updating the function enhances clarity.

The changes to use DeepCopy for AccountInfo instead of UserInfo align with the new terminology and improve the readability of the code.


64-66: LGTM! Renaming the function enhances clarity.

The changes to use ToAccount instead of ToUser align with the new terminology and improve the readability of the code.

However, ensure that all method calls to ToAccount are consistent throughout the codebase.

Verification successful

Method ToAccount usage is consistent across the codebase.

The ToAccount method is used correctly in all relevant places, and the deprecated ToUser method is appropriately marked. No further action is needed.

  • server/accounts/accounts.go
  • server/rpc/admin_server.go
  • api/converter/to_pb.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all method calls to `ToAccount` are consistent throughout the codebase.

# Test: Search for the method usage. Expect: Only occurrences of the new method name.
rg --type go -A 5 $'ToAccount'

Length of output: 2787

server/accounts/accounts.go (1)

86-96: LGTM!

The function GetAccountByID looks good and is correctly implemented.

server/backend/database/mongo/indexes.go (3)

31-32: LGTM!

The constant ColAccounts is correctly renamed and aligns with the new account-centric model.


48-48: LGTM!

The Collections variable is correctly updated to include ColAccounts instead of ColUsers.


80-80: LGTM!

The collectionInfos structure is correctly updated to include ColAccounts instead of ColUsers.

api/yorkie/v1/admin.proto (8)

29-29: Ensure clients are notified about the deprecation of SignUp.

The SignUp RPC is marked as deprecated and will be replaced by CreateAccount. Ensure that clients using this RPC are aware of the deprecation and have a migration path.


31-31: LGTM! The CreateAccount RPC is a good addition.

The introduction of the CreateAccount RPC aligns with the goal of enhancing account management.


33-34: LGTM! The DeleteAccount and ChangeAccountPassword RPCs are essential additions.

The introduction of the DeleteAccount and ChangeAccountPassword RPCs enhances the functionality of the AdminService.


60-63: LGTM! The CreateAccountRequest message is well-defined.

The CreateAccountRequest message includes the necessary fields for account creation.


65-67: LGTM! The CreateAccountResponse message is well-defined.

The CreateAccountResponse message includes the necessary field for the account creation response.


78-81: LGTM! The DeleteAccountRequest message is well-defined.

The DeleteAccountRequest message includes the necessary fields for account deletion.


86-90: LGTM! The ChangeAccountPasswordRequest message is well-defined.

The ChangeAccountPasswordRequest message includes the necessary fields for changing account passwords.


92-93: LGTM! The ChangeAccountPasswordResponse message is appropriate.

The ChangeAccountPasswordResponse message serves as a simple acknowledgment of the password change operation.

server/backend/backend.go (1)

125-125: Verify the existence and implementation of EnsureDefaultAccountAndProject.

The function call is changed from EnsureDefaultUserAndProject to EnsureDefaultAccountAndProject. Ensure that the renamed function exists and is correctly implemented.

Verification successful

The function EnsureDefaultAccountAndProject exists and is implemented correctly.

The function EnsureDefaultAccountAndProject is referenced and implemented in multiple files, including:

  • server/backend/database/mongo/client.go
  • server/backend/database/memory/database.go

The renaming from EnsureDefaultUserAndProject to EnsureDefaultAccountAndProject is consistent with the shift in terminology from "User" to "Account".

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence and implementation of `EnsureDefaultAccountAndProject`.

# Test: Search for the function implementation. Expect: The function should be implemented correctly.
ast-grep --lang go --pattern $'func EnsureDefaultAccountAndProject($_, $_, $_, $_) ($_, $_, $_) {
  $$$
}'

Length of output: 107


Script:

#!/bin/bash
# Description: Verify the existence and implementation of `EnsureDefaultAccountAndProject`.

# Test: Search for the function implementation without specifying parameters.
ast-grep --lang go --pattern $'func EnsureDefaultAccountAndProject($$$) {
  $$$
}'

Length of output: 83


Script:

#!/bin/bash
# Description: Search for references to `EnsureDefaultAccountAndProject` in the codebase.

# Test: Search for any references to the function name.
rg 'EnsureDefaultAccountAndProject'

Length of output: 1203

server/backend/database/memory/indexes.go (1)

23-23: Verify that all references to tblUsers are updated to tblAccounts.

The variable tblUsers is renamed to tblAccounts. Ensure that all references to the old variable name are updated.

Verification successful

All references to tblUsers have been successfully updated to tblAccounts.

The search results confirm that tblAccounts is used consistently across the codebase.

  • server/backend/database/memory/indexes.go
  • server/backend/database/memory/database.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all references to `tblUsers` are updated to `tblAccounts`.

# Test: Search for the old variable name. Expect: No occurrences of `tblUsers`.
rg --type go 'tblUsers'

Length of output: 23


Script:

#!/bin/bash
# Description: Verify that `tblAccounts` is used in place of `tblUsers`.

# Test: Search for the new variable name. Expect: Occurrences of `tblAccounts`.
rg --type go 'tblAccounts'

Length of output: 1309

server/backend/database/client_info.go (1)

70-70: Comment update approved.

The change in the comment for the Key field from "users" to "accounts" aligns with the updated terminology.

server/rpc/connecthelper/status.go (4)

56-56: Addition of database.ErrAccountNotFound approved.

The addition of database.ErrAccountNotFound to the errorToConnectCode map with a connect.CodeNotFound status is consistent with the updated terminology.


61-61: Addition of database.ErrAccountAlreadyExists approved.

The addition of database.ErrAccountAlreadyExists to the errorToConnectCode map with a connect.CodeAlreadyExists status is consistent with the updated terminology.


107-107: Addition of database.ErrAccountNotFound approved.

The addition of database.ErrAccountNotFound to the errorToCode map with a string representation of "ErrAccountNotFound" is consistent with the updated terminology.


111-111: Addition of database.ErrAccountAlreadyExists approved.

The addition of database.ErrAccountAlreadyExists to the errorToCode map with a string representation of "ErrAccountAlreadyExists" is consistent with the updated terminology.

api/yorkie/v1/resources.proto (2)

274-274: Deprecation comment for User approved.

The deprecation comment for the User message is clear and indicates the transition to the Account message.


281-285: New Account message definition approved.

The Account message mirrors the structure of the deprecated User message and aligns with the updated terminology.

server/backend/database/database.go (6)

35-36: Change Approved: Updated error message to ErrAccountNotFound.

The change aligns with the shift from user-centric to account-centric terminology.


41-42: Change Approved: Updated error message to ErrAccountAlreadyExists.

The change aligns with the shift from user-centric to account-centric terminology.


117-122: Change Approved: Updated method to CreateAccountInfo.

The method name and return type changes align with the shift to account-centric terminology.

Verify that all calls to this method have been updated to match the new signature.

Verification successful

Change Approved: Updated method to CreateAccountInfo.

The method name and return type changes align with the shift to account-centric terminology. All instances of CreateAccountInfo in the codebase have been updated to match the new signature.

  • server/accounts/accounts.go
  • server/backend/database/testcases/testcases.go
  • server/backend/database/mongo/client.go
  • server/backend/database/memory/database.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `CreateAccountInfo` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type go -A 5 $'CreateAccountInfo'

Length of output: 2581


124-125: Change Approved: Introduced method DeleteAccountInfoByName.

The method aligns with the new account management functionalities.

Verify that the method is used correctly in the codebase.

Verification successful

Change Approved: Introduced method DeleteAccountInfoByName.

The method aligns with the new account management functionalities and is used correctly and consistently across the codebase.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `DeleteAccountInfoByName` in the codebase.

# Test: Search for the method usage. Expect: Correct and consistent usage.
rg --type go -A 5 $'DeleteAccountInfoByName'

Length of output: 2011


127-128: Change Approved: Introduced method ChangeAccountPassword.

The method aligns with the new account management functionalities.

Verify that the method is used correctly in the codebase.

Verification successful

Change Approved: Introduced method ChangeAccountPassword.

The method aligns with the new account management functionalities and is consistently used across the codebase.

  • server/rpc/testcases/testcases.go
  • server/rpc/interceptors/admin.go
  • server/accounts/accounts.go
  • server/rpc/admin_server.go
  • server/backend/database/database.go
  • server/backend/database/memory/database.go
  • server/backend/database/mongo/client.go
  • api/yorkie/v1/admin.pb.go
  • api/yorkie/v1/v1connect/admin.connect.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `ChangeAccountPassword` in the codebase.

# Test: Search for the method usage. Expect: Correct and consistent usage.
rg --type go -A 5 $'ChangeAccountPassword'

Length of output: 21116


89-96: Change Approved: Updated method to EnsureDefaultAccountAndProject.

The method name and return type changes align with the shift to account-centric terminology.

Verify that all calls to this method have been updated to match the new signature.

server/rpc/admin_server.go (4)

53-73: Deprecation Notice Approved: SignUp method.

The SignUp method is deprecated and will be replaced by CreateAccount. The notice is clear, and the method remains functional.


143-169: Change Approved: Introduced method ChangeAccountPassword.

The method validates the new password fields and calls accounts.ChangeAccountPassword. Ensure the validation and password change logic are correct.

Verify that the method is used correctly in the codebase.

Verification successful

Change Approved: Introduced method ChangeAccountPassword.

The method validates the new password fields and calls accounts.ChangeAccountPassword. The method is used correctly and consistently in the codebase.

  • Verified usage in server/rpc/admin_server.go, server/rpc/server_test.go, server/rpc/testcases/testcases.go, server/rpc/interceptors/admin.go, server/accounts/accounts.go, server/backend/database/database.go, server/backend/database/memory/database.go, server/backend/database/mongo/client.go, api/yorkie/v1/admin.pb.go, and api/yorkie/v1/v1connect/admin.connect.go.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `ChangeAccountPassword` in the codebase.

# Test: Search for the method usage. Expect: Correct and consistent usage.
rg --type go -A 5 $'ChangeAccountPassword'

Length of output: 21116


120-141: Change Approved: Introduced method DeleteAccount.

The method validates the user's password and calls accounts.DeleteAccountByName. Ensure the validation and account deletion logic are correct.

Verify that the method is used correctly in the codebase.

Verification successful

Verification Successful: Method DeleteAccount is used correctly in the codebase.

The method DeleteAccount is properly implemented and tested across various files:

  • server/rpc/testcases/testcases.go
  • server/rpc/server_test.go
  • api/yorkie/v1/v1connect/admin.connect.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `DeleteAccount` in the codebase.

# Test: Search for the method usage. Expect: Correct and consistent usage.
rg --type go -A 5 $'DeleteAccount'

Length of output: 20237


75-91: Change Approved: Introduced method CreateAccount.

The method validates account fields and calls accounts.CreateAccount. Ensure the validation and account creation logic are correct.

Verify that the method is used correctly in the codebase.

Verification successful

Change Approved: Introduced method CreateAccount.

The method validates account fields and calls accounts.CreateAccount. The usage of the CreateAccount method is consistent and correct across the codebase.

  • Verified in test/integration/account_test.go
  • Verified in server/rpc/admin_server.go
  • Verified in server/rpc/testcases/testcases.go
  • Verified in api/yorkie/v1/v1connect/admin.connect.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `CreateAccount` in the codebase.

# Test: Search for the method usage. Expect: Correct and consistent usage.
rg --type go -A 5 $'CreateAccount'

Length of output: 25657

api/converter/to_pb.go (2)

36-43: Deprecation Notice Approved: ToUser function.

The ToUser function is deprecated and will be replaced by ToAccount. The notice is clear, and the function remains functional.


45-50: Change Approved: Introduced function ToAccount.

The function converts a *types.Account to an api.Account, mirroring the implementation of the deprecated ToUser function.

Verify that the function is used correctly in the codebase.

Verification successful

Change Approved: Introduced function ToAccount.

The function converts a *types.Account to an api.Account, mirroring the implementation of the deprecated ToUser function. The function is used correctly in the codebase.

  • server/accounts/accounts.go: Used to return the result of ToAccount().
  • server/rpc/admin_server.go: Used to assign the result to a field in a struct.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `ToAccount` in the codebase.

# Test: Search for the function usage. Expect: Correct and consistent usage.
rg --type go -A 5 $'ToAccount'

Length of output: 2787

api/converter/from_pb.go (1)

32-37: LGTM!

The function FromAccount correctly maps fields from the Protobuf Account message to the types.Account model.

api/yorkie/v1/v1connect/admin.connect.go (6)

53-55: LGTM!

The AdminServiceCreateAccountProcedure is correctly defined and consistent with other procedure names.


58-60: LGTM!

The AdminServiceDeleteAccountProcedure is correctly defined and consistent with other procedure names.


61-63: LGTM!

The AdminServiceChangeAccountPasswordProcedure is correctly defined and consistent with other procedure names.


100-105: LGTM!

The methods CreateAccount, DeleteAccount, and ChangeAccountPassword are correctly defined and consistent with other methods in the AdminServiceClient interface.


134-153: LGTM!

The fields for createAccount, deleteAccount, and changeAccountPassword RPC methods are correctly defined and consistent with other fields in the adminServiceClient struct.


314-319: LGTM!

The methods CreateAccount, DeleteAccount, and ChangeAccountPassword are correctly defined and consistent with other methods in the AdminServiceHandler interface.

server/backend/database/memory/database.go (8)

Line range hint 134-144: LGTM!

The function EnsureDefaultAccountAndProject correctly reflects the shift from user management to account management, and the return types are correctly updated.


159-180: LGTM!

The function ensureDefaultAccountInfo correctly reflects the shift from user management to account management, and the database table is correctly updated.


405-425: LGTM!

The function DeleteAccountInfoByName correctly handles the deletion of an account by name, and error handling is properly implemented.


427-449: LGTM!

The function ChangeAccountPassword correctly handles the password change, and error handling is properly implemented.


378-397: LGTM!

The function CreateAccountInfo correctly reflects the shift from user management to account management.


451-464: LGTM!

The function FindAccountInfoByID correctly reflects the shift from user management to account management.


467-480: LGTM!

The function FindAccountInfoByName correctly reflects the shift from user management to account management.


483-499: LGTM!

The function ListAccountInfos correctly reflects the shift from user management to account management.

server/backend/database/testcases/testcases.go (7)

172-172: LGTM!

The change from EnsureDefaultUserAndProject to EnsureDefaultAccountAndProject is consistent with the new terminology.


371-385: LGTM!

The changes from RunListUserInfosTest to RunListAccountInfosTest and the renaming of user-related terms to account-related terms are consistent with the new terminology.


392-403: LGTM!

The changes from RunFindUserInfoByIDTest to RunFindAccountInfoByIDTest and the renaming of user-related terms to account-related terms are consistent with the new terminology.


410-421: LGTM!

The changes from RunFindUserInfoByNameTest to RunFindAccountInfoByNameTest and the renaming of user-related terms to account-related terms are consistent with the new terminology.


371-385: LGTM!

The changes from RunListUserInfosTest to RunListAccountInfosTest and the renaming of user-related terms to account-related terms are consistent with the new terminology.


392-403: LGTM!

The changes from RunFindUserInfoByIDTest to RunFindAccountInfoByIDTest and the renaming of user-related terms to account-related terms are consistent with the new terminology.


410-421: LGTM!

The changes from RunFindUserInfoByNameTest to RunFindAccountInfoByNameTest and the renaming of user-related terms to account-related terms are consistent with the new terminology.

api/docs/yorkie/v1/resources.openapi.yaml (2)

161-181: LGTM!

The addition of the yorkie.v1.Account schema with properties createdAt, id, and username is well-defined and aligns with the new terminology.


1687-1687: LGTM!

The deprecation of the yorkie.v1.User schema is consistent with the shift to the new Account schema.

api/types/account.go Outdated Show resolved Hide resolved
server/accounts/accounts.go Outdated Show resolved Hide resolved
server/accounts/accounts.go Outdated Show resolved Hide resolved
server/accounts/accounts.go Outdated Show resolved Hide resolved
server/accounts/accounts.go Outdated Show resolved Hide resolved
server/backend/database/mongo/client_test.go Outdated Show resolved Hide resolved
server/backend/database/mongo/client_test.go Outdated Show resolved Hide resolved
server/backend/database/mongo/client_test.go Outdated Show resolved Hide resolved
@gusah009 gusah009 force-pushed the support-basic-account-action-for-admin branch from e06f7f9 to acaf851 Compare July 27, 2024 01:15
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

Outside diff range, codebase verification and nitpick comments (1)
server/backend/database/mongo/client.go (1)

Line range hint 123-155: Rename info to accountInfo and update error message.

The variable info should be renamed to accountInfo to align with the new account-centric model. The error message should be updated to reflect the account-centric model.

-	info := database.AccountInfo{}
-	if err := result.Decode(&info); err != nil {
+	accountInfo := database.AccountInfo{}
+	if err := result.Decode(&accountInfo); err != nil {
		if err == mongo.ErrNoDocuments {
-			return nil, fmt.Errorf("default: %w", database.ErrAccountNotFound)
+			return nil, fmt.Errorf("default account: %w", database.ErrAccountNotFound)
		}
-		return nil, fmt.Errorf("decode user info: %w", err)
+		return nil, fmt.Errorf("decode account info: %w", err)
	}

-	return &info, nil
+	return &accountInfo, nil
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e06f7f9 and acaf851.

Files ignored due to path filters (2)
  • api/yorkie/v1/admin.pb.go is excluded by !**/*.pb.go
  • api/yorkie/v1/resources.pb.go is excluded by !**/*.pb.go
Files selected for processing (39)
  • admin/client.go (1 hunks)
  • api/converter/from_pb.go (1 hunks)
  • api/converter/to_pb.go (1 hunks)
  • api/docs/yorkie/v1/admin.openapi.yaml (12 hunks)
  • api/docs/yorkie/v1/resources.openapi.yaml (2 hunks)
  • api/types/account.go (1 hunks)
  • api/types/account_fields.go (1 hunks)
  • api/types/account_fields_test.go (1 hunks)
  • api/yorkie/v1/admin.proto (5 hunks)
  • api/yorkie/v1/resources.proto (1 hunks)
  • api/yorkie/v1/v1connect/admin.connect.go (9 hunks)
  • cmd/yorkie/login.go (1 hunks)
  • cmd/yorkie/server.go (2 hunks)
  • design/presence.md (2 hunks)
  • pkg/index/tree.go (1 hunks)
  • server/accounts/accounts.go (4 hunks)
  • server/accounts/context.go (1 hunks)
  • server/backend/backend.go (1 hunks)
  • server/backend/config.go (1 hunks)
  • server/backend/database/account_info.go (1 hunks)
  • server/backend/database/client_info.go (1 hunks)
  • server/backend/database/database.go (3 hunks)
  • server/backend/database/memory/database.go (3 hunks)
  • server/backend/database/memory/database_test.go (1 hunks)
  • server/backend/database/memory/indexes.go (2 hunks)
  • server/backend/database/mongo/client.go (5 hunks)
  • server/backend/database/mongo/client_test.go (1 hunks)
  • server/backend/database/mongo/indexes.go (3 hunks)
  • server/backend/database/testcases/testcases.go (2 hunks)
  • server/config.go (2 hunks)
  • server/rpc/admin_server.go (16 hunks)
  • server/rpc/connecthelper/status.go (2 hunks)
  • server/rpc/interceptors/admin.go (6 hunks)
  • server/rpc/server_test.go (2 hunks)
  • server/rpc/testcases/testcases.go (10 hunks)
  • test/helper/helper.go (3 hunks)
  • test/integration/account_test.go (1 hunks)
  • test/sharding/mongo_client_test.go (1 hunks)
  • test/sharding/server_test.go (2 hunks)
Files skipped from review due to trivial changes (4)
  • design/presence.md
  • server/backend/config.go
  • server/backend/database/client_info.go
  • server/config.go
Files skipped from review as they are similar to previous changes (25)
  • admin/client.go
  • api/docs/yorkie/v1/admin.openapi.yaml
  • api/docs/yorkie/v1/resources.openapi.yaml
  • api/types/account.go
  • api/types/account_fields.go
  • api/types/account_fields_test.go
  • api/yorkie/v1/resources.proto
  • api/yorkie/v1/v1connect/admin.connect.go
  • cmd/yorkie/login.go
  • cmd/yorkie/server.go
  • pkg/index/tree.go
  • server/accounts/accounts.go
  • server/backend/backend.go
  • server/backend/database/account_info.go
  • server/backend/database/database.go
  • server/backend/database/memory/database_test.go
  • server/backend/database/memory/indexes.go
  • server/rpc/admin_server.go
  • server/rpc/connecthelper/status.go
  • server/rpc/server_test.go
  • server/rpc/testcases/testcases.go
  • test/helper/helper.go
  • test/integration/account_test.go
  • test/sharding/mongo_client_test.go
  • test/sharding/server_test.go
Additional comments not posted (36)
server/accounts/context.go (3)

17-17: LGTM!

The package name change from users to accounts aligns with the new account-centric model.


25-26: LGTM!

The type name change from userKey to accountKey aligns with the new account-centric model.


29-35: LGTM!

The function signature changes from handling *types.User to *types.Account are consistent with the new account-centric model. The context handling appears correct.

server/backend/database/mongo/client_test.go (3)

83-85: LGTM!

The test case name change from ListUserInfos to ListAccountInfos aligns with the new account-centric model.


88-89: LGTM!

The test case name change from FindUserInfoByID to FindAccountInfoByID aligns with the new account-centric model.


92-92: Update the test function name for consistency.

The test function name should be updated to reflect the new account-centric model.

-    testcases.RunFindUserInfoByNameTest(t, cli)
+    testcases.RunFindAccountInfoByNameTest(t, cli)

Likely invalid or redundant comment.

server/backend/database/mongo/indexes.go (3)

31-32: LGTM!

The collection name change from ColUsers to ColAccounts aligns with the new account-centric model.


48-48: LGTM!

The update to replace ColUsers with ColAccounts in the Collections variable aligns with the new account-centric model.


Line range hint 80-85:
LGTM!

The update to replace ColUsers with ColAccounts in the collectionInfos structure aligns with the new account-centric model.

api/yorkie/v1/admin.proto (5)

29-31: LGTM! Deprecation and replacement of SignUp RPC.

The SignUp RPC is correctly marked as deprecated and replaced by the CreateAccount RPC.


33-34: LGTM! Addition of DeleteAccount and ChangeAccountPassword RPCs.

The new RPCs for DeleteAccount and ChangeAccountPassword are correctly defined.


60-63: LGTM! Addition of CreateAccountRequest message.

The CreateAccountRequest message is correctly defined with username and password fields.


78-81: LGTM! Addition of DeleteAccountRequest message.

The DeleteAccountRequest message is correctly defined with username and password fields.


86-90: LGTM! Addition of ChangeAccountPasswordRequest message.

The ChangeAccountPasswordRequest message is correctly defined with username, current_password, and new_password fields.

server/rpc/interceptors/admin.go (4)

167-167: LGTM! Updated context management in buildContext.

The context management is correctly updated to use accounts instead of users.


Line range hint 179-201:
LGTM! Updated authenticate function to use accounts.

The authenticate function is correctly updated to use accounts instead of users.


201-204: LGTM! Updated authenticate function to use accounts for project owner.

The authenticate function is correctly updated to use accounts instead of users for the project owner.


45-48: Verify the security implications of the updated isRequiredAuth function.

The updated isRequiredAuth function now includes additional methods that do not require authentication. Ensure this change does not introduce security vulnerabilities.

api/converter/to_pb.go (2)

36-43: LGTM! Deprecation and update of ToUser function.

The ToUser function is correctly deprecated and updated to use account instead of user.


45-50: LGTM! Addition of ToAccount function.

The ToAccount function is correctly defined to convert a *types.Account to an api.Account.

api/converter/from_pb.go (1)

32-37: LGTM!

The function correctly converts the Protobuf Account object to the types.Account object. The changes reflect the shift from user-centric to account-centric data handling.

server/backend/database/memory/database.go (9)

134-140: LGTM!

The function correctly ensures the creation of default account and project. The changes reflect the shift from user-centric to account-centric data handling.


159-180: LGTM!

The function correctly ensures the creation of the default account. The changes reflect the shift from user-centric to account-centric data handling.


378-397: LGTM!

The function correctly creates a new account. The changes reflect the shift from user-centric to account-centric data handling.


405-425: LGTM!

The function correctly deletes an account by name. It follows a similar transaction pattern as the previous user functions.


427-448: LGTM!

The function correctly changes the password for an account. It follows a similar transaction pattern as the previous user functions.


451-464: LGTM!

The function correctly finds an account by the given ID. The changes reflect the shift from user-centric to account-centric data handling.


467-480: LGTM!

The function correctly finds an account by the given username. The changes reflect the shift from user-centric to account-centric data handling.


483-499: LGTM!

The function correctly lists all accounts. The changes reflect the shift from user-centric to account-centric data handling.


134-140: LGTM!

The function correctly ensures the creation of default account and project. The changes reflect the shift from user-centric to account-centric data handling.

server/backend/database/mongo/client.go (2)

Line range hint 504-549: LGTM!

The function ActivateClient is correctly implemented and does not require any changes.


Line range hint 550-606: LGTM!

The function DeactivateClient is correctly implemented and does not require any changes.

server/backend/database/testcases/testcases.go (4)

392-403: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to RunFindAccountInfoByIDTest match the new signature.

Verification successful

Verified: All function calls to RunFindAccountInfoByIDTest match the new signature.

The function RunFindAccountInfoByIDTest is correctly used in the codebase with the updated signature.

  • server/backend/database/mongo/client_test.go
  • server/backend/database/memory/database_test.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `RunFindAccountInfoByIDTest` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type go -A 5 $'RunFindAccountInfoByIDTest'

Length of output: 1571


172-172: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to EnsureDefaultAccountAndProject match the new signature.

Verification successful

Verification successful: Function usage matches the new signature.

The function EnsureDefaultAccountAndProject is consistently used with the new signature across the codebase.

  • server/backend/backend.go
  • server/backend/database/database.go
  • server/backend/database/memory/database.go
  • server/backend/database/mongo/client.go
  • server/backend/database/testcases/testcases.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `EnsureDefaultAccountAndProject` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type go -A 5 $'EnsureDefaultAccountAndProject'

Length of output: 3580


410-421: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to RunFindAccountInfoByNameTest match the new signature.


371-385: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to RunListAccountInfosTest match the new signature.

Verification successful

Function usage verified successfully.

All instances of RunListAccountInfosTest match the new function signature and are used correctly.

  • test/sharding/mongo_client_test.go
  • server/backend/database/memory/database_test.go
  • server/backend/database/mongo/client_test.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `RunListAccountInfosTest` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type go -A 5 $'RunListAccountInfosTest'

Length of output: 1899


Script:

#!/bin/bash
# Verify the function calls to `RunListAccountInfosTest` in the listed files.

# Check `test/sharding/mongo_client_test.go`
rg --type go -A 5 -B 5 'RunListAccountInfosTest' test/sharding/mongo_client_test.go

# Check `server/backend/database/memory/database_test.go`
rg --type go -A 5 -B 5 'RunListAccountInfosTest' server/backend/database/memory/database_test.go

# Check `server/backend/database/mongo/client_test.go`
rg --type go -A 5 -B 5 'RunListAccountInfosTest' server/backend/database/mongo/client_test.go

Length of output: 1288

server/backend/database/mongo/client.go Outdated Show resolved Hide resolved
server/backend/database/mongo/client.go Outdated Show resolved Hide resolved
server/backend/database/mongo/client.go Outdated Show resolved Hide resolved
server/backend/database/mongo/client.go Outdated Show resolved Hide resolved
server/backend/database/mongo/client.go Outdated Show resolved Hide resolved
server/backend/database/mongo/client.go Outdated Show resolved Hide resolved
server/backend/database/mongo/client.go Outdated Show resolved Hide resolved
@gusah009 gusah009 force-pushed the support-basic-account-action-for-admin branch from acaf851 to 9ab1142 Compare July 27, 2024 04:32
@krapie
Copy link
Member

krapie commented Jul 27, 2024

After discussing with @gusah009, we have concluded what we revert our changes to use RPC name as DeleteAccount and ChangePassword. This is because the scope of changing keyword User to Account takes more resources and changes that we thought. Considering our scope of this PR of just adding new actions for admin, it will be better to keep our changes small as possible.

I apologize for the frequent change request to @gusah009. Thank you for your understanding.
Next time we will decide our design prior to implementation.

@gusah009 gusah009 force-pushed the support-basic-account-action-for-admin branch from 9ab1142 to ddfdff5 Compare July 27, 2024 04:49
@krapie krapie self-requested a review July 27, 2024 04:49
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between acaf851 and ddfdff5.

Files ignored due to path filters (1)
  • api/yorkie/v1/admin.pb.go is excluded by !**/*.pb.go
Files selected for processing (16)
  • api/docs/yorkie/v1/admin.openapi.yaml (54 hunks)
  • api/docs/yorkie/v1/resources.openapi.yaml (64 hunks)
  • api/docs/yorkie/v1/yorkie.openapi.yaml (49 hunks)
  • api/types/user_fields.go (1 hunks)
  • api/types/user_fields_test.go (1 hunks)
  • api/yorkie/v1/admin.proto (2 hunks)
  • api/yorkie/v1/v1connect/admin.connect.go (9 hunks)
  • server/backend/database/database.go (1 hunks)
  • server/backend/database/memory/database.go (1 hunks)
  • server/backend/database/mongo/client.go (1 hunks)
  • server/rpc/admin_server.go (2 hunks)
  • server/rpc/interceptors/admin.go (1 hunks)
  • server/rpc/server_test.go (1 hunks)
  • server/rpc/testcases/testcases.go (2 hunks)
  • server/users/users.go (1 hunks)
  • test/helper/helper.go (1 hunks)
Files skipped from review due to trivial changes (2)
  • api/docs/yorkie/v1/resources.openapi.yaml
  • api/docs/yorkie/v1/yorkie.openapi.yaml
Files skipped from review as they are similar to previous changes (12)
  • api/docs/yorkie/v1/admin.openapi.yaml
  • api/types/user_fields.go
  • api/types/user_fields_test.go
  • api/yorkie/v1/admin.proto
  • api/yorkie/v1/v1connect/admin.connect.go
  • server/backend/database/database.go
  • server/backend/database/memory/database.go
  • server/backend/database/mongo/client.go
  • server/rpc/server_test.go
  • server/rpc/testcases/testcases.go
  • server/users/users.go
  • test/helper/helper.go
Additional comments not posted (5)
server/rpc/interceptors/admin.go (3)

45-47: Security Risk: Review the decision to bypass authentication for additional methods.

Adding ChangePassword and DeleteAccount to the list of methods that do not require authentication could pose a security risk. Ensure that this decision is intentional and consider the potential implications.


Line range hint 66-66:
LGTM! Consistent with the shift to account-centric handling.

The change from users.With to accounts.With aligns with the transition to account-centric handling.


Line range hint 79-79:
LGTM! Consistent with the shift to account-centric handling.

The changes from users.GetUserByName to accounts.GetAccountByName and users.GetUserByID to accounts.GetAccountByID align with the transition to account-centric handling.

Also applies to: 85-85, 92-92

server/rpc/admin_server.go (2)

98-119: Enhance error handling and logging.

Consider adding more specific error messages and logging for better traceability.

func (s *adminServer) DeleteAccount(
	ctx context.Context,
	req *connect.Request[api.DeleteAccountRequest],
) (*connect.Response[api.DeleteAccountResponse], error) {
	user, err := users.IsCorrectPassword(
		ctx,
		s.backend,
		req.Msg.Username,
		req.Msg.Password,
	)
	if err != nil {
		logging.DefaultLogger().Errorf("Failed to validate password for user: %s, error: %v", req.Msg.Username, err)
		return nil, fmt.Errorf("failed to validate password for user %s: %w", req.Msg.Username, err)
	}

	err = users.DeleteAccountByName(ctx, s.backend, user.Username)
	if err != nil {
		logging.DefaultLogger().Errorf("Failed to delete account for user: %s, error: %v", user.Username, err)
		return nil, fmt.Errorf("failed to delete account for user %s: %w", user.Username, err)
	}

	logging.DefaultLogger().Infof("Account deleted for user: %s", user.Username)
	return connect.NewResponse(&api.DeleteAccountResponse{}), nil
}

121-147: Enhance error handling and logging.

Consider adding more specific error messages and logging for better traceability.

func (s *adminServer) ChangePassword(
	ctx context.Context,
	req *connect.Request[api.ChangePasswordRequest],
) (*connect.Response[api.ChangePasswordResponse], error) {
	fields := &types.UserFields{Username: &req.Msg.Username, Password: &req.Msg.NewPassword}
	if err := fields.Validate(); err != nil {
		logging.DefaultLogger().Errorf("Failed to validate new password for user: %s, error: %v", req.Msg.Username, err)
		return nil, fmt.Errorf("failed to validate new password for user %s: %w", req.Msg.Username, err)
	}

	user, err := users.IsCorrectPassword(
		ctx,
		s.backend,
		req.Msg.Username,
		req.Msg.CurrentPassword,
	)
	if err != nil {
		logging.DefaultLogger().Errorf("Failed to validate current password for user: %s, error: %v", req.Msg.Username, err)
		return nil, fmt.Errorf("failed to validate current password for user %s: %w", req.Msg.Username, err)
	}

	err = users.ChangePassword(ctx, s.backend, user.Username, req.Msg.NewPassword)
	if err != nil {
		logging.DefaultLogger().Errorf("Failed to change password for user: %s, error: %v", user.Username, err)
		return nil, fmt.Errorf("failed to change password for user %s: %w", user.Username, err)
	}

	logging.DefaultLogger().Infof("Password changed for user: %s", user.Username)
	return connect.NewResponse(&api.ChangePasswordResponse{}), nil
}

@gusah009 gusah009 force-pushed the support-basic-account-action-for-admin branch from ca0dc39 to 7022723 Compare July 27, 2024 04:59
Copy link
Member

@krapie krapie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍🏼

Copy link

codecov bot commented Jul 27, 2024

Codecov Report

Attention: Patch coverage is 28.42105% with 68 lines in your changes missing coverage. Please review.

Project coverage is 51.31%. Comparing base (bcb246b) to head (7022723).

Files Patch % Lines
server/backend/database/memory/database.go 0.00% 36 Missing ⚠️
server/backend/database/mongo/client.go 0.00% 23 Missing ⚠️
server/rpc/admin_server.go 74.28% 6 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #934      +/-   ##
==========================================
- Coverage   51.53%   51.31%   -0.22%     
==========================================
  Files          71       71              
  Lines       10586    10679      +93     
==========================================
+ Hits         5455     5480      +25     
- Misses       4585     4650      +65     
- Partials      546      549       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@krapie krapie merged commit 52d2732 into yorkie-team:main Jul 27, 2024
4 checks passed
@krapie
Copy link
Member

krapie commented Jul 27, 2024

@hackerwins We did not consider cascading delete on user related objects including projects and documents. I think we need to also consider to also delete related resources.

@hackerwins
Copy link
Member

@krapie Please create an issue regarding this. 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 🌟 New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Support Basic Account Action for Admin
4 participants