Skip to content

feat: add bl user add/update/delete, recently-viewed-projects/wikis, and star commands#61

Closed
23prime wants to merge 2 commits intomainfrom
feature/user-management-enhancements
Closed

feat: add bl user add/update/delete, recently-viewed-projects/wikis, and star commands#61
23prime wants to merge 2 commits intomainfrom
feature/user-management-enhancements

Conversation

@23prime
Copy link
Owner

@23prime 23prime commented Mar 15, 2026

Checklist

  • Target branch is main
  • Status checks are passing

Summary

  • Add bl user add, bl user update, bl user delete
  • Add bl user recently-viewed-projects, bl user recently-viewed-wikis
  • Add bl user star list <id>, bl user star count <id>

Reason for change

Closes #53

Changes

  • src/api/user.rsRecentlyViewedProject, RecentlyViewedWiki, Star, StarCount structs + 7 new methods
  • src/api/mod.rs — trait + impl
  • src/cmd/user/add.rs, update.rs, delete.rs, recently_viewed_projects.rs, recently_viewed_wikis.rs, star.rs
  • src/main.rs — clap wiring

Notes

bl user update requires at least one optional field via try_new validation.

…and star commands

Implements GitHub issue #53:
- POST /api/v2/users → bl user add
- PATCH /api/v2/users/{userId} → bl user update (requires at least one field)
- DELETE /api/v2/users/{userId} → bl user delete
- GET /api/v2/users/myself/recentlyViewedProjects → bl user recently-viewed-projects
- GET /api/v2/users/myself/recentlyViewedWikis → bl user recently-viewed-wikis
- GET /api/v2/users/{userId}/stars → bl user star list
- GET /api/v2/users/{userId}/stars/count → bl user star count

Adds BacklogApi trait methods and updates all existing MockApi implementations.
Copilot AI review requested due to automatic review settings March 15, 2026 02:48
@coderabbitai
Copy link

coderabbitai bot commented Mar 15, 2026

📝 Walkthrough

Walkthrough

This PR extends the Backlog API client with user management capabilities and recently-viewed data retrieval. It introduces seven new BacklogApi trait methods (add_user, update_user, delete_user, get_recently_viewed_projects, get_recently_viewed_wikis, get_user_stars, count_user_stars), corresponding data structures, concrete implementations in BacklogClient, and CLI command handlers for user operations. Mock implementations are added across existing test modules.

Changes

Cohort / File(s) Summary
Core API Definitions
src/api/mod.rs, src/api/user.rs
Added 7 new public BacklogApi trait methods for user CRUD and related data retrieval; introduced 6 new public data structures (ProjectSummary, RecentlyViewedProject, WikiSummary, RecentlyViewedWiki, Star, StarCount) with camelCase deserialization; implemented all new methods in BacklogClient with HTTP request forwarding.
User Command Modules
src/cmd/user/add.rs, src/cmd/user/delete.rs, src/cmd/user/update.rs, src/cmd/user/recently_viewed_projects.rs, src/cmd/user/recently_viewed_wikis.rs, src/cmd/user/star.rs
New command handlers for user creation, deletion, updating, viewing recently-accessed projects/wikis, and listing/counting user stars. Each includes argument validation, API delegation, and dual text/JSON output modes.
User Command Module Index
src/cmd/user/mod.rs, src/main.rs
Updated module exports and public re-exports; expanded UserCommands enum with Add, Update, Delete, RecentlyViewedProjects, RecentlyViewedWikis, and nested Star variants; wired new command routing and argument instantiation in run() handler.
Visibility Changes
src/cmd/user/show.rs
Made format_user_text() public for reuse across user command modules.
Test Mock Implementations
src/cmd/{auth,issue/*,notification/*,project/*,space/*,team/*,wiki/*}.rs
Added 7 unimplemented!() method stubs to MockApi trait impl across ~30 test contexts to satisfy the expanded BacklogApi interface.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

The PR introduces substantive new logic in multiple user command modules with parameter validation, multi-mode output, and error handling patterns. While many test files receive identical mechanical updates (7 stub methods), the spread across 30+ files and the density of new public types and command routing require careful verification of command semantics, API parameter mapping, and integration correctness.

Possibly related PRs

Poem

🐰 Whiskers twitching with glee,
Seven new paths for users to be—
Add, delete, update with care,
Stars and viewed projects to share!
Hopping through APIs, making dreams clear!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.35% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main additions: bl user commands for add, update, delete, recently-viewed projects/wikis, and star management.
Description check ✅ Passed The description is related to the changeset, providing a summary of new commands, file changes, and implementation notes regarding validation requirements.
Linked Issues check ✅ Passed The PR implements all planned commands and API endpoints from issue #53: add, update, delete user operations [#53]; recently-viewed projects/wikis retrieval [#53]; and user star listing/counting [#53]. All coding requirements are met.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the user management features outlined in issue #53. The GET /api/v2/users/{userId}/icon endpoint mentioned in the issue is not implemented, but this appears intentional (noted as unassigned). No out-of-scope changes detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/user-management-enhancements
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch feature/user-management-enhancements
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a suite of new bl user subcommands (CRUD + “recently viewed” + stars) by extending the Backlog API layer and wiring new clap subcommands through main.rs, with corresponding command implementations and test updates across the repo to satisfy the expanded BacklogApi trait.

Changes:

  • Extend BacklogApi / BacklogClient with user CRUD, recently-viewed projects/wikis, and stars endpoints.
  • Add new cmd::user::* subcommands (add, update, delete, recently-viewed-projects, recently-viewed-wikis, star list/count) and wire them into src/main.rs.
  • Update many existing command tests’ MockApi implementations to include the new trait methods.

Reviewed changes

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

Show a summary per file
File Description
src/main.rs Adds clap subcommands and dispatch for new bl user commands (including nested user star).
src/api/user.rs Adds response structs + BacklogClient methods for new user endpoints.
src/api/mod.rs Extends BacklogApi trait and implements new methods for BacklogClient.
src/cmd/user/mod.rs Registers new user subcommand modules and re-exports.
src/cmd/user/add.rs Implements bl user add command + unit tests with MockApi.
src/cmd/user/update.rs Implements bl user update command + unit tests with MockApi.
src/cmd/user/delete.rs Implements bl user delete command + unit tests with MockApi.
src/cmd/user/recently_viewed_projects.rs Implements bl user recently-viewed-projects + args validation/tests.
src/cmd/user/recently_viewed_wikis.rs Implements bl user recently-viewed-wikis + args validation/tests.
src/cmd/user/star.rs Implements bl user star list/count + unit tests with MockApi.
src/cmd/user/show.rs Exposes shared user text formatting and updates MockApi in tests.
src/cmd/user/list.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/user/activities.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/user/recently_viewed.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/auth.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/space/activities.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/space/disk_usage.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/space/notification.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/space/show.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/project/activities.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/project/category.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/project/disk_usage.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/project/issue_type.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/project/list.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/project/show.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/project/status.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/project/user.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/project/version.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/team/list.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/team/show.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/wiki/create.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/wiki/update.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/wiki/delete.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/wiki/list.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/wiki/show.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/wiki/history.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/wiki/attachment/list.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/issue/create.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/issue/update.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/issue/delete.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/issue/list.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/issue/show.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/issue/count.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/issue/attachment/list.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/issue/comment/add.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/issue/comment/update.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/issue/comment/delete.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/issue/comment/list.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/notification/list.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/notification/count.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/notification/read.rs Updates MockApi in tests to satisfy expanded BacklogApi.
src/cmd/notification/reset_unread.rs Updates MockApi in tests to satisfy expanded BacklogApi.
Comments suppressed due to low confidence (1)

src/cmd/user/show.rs:40

  • format_user_text was made fully pub (and cmd::user::show was made a public module) to share formatting with sibling subcommands. To avoid expanding the crate's public API surface and to stay consistent with other cmd modules, consider keeping show private and changing this function to pub(super)/pub(crate) (or re-exporting a pub(crate) helper from cmd::user::mod).

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +84 to +90
pub struct Star {
pub id: u64,
pub comment: Option<String>,
pub url: String,
pub title: String,
pub presenter: User,
pub created: String,
Comment on lines +114 to +127
pub fn add_user(&self, params: &[(String, String)]) -> Result<User> {
let value = self.post_form("/users", params)?;
deserialize(value, "user response")
}

pub fn update_user(&self, user_id: u64, params: &[(String, String)]) -> Result<User> {
let value = self.patch_form(&format!("/users/{user_id}"), params)?;
deserialize(value, "user response")
}

pub fn delete_user(&self, user_id: u64) -> Result<User> {
let value = self.delete_req(&format!("/users/{user_id}"))?;
deserialize(value, "user response")
}
Comment on lines +611 to +615
/// Add a new user
Add {
/// User ID (login name)
#[arg(long)]
user_id: String,
Comment on lines +616 to +619
/// Password
#[arg(long)]
password: String,
/// Display name
Comment on lines +16 to +24
impl UserAddArgs {
pub fn new(
user_id: String,
password: String,
name: String,
mail_address: String,
role_type: u8,
json: bool,
) -> Self {
Comment on lines +17 to +28
pub fn try_new(
user_id: u64,
name: Option<String>,
password: Option<String>,
mail_address: Option<String>,
role_type: Option<u8>,
json: bool,
) -> anyhow::Result<Self> {
if name.is_none() && password.is_none() && mail_address.is_none() && role_type.is_none() {
anyhow::bail!(
"at least one of --name, --password, --mail-address, or --role-type must be specified"
);
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

🧹 Nitpick comments (4)
src/cmd/user/recently_viewed_projects.rs (1)

41-47: Add a regression test for forwarded query parameters.

Current tests validate success/error, but not that count/offset/order are actually passed through.

✅ Suggested test-oriented patch
 struct MockApi {
     items: Option<Vec<RecentlyViewedProject>>,
+    captured: std::cell::RefCell<Vec<(String, String)>>,
 }
@@
-        fn get_recently_viewed_projects(
-            &self,
-            _: &[(String, String)],
-        ) -> anyhow::Result<Vec<RecentlyViewedProject>> {
+        fn get_recently_viewed_projects(
+            &self,
+            params: &[(String, String)],
+        ) -> anyhow::Result<Vec<RecentlyViewedProject>> {
+            *self.captured.borrow_mut() = params.to_vec();
             self.items.clone().ok_or_else(|| anyhow!("no items"))
         }
@@
         let api = MockApi {
             items: Some(vec![sample_item()]),
+            captured: std::cell::RefCell::new(vec![]),
         };
@@
         let api = MockApi {
             items: Some(vec![sample_item()]),
+            captured: std::cell::RefCell::new(vec![]),
         };
@@
-        let api = MockApi { items: None };
+        let api = MockApi {
+            items: None,
+            captured: std::cell::RefCell::new(vec![]),
+        };
@@
+    #[test]
+    fn recently_viewed_projects_with_builds_query_params() {
+        let api = MockApi {
+            items: Some(vec![sample_item()]),
+            captured: std::cell::RefCell::new(vec![]),
+        };
+        let args = UserRecentlyViewedProjectsArgs::try_new(
+            false,
+            50,
+            10,
+            Some("asc".to_string()),
+        )
+        .unwrap();
+        recently_viewed_projects_with(&args, &api).unwrap();
+        let params = api.captured.borrow();
+        assert!(params.iter().any(|(k, v)| k == "count" && v == "50"));
+        assert!(params.iter().any(|(k, v)| k == "offset" && v == "10"));
+        assert!(params.iter().any(|(k, v)| k == "order" && v == "asc"));
+    }

Also applies to: 346-401

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/cmd/user/recently_viewed_projects.rs` around lines 41 - 47, Add a
regression test that verifies the query parameters are forwarded to the API when
calling get_recently_viewed_projects: create a test that constructs args with
specific count/offset and an order, invoke the command path that builds the
params (the code that pushes ("count", args.count), ("offset", args.offset), and
("order", args.order) into params) and use a mock HTTP server or request
inspector for get_recently_viewed_projects to assert the outgoing request's
query string contains the expected count, offset and order values; ensure you
cover both Some(order) and None(order) cases so the code path that conditionally
pushes ("order", ...) is exercised.
src/cmd/user/recently_viewed_wikis.rs (1)

37-47: Add a query-param capture test for recently_viewed_wikis_with.

Please add a capture-style test asserting that count, offset, and optional order are sent with expected names and values. This command is query-shape-sensitive and currently only tests success/error paths.

Also applies to: 345-400

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/cmd/user/recently_viewed_wikis.rs` around lines 37 - 47, Add a
capture-style unit test for recently_viewed_wikis_with that verifies the query
parameters sent to api.get_recently_viewed_wikis: assert the captured params
vector contains entries for "count" with args.count.to_string(), "offset" with
args.offset.to_string(), and when args.order.is_some() also contains "order"
with the provided value; implement the test by mocking
BacklogApi.get_recently_viewed_wikis to capture its &Vec<(String,String)>
argument and assert names/values, and add an additional variant covering None
for order; apply the same pattern for the other related tests referenced around
lines 345-400 that exercise query-shape sensitivity.
src/cmd/user/update.rs (1)

46-60: Add a param-capture unit test for update_with form keys.

Current tests verify success/error, but not that keys are exactly name, password, mailAddress, and roleType. A capture-style test would prevent subtle request-shape regressions.

Also applies to: 349-392

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/cmd/user/update.rs` around lines 46 - 60, The tests lack a capture-style
unit test ensuring update_with builds params with exact form keys; add a unit
test that calls update_with with a mocked BacklogApi implementation (or a test
double) that captures the params passed into update_user and asserts the keys
are exactly "name", "password", "mailAddress", and "roleType" (and present only
when the corresponding UserUpdateArgs fields are Some), using the update_with
function and UserUpdateArgs to exercise each optional field; locate the call
site by referencing update_with and the api.update_user(...) invocation to
capture the Vec<(String,String)> and assert keys and presence/absence to prevent
request-shape regressions.
src/api/user.rs (1)

114-127: Add endpoint-level tests for the new user API methods.

The newly added methods (add_user, update_user, delete_user, get_recently_viewed_projects, get_recently_viewed_wikis, get_user_stars, count_user_stars) are not covered in this module’s httpmock tests yet. Please add happy-path + API-error tests to lock down path/query/form mapping and response deserialization.

As per coding guidelines: Never call BacklogClient::from_config() in tests — it requires real credentials on disk. Use httpmock for api/ layer tests and MockApi struct for cmd/ layer tests.

Also applies to: 146-170

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/api/user.rs` around lines 114 - 127, Add httpmock-based endpoint tests
covering happy-path and API-error cases for the new API methods so their request
mapping and deserialization are locked down: write tests for add_user,
update_user, delete_user, get_recently_viewed_projects,
get_recently_viewed_wikis, get_user_stars, and count_user_stars using httpmock
server to stub expected POST/PATCH/DELETE/GET endpoints and responses, asserting
correct form/query payloads and successful deserialize behavior as well as
error-path responses; do not call BacklogClient::from_config() in
tests—construct the client pointed at the httpmock server or use the existing
test helper that injects base URL—and for cmd/ layer tests use MockApi instead
of real network calls.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/cmd/user/update.rs`:
- Around line 17-38: In UserUpdateArgs::try_new validate the optional role_type
early: if role_type.is_some() check the inner u8 is in the allowed range 1..=6
and otherwise return an error (use anyhow::bail with a clear message); keep the
existing presence check for all fields and construct Self only when role_type is
either None or within 1–6. This touches the try_new function and the role_type
parameter validation.

---

Nitpick comments:
In `@src/api/user.rs`:
- Around line 114-127: Add httpmock-based endpoint tests covering happy-path and
API-error cases for the new API methods so their request mapping and
deserialization are locked down: write tests for add_user, update_user,
delete_user, get_recently_viewed_projects, get_recently_viewed_wikis,
get_user_stars, and count_user_stars using httpmock server to stub expected
POST/PATCH/DELETE/GET endpoints and responses, asserting correct form/query
payloads and successful deserialize behavior as well as error-path responses; do
not call BacklogClient::from_config() in tests—construct the client pointed at
the httpmock server or use the existing test helper that injects base URL—and
for cmd/ layer tests use MockApi instead of real network calls.

In `@src/cmd/user/recently_viewed_projects.rs`:
- Around line 41-47: Add a regression test that verifies the query parameters
are forwarded to the API when calling get_recently_viewed_projects: create a
test that constructs args with specific count/offset and an order, invoke the
command path that builds the params (the code that pushes ("count", args.count),
("offset", args.offset), and ("order", args.order) into params) and use a mock
HTTP server or request inspector for get_recently_viewed_projects to assert the
outgoing request's query string contains the expected count, offset and order
values; ensure you cover both Some(order) and None(order) cases so the code path
that conditionally pushes ("order", ...) is exercised.

In `@src/cmd/user/recently_viewed_wikis.rs`:
- Around line 37-47: Add a capture-style unit test for
recently_viewed_wikis_with that verifies the query parameters sent to
api.get_recently_viewed_wikis: assert the captured params vector contains
entries for "count" with args.count.to_string(), "offset" with
args.offset.to_string(), and when args.order.is_some() also contains "order"
with the provided value; implement the test by mocking
BacklogApi.get_recently_viewed_wikis to capture its &Vec<(String,String)>
argument and assert names/values, and add an additional variant covering None
for order; apply the same pattern for the other related tests referenced around
lines 345-400 that exercise query-shape sensitivity.

In `@src/cmd/user/update.rs`:
- Around line 46-60: The tests lack a capture-style unit test ensuring
update_with builds params with exact form keys; add a unit test that calls
update_with with a mocked BacklogApi implementation (or a test double) that
captures the params passed into update_user and asserts the keys are exactly
"name", "password", "mailAddress", and "roleType" (and present only when the
corresponding UserUpdateArgs fields are Some), using the update_with function
and UserUpdateArgs to exercise each optional field; locate the call site by
referencing update_with and the api.update_user(...) invocation to capture the
Vec<(String,String)> and assert keys and presence/absence to prevent
request-shape regressions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 94c12b79-fae9-471b-8273-21e8967a68e4

📥 Commits

Reviewing files that changed from the base of the PR and between 8b899ec and e3cffd0.

📒 Files selected for processing (52)
  • src/api/mod.rs
  • src/api/user.rs
  • src/cmd/auth.rs
  • src/cmd/issue/attachment/list.rs
  • src/cmd/issue/comment/add.rs
  • src/cmd/issue/comment/delete.rs
  • src/cmd/issue/comment/list.rs
  • src/cmd/issue/comment/update.rs
  • src/cmd/issue/count.rs
  • src/cmd/issue/create.rs
  • src/cmd/issue/delete.rs
  • src/cmd/issue/list.rs
  • src/cmd/issue/show.rs
  • src/cmd/issue/update.rs
  • src/cmd/notification/count.rs
  • src/cmd/notification/list.rs
  • src/cmd/notification/read.rs
  • src/cmd/notification/reset_unread.rs
  • src/cmd/project/activities.rs
  • src/cmd/project/category.rs
  • src/cmd/project/disk_usage.rs
  • src/cmd/project/issue_type.rs
  • src/cmd/project/list.rs
  • src/cmd/project/show.rs
  • src/cmd/project/status.rs
  • src/cmd/project/user.rs
  • src/cmd/project/version.rs
  • src/cmd/space/activities.rs
  • src/cmd/space/disk_usage.rs
  • src/cmd/space/notification.rs
  • src/cmd/space/show.rs
  • src/cmd/team/list.rs
  • src/cmd/team/show.rs
  • src/cmd/user/activities.rs
  • src/cmd/user/add.rs
  • src/cmd/user/delete.rs
  • src/cmd/user/list.rs
  • src/cmd/user/mod.rs
  • src/cmd/user/recently_viewed.rs
  • src/cmd/user/recently_viewed_projects.rs
  • src/cmd/user/recently_viewed_wikis.rs
  • src/cmd/user/show.rs
  • src/cmd/user/star.rs
  • src/cmd/user/update.rs
  • src/cmd/wiki/attachment/list.rs
  • src/cmd/wiki/create.rs
  • src/cmd/wiki/delete.rs
  • src/cmd/wiki/history.rs
  • src/cmd/wiki/list.rs
  • src/cmd/wiki/show.rs
  • src/cmd/wiki/update.rs
  • src/main.rs

Comment on lines +17 to +38
pub fn try_new(
user_id: u64,
name: Option<String>,
password: Option<String>,
mail_address: Option<String>,
role_type: Option<u8>,
json: bool,
) -> anyhow::Result<Self> {
if name.is_none() && password.is_none() && mail_address.is_none() && role_type.is_none() {
anyhow::bail!(
"at least one of --name, --password, --mail-address, or --role-type must be specified"
);
}
Ok(Self {
user_id,
name,
password,
mail_address,
role_type,
json,
})
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🌐 Web query:

Backlog API "Update User" roleType allowed values for PATCH /api/v2/users/:userId

💡 Result:

For Backlog API v2 PATCH /api/v2/users/:userId (“Update User”), the roleType field (Number) allows these values: Administrator (1), Normal User (2), Reporter (3), Viewer (4), Guest Reporter (5), Guest Viewer (6). [1]


Validate --role-type range in UserUpdateArgs::try_new.

try_new accepts any u8, but the API only allows values 1–6 (Administrator through Guest Viewer). Reject out-of-range values early in the domain-validation layer:

Suggested fix
     ) -> anyhow::Result<Self> {
         if name.is_none() && password.is_none() && mail_address.is_none() && role_type.is_none() {
             anyhow::bail!(
                 "at least one of --name, --password, --mail-address, or --role-type must be specified"
             );
         }
+        if let Some(role) = role_type
+            && !(1..=6).contains(&role)
+        {
+            anyhow::bail!("--role-type must be between 1 and 6");
+        }
         Ok(Self {
             user_id,
             name,
             password,
             mail_address,
             role_type,
             json,
         })
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
pub fn try_new(
user_id: u64,
name: Option<String>,
password: Option<String>,
mail_address: Option<String>,
role_type: Option<u8>,
json: bool,
) -> anyhow::Result<Self> {
if name.is_none() && password.is_none() && mail_address.is_none() && role_type.is_none() {
anyhow::bail!(
"at least one of --name, --password, --mail-address, or --role-type must be specified"
);
}
Ok(Self {
user_id,
name,
password,
mail_address,
role_type,
json,
})
}
pub fn try_new(
user_id: u64,
name: Option<String>,
password: Option<String>,
mail_address: Option<String>,
role_type: Option<u8>,
json: bool,
) -> anyhow::Result<Self> {
if name.is_none() && password.is_none() && mail_address.is_none() && role_type.is_none() {
anyhow::bail!(
"at least one of --name, --password, --mail-address, or --role-type must be specified"
);
}
if let Some(role) = role_type
&& !(1..=6).contains(&role)
{
anyhow::bail!("--role-type must be between 1 and 6");
}
Ok(Self {
user_id,
name,
password,
mail_address,
role_type,
json,
})
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/cmd/user/update.rs` around lines 17 - 38, In UserUpdateArgs::try_new
validate the optional role_type early: if role_type.is_some() check the inner u8
is in the allowed range 1..=6 and otherwise return an error (use anyhow::bail
with a clear message); keep the existing presence check for all fields and
construct Self only when role_type is either None or within 1–6. This touches
the try_new function and the role_type parameter validation.

@23prime 23prime closed this Mar 15, 2026
@23prime 23prime deleted the feature/user-management-enhancements branch March 15, 2026 03:49
@23prime 23prime restored the feature/user-management-enhancements branch March 15, 2026 03:50
@23prime 23prime reopened this Mar 15, 2026
@23prime 23prime marked this pull request as draft March 15, 2026 04:31
@23prime
Copy link
Owner Author

23prime commented Mar 15, 2026

Closing due to large conflicts with main. Will reimplement from scratch on current main.

@23prime 23prime closed this Mar 15, 2026
@23prime 23prime deleted the feature/user-management-enhancements branch March 15, 2026 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: bl user add / update / delete + recently-viewed projects/wikis + stars

2 participants