Skip to content

feat(user): implement user update command - #1033

Open
shellyco-code wants to merge 18 commits into
goharbor:mainfrom
shellyco-code:feat/user-update-command
Open

feat(user): implement user update command#1033
shellyco-code wants to merge 18 commits into
goharbor:mainfrom
shellyco-code:feat/user-update-command

Conversation

@shellyco-code

Copy link
Copy Markdown
Contributor

What type of PR is this?
/kind feature

What this PR does / why we need it:
The user command group currently supports create, delete, list, elevate, and password subcommands, but lacks an update command. In the Harbor REST API, the PUT /users/{user_id} endpoint allows administrators to update a user's email, realname, and comment fields.

This PR implements the missing harbor user update command to support these user profile modifications.

It features:

  1. Interactive Workflow: Running harbor user update prompts the user to select a user from the visual list (using huh and bubbletea), prepopulates the form with existing user values (retrieved using the client), and allows interactive updates.
  2. Non-interactive Workflow: Running harbor user update <username-or-id> --email "new@example.com" --realname "New Name" updates only the requested fields without displaying prompts, falling back to existing values for unspecified fields.
  3. Robust ID/Name Resolution: Accepts both user ID (integer) or username arguments.
  4. Validation and Error Handling: Validates email format changes and checks for 403 unauthorized responses to provide clean user feedback.
  5. Command Unit Tests: Added metadata, flags, and command validation tests under cmd/harbor/root/user/update_test.go.

Which issue(s) this PR fixes:
Fixes #966

Does this PR introduce a user-facing change?:

Implement `harbor user update` command to modify user profile fields (email, realname, comment) interactively or via flags.


@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.82390% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 10.40%. Comparing base (60ad0bd) to head (8182e12).
⚠️ Report is 196 commits behind head on main.

Files with missing lines Patch % Lines
pkg/api/user_handler.go 84.61% 8 Missing ⚠️
pkg/api/immutable_handler.go 0.00% 2 Missing ⚠️
pkg/views/user/update/view.go 94.28% 2 Missing ⚠️
cmd/harbor/root/user/cmd.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1033      +/-   ##
==========================================
- Coverage   10.99%   10.40%   -0.59%     
==========================================
  Files         173      323     +150     
  Lines        8671    16239    +7568     
==========================================
+ Hits          953     1689     +736     
- Misses       7612    14416    +6804     
- Partials      106      134      +28     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Implements a new harbor user update subcommand to update Harbor user profile fields (email, realname, comment) via either an interactive TUI form or a flag-driven workflow, aligning CLI capabilities with Harbor’s PUT /users/{user_id} endpoint.

Changes:

  • Added interactive update form view for editing user profile fields.
  • Added harbor user update command with ID/username resolution and flag-based updates.
  • Extended API user handler with update and user lookup helpers, plus basic command tests and command registration.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
pkg/views/user/update/view.go Adds a TUI form for interactively editing user profile fields with validation.
pkg/api/user_handler.go Adds API helper to update user profile and helper(s) to resolve/fetch users for the command.
cmd/harbor/root/user/update.go Introduces the user update cobra command with interactive and non-interactive workflows.
cmd/harbor/root/user/update_test.go Adds basic tests for command metadata and flag registration.
cmd/harbor/root/user/cmd.go Registers the new update subcommand under the user command group.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/harbor/root/user/update.go Outdated
Comment thread pkg/api/user_handler.go
Comment thread pkg/api/user_handler.go
Comment thread cmd/harbor/root/user/update_test.go Outdated

@qcserestipy qcserestipy left a comment

Copy link
Copy Markdown
Collaborator

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, please address the requested changes.

Comment thread pkg/api/user_handler.go
Comment thread cmd/harbor/root/user/update.go Outdated
Comment thread cmd/harbor/root/user/update.go Outdated
@qcserestipy qcserestipy added enhancement New feature or request Changes Requesed feedback that must be addressed before merging. status/in-progress Work on this issue has started or a linked pull request is actively being developed. labels Jul 5, 2026
@shellyco-code
shellyco-code force-pushed the feat/user-update-command branch 6 times, most recently from 49fb8dc to 35b9e0a Compare July 6, 2026 03:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 8 comments.

Comment thread cmd/harbor/root/user/update.go
Comment thread cmd/harbor/root/user/update.go Outdated
Comment thread cmd/harbor/root/user/update.go
Comment thread pkg/api/user_handler.go
Comment thread pkg/views/user/update/view.go Outdated
Comment thread pkg/api/user_handler_test.go
Comment thread pkg/api/user_handler_test.go
Comment thread pkg/api/user_handler_test.go

@qcserestipy qcserestipy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please checkout the comments

This PR introduces the missing harbor user update command to support
updating a user's profile information (email, realname, and comment fields)
using the SDK's UpdateUserProfile and the REST API PUT /users/{user_id}.

It provides:
1. Interactive prompt workflow using huh form when no flags are supplied.
2. Non-interactive flag-based updates.
3. Proper user ID/name resolution and input verification.
4. Command unit tests.

Signed-off-by: shellyco-code <shellychahar57@gmail.com>
Signed-off-by: shellyco-code <shellychahar57@gmail.com>
Signed-off-by: shellyco-code <shellychahar57@gmail.com>
Signed-off-by: shellyco-code <shellychahar57@gmail.com>
Signed-off-by: shellyco-code <shellychahar57@gmail.com>
Signed-off-by: shellyco-code <shellychahar57@gmail.com>
@shellyco-code
shellyco-code force-pushed the feat/user-update-command branch 4 times, most recently from ce82a3b to c4da7b9 Compare July 21, 2026 06:30
@shellyco-code
shellyco-code force-pushed the feat/user-update-command branch 4 times, most recently from 85eaabb to 63ee1d9 Compare July 21, 2026 08:12
Signed-off-by: shellyco-code <shellychahar57@gmail.com>
@shellyco-code
shellyco-code force-pushed the feat/user-update-command branch from 63ee1d9 to 3e49872 Compare July 21, 2026 08:33
Signed-off-by: shellyco-code <shellychahar57@gmail.com>
Signed-off-by: shellyco-code <shellychahar57@gmail.com>
Signed-off-by: shellyco-code <shellychahar57@gmail.com>
Signed-off-by: shellyco-code <shellychahar57@gmail.com>
Signed-off-by: shellyco-code <shellychahar57@gmail.com>
Signed-off-by: shellyco-code <shellychahar57@gmail.com>
Signed-off-by: shellyco-code <shellychahar57@gmail.com>
Signed-off-by: shellyco-code <shellychahar57@gmail.com>
Signed-off-by: shellyco-code <shellychahar57@gmail.com>
@qcserestipy

Copy link
Copy Markdown
Collaborator

@shellyco-code Thank you for the changes, please fix merge conflicts first

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Changes Requesed feedback that must be addressed before merging. enhancement New feature or request status/in-progress Work on this issue has started or a linked pull request is actively being developed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature]: Implement user update command

3 participants