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

Add Account Deletion and Change Password to CLI #983

Merged
merged 15 commits into from
Sep 3, 2024

Conversation

sigmaith
Copy link
Contributor

@sigmaith sigmaith commented Aug 27, 2024

What this PR does / why we need it:
Added functionality allowing users to delete accounts, change passwords, etc., through the CLI. Additionally, grouped related commands such as login, logout, account deletion, and password change under the same user folder for better organization.

Which issue(s) this PR fixes:
fixes #982

Special notes for your reviewer:
I've been trying to do all the security implementations. If I've missed anything, please let me know. Plus, I'm wondering where the printout code is in the code for the terminal. I'm thinking about using the golang.org/x/crypto/ssh/terminal package to cover it up when a user enters a password. (checked)

Replaced the deprecated golang.org/x/crypto/ssh/terminal with golang.org/x/term to securely handle password input in the terminal.

Does this PR introduce a user-facing change?:

Users need to start with yorkie user ~ when they want to perform actions like login, logout, account deletion, and password change via the CLI.

Additional documentation:
example)

image (1) image (2)

Checklist:

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

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced methods for users to delete their accounts and change their passwords directly through the application.
    • Added command-line interface (CLI) commands for changing passwords and deleting accounts, enhancing user management capabilities.
    • Implemented a structured command framework for managing user accounts, improving organization and usability.
  • Bug Fixes

    • Improved error handling during account management processes to enhance user experience.

These changes empower users with greater control over their accounts while ensuring secure and intentional actions are taken.

@CLAassistant
Copy link

CLAassistant commented Aug 27, 2024

CLA assistant check
All committers have signed the CLA.

Copy link

coderabbitai bot commented Aug 27, 2024

Walkthrough

The changes introduce two new methods, DeleteAccount and ChangePassword, to the Client struct for user account management in the admin/client.go file. Additionally, new CLI commands for changing passwords and deleting accounts are added in the cmd/yorkie/user package, allowing users to manage their accounts securely via command line with necessary confirmations.

Changes

Files Change Summary
admin/client.go Added DeleteAccount and ChangePassword methods to Client struct for account management.
cmd/yorkie/user/change-password.go Added changePasswordCmd for changing user passwords via CLI.
cmd/yorkie/user/delete-account.go Introduced deleteAccountCmd for user account deletion via CLI, including confirmation steps.
cmd/yorkie/user/login.go Changed package declaration from main to user and modified command registration structure.
cmd/yorkie/user/user.go Defined SubCmd for managing user accounts in the CLI.
go.mod Added direct requirement for gopkg.in/yaml.v3 and removed its indirect requirement.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant Client
    participant Server

    User->>CLI: invoke change password
    CLI->>Client: ChangePassword(username, currentPassword, newPassword)
    Client->>Server: request password change
    Server-->>Client: success
    Client-->>CLI: confirmation of change
    CLI-->>User: display success message

    User->>CLI: invoke delete account
    CLI->>Client: DeleteAccount(username, password)
    Client->>Server: request account deletion
    Server-->>Client: success
    Client-->>CLI: confirmation of deletion
    CLI-->>User: display success message
Loading

🐇 In the meadow, hopping around,
A new command for accounts is found.
With a simple prompt, your wish is clear,
Deletion confirmed, no need to fear.
Changes are here, so let’s give a cheer! 🎉

Assessment against linked issues

Objective Addressed Explanation
Integrate with the newly developed server APIs: ChangePassword and DeleteAccount (#[982])
Implement proper error handling and user feedback (#[982])
Ensure secure handling of sensitive information (passwords) (#[982])
Update CLI documentation to reflect these new commands (#[982]) Documentation update is not included in the changes.
For the delete account command, consider implementing a confirmation step (#[982])

Tip

We have updated our review workflow to use the Anthropic's Claude family of models. Please share any feedback in the discussion post on our Discord.


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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

coderabbitai[bot]

This comment was marked as resolved.

@krapie krapie assigned krapie and sigmaith and unassigned krapie Aug 27, 2024
@krapie krapie self-requested a review August 27, 2024 10:07
@krapie krapie added the enhancement 🌟 New feature or request label Aug 27, 2024
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.

Overall, your code looks good. How about referring to our other CLI command codes for the code consistency?

Also, I think you need to lint the code, it is not passing our CI lint.
You can lint your code by make lint command in your CLI.

For your question:

I'm wondering where the printout code is in the code for the terminal. I'm thinking about using the 'golang.org/x/crypto/ssh/terminal' package to cover it up when a user enters a password.

We are using Cobra CLI library for our CLI implementation.
And there will be confirmation prompt feature in Cobra CLI library. Could you check their repository for more information?

Also, I think we need to refactor our user-related files to new user folder in the cmd command later. This may change CLI to yorkie user .... How about this approach?

cc. @hackerwins

admin/client.go Outdated Show resolved Hide resolved
admin/client.go Show resolved Hide resolved
cmd/yorkie/signout.go Outdated Show resolved Hide resolved
cmd/yorkie/signout.go Outdated Show resolved Hide resolved
cmd/yorkie/signout.go Outdated Show resolved Hide resolved
cmd/yorkie/signout.go Outdated Show resolved Hide resolved
cmd/yorkie/signout.go Outdated Show resolved Hide resolved
coderabbitai[bot]

This comment was marked as resolved.

@sigmaith sigmaith marked this pull request as draft August 28, 2024 09:47
@sigmaith sigmaith requested a review from krapie August 29, 2024 07:21
@sigmaith sigmaith changed the title Add Account Deletion to CLI Commands Add Account Deletion and Change Password to CLI Commands Aug 29, 2024
Copy link

codecov bot commented Aug 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 51.07%. Comparing base (3f4f5d3) to head (7cad611).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #983   +/-   ##
=======================================
  Coverage   51.06%   51.07%           
=======================================
  Files          73       73           
  Lines       10782    10784    +2     
=======================================
+ Hits         5506     5508    +2     
  Misses       4725     4725           
  Partials      551      551           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@chacha912 chacha912 marked this pull request as ready for review August 29, 2024 09:09
coderabbitai[bot]

This comment was marked as resolved.

@sigmaith sigmaith marked this pull request as draft August 29, 2024 10:17
@krapie

This comment was marked as resolved.

@sigmaith sigmaith marked this pull request as ready for review August 30, 2024 05:25
coderabbitai[bot]

This comment was marked as 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.

Below are just my thoughts related to CLIs.

1. Using go prompt library for prompting.

Current prompting method looks somewhat raw. If we use go prompt library like go-prompt or promptui, it will make our CLI prompt more interactive.

2. Considering refactor of all the CLI related codes.

We can consider refactoring our CLI related codes for better code readability. Especially by refactoring out code into several functions that can explain what that code block does.

For example, for change-password.go file, we can refactor into:

RunE: func(cmd *cobra.Command, args []string) error {
  promptPassword()
  changePassword()
  deleteAuthSession()
}

What's your thought about this? @hackerwins
We might want to perform above action items after this PR merges.

go.mod Show resolved Hide resolved
coderabbitai[bot]

This comment was marked as 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.

Leaving just one small comment related to my previous request changes.
Besides that, looks good to me :)

cmd/yorkie/user/delete-account.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 7cad611 and 9cd128f.

Files selected for processing (1)
  • cmd/yorkie/user/delete-account.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • cmd/yorkie/user/delete-account.go

@hackerwins hackerwins requested review from krapie and removed request for chacha912 September 3, 2024 03:15
@sigmaith sigmaith requested a review from krapie September 3, 2024 08:09
coderabbitai[bot]

This comment was marked as 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.

Well... I forgot to mention that the filename change-password.go and delete-account.go should be change_password.go and delete_account.go, just like we use in pkg/document/internal_document.go.

Sorry for dragging this PR :(

@sigmaith
Copy link
Contributor Author

sigmaith commented Sep 3, 2024

No, it's an opportunity for me to grow if you review it in detail!

coderabbitai[bot]

This comment was marked as resolved.

@krapie krapie self-requested a review September 3, 2024 08:39
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.

After this PR merges, we might need to consider refactoring the whole cmd package. I think current code is enough for now.

@sigmaith Having pair programming with contributors will help you understand overall code style & flow.

@krapie krapie merged commit 7a23cb1 into yorkie-team:main Sep 3, 2024
5 checks passed
@sigmaith sigmaith deleted the #982 branch September 3, 2024 08:46
hackerwins pushed a commit that referenced this pull request Sep 5, 2024
Added functionality allowing users to delete accounts and change passwords
through the CLI to support recent development of admin ChangePassword and
DeleteAccount APIs on the server side.
@hackerwins hackerwins changed the title Add Account Deletion and Change Password to CLI Commands Add Account Deletion and Change Password to CLI Sep 5, 2024
raararaara pushed a commit that referenced this pull request Oct 7, 2024
Added functionality allowing users to delete accounts and change passwords through the CLI to support recent development of admin ChangePassword and DeleteAccount APIs on the server side.
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.

Add Account Deletion and Password Change to CLI Commands
4 participants