Skip to content

feat(user): group management over HTTP and in the CLI - #5

Merged
dkruempe merged 2 commits into
masterfrom
feat/user-group-management
Oct 22, 2026
Merged

dkruempe merged 2 commits into
masterfrom
feat/user-group-management

Conversation

@dkruempe

Copy link
Copy Markdown
Owner

Summary

Group management was reachable from nowhere: UserController has only GET routes for groups, which is exactly why the AddGroup/RemoveGroup/UpdateGroup slots in UserManagementCliComponent were dead code and were removed in #4. GroupRepository already had createOf, deleteOf, addGroupOf and removeGroupOf — only the glue was missing.

Stacked on #4 (refactor/nolint-cleanup). Retarget to master once #4 is merged.

What changed

Route Method Auth Repository call
/user/groups POST Admin-User createOf(Group)
/user/groups/{name} DELETE Admin-User deleteOf(Group)
/user/groups/{name}/subgroups/{sub} POST Admin-User addGroupOf(group, sub)
/user/groups/{name}/subgroups/{sub} DELETE Admin-User removeGroupOf(group, sub)

Body/response is the existing GroupDto (group_name, virtual), so no new DTO. Codes: 401 (no token / wrong group), 403 (wrong content type), 400 (broken body, virtual group, missing name), 404 (unknown group), 409 (name exists, or the group still belongs to a user).

CLI: group_add --group -g [--virtual -v], group_remove -g, group_add_subgroup -g -s, group_remove_subgroup -g -s. The enum slots are back, this time with a command and a handler.

Swagger documents all four paths.

Bug found on the way

GroupRepository::deleteOf() removed the groups row but left the group_groups_relation rows pointing at the deleted group. initGroups() then dereferenced it (m_groupMap.at) and the process could not start again. It now deletes the relations in both directions and scrubs the in-memory member lists; the test builds a second repository on the same database, which is what a restart does.

Counter-check: without the fix the new test fails with map::at.

Notes

  • Virtual groups cannot be created over HTTP (400): GroupRepository::createOf rejects them by design, they are defined in code and seeded by VirtualGroupBootstrapPlugin.
  • Sub-group operations are idempotent and report added/removed: false instead of an error.

Verification

  • Build green (GCC 14 Release, -Werror), 1311/1311 unit tests.
  • clang-tidy with the CI check list: 0 findings on the changed sources.
  • check-format.sh master, check-swagger.sh (49 paths), check-namespace.sh: green.

GroupRepository could create and delete groups and maintain sub-group
relations, but nothing exposed it: UserController only had GET routes, which
is why the AddGroup/RemoveGroup/UpdateGroup enum slots in the CLI were dead
code and were removed.

Four routes now cover it (Admin-User): POST/DELETE /user/groups and
POST/DELETE /user/groups/{name}/subgroups/{sub}, with the matching UserApi
methods and the CLI commands group_add, group_remove, group_add_subgroup and
group_remove_subgroup.

Deleting a group that some other group contains was broken: deleteOf removed
the groups row but left the group_groups_relation rows behind, so the next
initGroups() dereferenced a missing group (m_groupMap.at) and the process
could not start. It now removes the relations in both directions, scrubs the
in-memory member lists and has a test that restarts the repository on the
same database.
@dkruempe dkruempe closed this Oct 22, 2026
@dkruempe dkruempe reopened this Oct 22, 2026
@dkruempe
dkruempe changed the base branch from refactor/nolint-cleanup to master October 22, 2026 04:31
@dkruempe dkruempe closed this Oct 22, 2026
@dkruempe dkruempe reopened this Oct 22, 2026
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 92.25352% with 22 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/features/http/controllers/UserController.cpp 90.4% 16 Missing ⚠️
src/features/http/controllers/UserApi.cpp 94.3% 3 Missing ⚠️
...ures/cli/components/UserManagementCliComponent.cpp 95.2% 2 Missing ⚠️
src/features/base/repositories/GroupRepository.cpp 94.4% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

performance-enum-size: the values fit into one byte, and the neighbouring
components (CommandLineService, EventBusCliComponent) already use
std::uint8_t.
@dkruempe
dkruempe merged commit fd18e77 into master Oct 22, 2026
17 checks passed
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.

2 participants